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
booltype.
-
pcapkit.utilities.validations.bytearray_check(*args, stacklevel=2)[source]¶ Check if arguments are
bytearraytype.- Parameters
*args – Arguments to check.
stacklevel (int) – Stack level to fetch originated function name.
- Raises
BytearrayError – If any of the arguments is NOT
bytearraytype.
-
pcapkit.utilities.validations.bytes_check(*args, stacklevel=2)[source]¶ Check if arguments are
bytestype.- Parameters
*args – Arguments to check.
stacklevel (int) – Stack level to fetch originated function name.
- Raises
BytesError – If any of the arguments is NOT
bytestype.
-
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
dicttype.
-
pcapkit.utilities.validations.enum_check(*args, stacklevel=2)[source]¶ Check if arguments are of enumeration protocol type (
enum.EnumMetaand/oraenum.EnumMeta).
-
pcapkit.utilities.validations.frag_check(*args, protocol, stacklevel=3)[source]¶ Check if arguments are valid fragments.
- Parameters
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
Infoinstances.
-
pcapkit.utilities.validations.int_check(*args, stacklevel=2)[source]¶ Check if arguments are integrals (
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.IPv4Addressand/oripaddress.IPv6Address).
-
pcapkit.utilities.validations.list_check(*args, stacklevel=2)[source]¶ Check if arguments are
listtype.
-
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,floatand/orcomplex).
-
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 (
intand/orfloat).