Validation Utilities

pcapkit.utilities.validations contains functions to validate arguments for functions and classes. It was first used in PyNTLib as validators.

pcapkit.utilities.validations._ip_frag_check(*args, stacklevel=3)[source]

Check if arguments are valid IP fragments (IPv4 and/or IPv6 packet).

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

pcapkit.utilities.validations._tcp_frag_check(*args, stacklevel=3)[source]

Check if arguments are valid TCP fragments (TCP packet).

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

pcapkit.utilities.validations.bool_check(*args, stacklevel=2)[source]

Check if arguments are bool type.

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

BoolError – If any of the arguments is NOT bool type.

pcapkit.utilities.validations.bytearray_check(*args, stacklevel=2)[source]

Check if arguments are bytearray type.

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

BytearrayError – If any of the arguments is NOT bytearray type.

pcapkit.utilities.validations.bytes_check(*args, stacklevel=2)[source]

Check if arguments are bytes type.

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

BytesError – If any of the arguments is NOT bytes type.

pcapkit.utilities.validations.complex_check(*args, stacklevel=2)[source]

Check if arguments are complex numbers (complex).

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

ComplexError – If any of the arguments is NOT complex number (complex).

pcapkit.utilities.validations.dict_check(*args, stacklevel=2)[source]

Check if arguments are dict type.

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

DictError – If any of the arguments is NOT dict type.

pcapkit.utilities.validations.enum_check(*args, stacklevel=2)[source]

Check if arguments are of enumeration protocol type (enum.EnumMeta and/or aenum.EnumMeta).

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

EnumError – If any of the arguments is NOT enumeration protocol type (enum.EnumMeta and/or aenum.EnumMeta).

pcapkit.utilities.validations.frag_check(*args, protocol, stacklevel=3)[source]

Check if arguments are valid fragments.

Parameters
  • *args – Arguments to check.

  • protocol (str) – Originated fragmentation protocol (IPv4, IPv6 or TCP).

  • stacklevel (int) – Stack level to fetch originated function name.

  • If the protocol is IPv4, the fragment should be as an IPv4 fragmentation.

  • If the protocol is IPv6, the fragment should be as an IPv6 fragmentation.

  • If the protocol is TCP, the fragment should be as an TCP fragmentation.

Raises

FragmentError – If any of the arguments is NOT valid fragment.

pcapkit.utilities.validations.info_check(*args, stacklevel=2)[source]

Check if arguments are Info instances.

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

InfoError – If any of the arguments is NOT Info instance.

pcapkit.utilities.validations.int_check(*args, stacklevel=2)[source]

Check if arguments are integrals (int).

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

IntError – If any of the arguments is NOT integral (int).

pcapkit.utilities.validations.io_check(*args, stacklevel=2)[source]

Check if arguments are file-like object (io.IOBase).

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

IOObjError – If any of the arguments is NOT file-like object (io.IOBase).

pcapkit.utilities.validations.ip_check(*args, stacklevel=2)[source]

Check if arguments are IP addresses (ipaddress.IPv4Address and/or ipaddress.IPv6Address).

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

IPError – If any of the arguments is NOT IP address (ipaddress.IPv4Address and/or ipaddress.IPv6Address).

pcapkit.utilities.validations.list_check(*args, stacklevel=2)[source]

Check if arguments are list type.

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

ListError – If any of the arguments is NOT list type.

pcapkit.utilities.validations.number_check(*args, stacklevel=2)[source]

Check if arguments are numbers.

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

DigitError – If any of the arguments is NOT number (int, float and/or complex).

pcapkit.utilities.validations.pkt_check(*args, stacklevel=3)[source]

Check if arguments are valid packets (TCP packet).

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

PacketError – If any of the arguments is NOT valid packet.

pcapkit.utilities.validations.real_check(*args, stacklevel=2)[source]

Check if arguments are real numbers (int and/or float).

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

RealError – If any of the arguments is NOT real number (int and/or float).

pcapkit.utilities.validations.str_check(*args, stacklevel=2)[source]

Check if arguments are str type.

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

StringError – If any of the arguments is NOT str type.

pcapkit.utilities.validations.tuple_check(*args, stacklevel=2)[source]

Check if arguments are tuple type.

Parameters
  • *args – Arguments to check.

  • stacklevel (int) – Stack level to fetch originated function name.

Raises

TupleError – If any of the arguments is NOT tuple type.