Module Utilities

pcapkit.utilities holds the cross-cutting services pcapkit is built with, and imports nothing from pcapkit outside itself (see Choosing Between utilities and corekit):

  • user-refined exceptions and warnings, and logging;

  • the tunable limits of config;

  • a compatibility layer, timestamp conversion and pickle reductions;

  • the context variables its modules share, lazy imports for a package’s exports, and an abstract-class check that reads no interpreter flag;

  • wrappers around third-party libraries.

Version Compatibility

pcapkit.utilities.compat covers these objects on interpreters older than the version listed:

Compatibility Target

Minimal Required Version

collections.abc.Mapping[KT, VT]

Python 3.9

tuple[T, ...]

Python 3.9

list[T]

Python 3.9

dict[KT, VT]

Python 3.9

urllib.parse.unquote() on bytes

Python 3.9

enum.StrEnum

Python 3.11

typing.final()

Python 3.11

decimal.localcontext(ctx=None, **kwargs)

Python 3.11

enum.show_flag_values()

Python 3.11

typing.TypeAlias

Python 3.10

threading.__excepthook__, as default_threading_excepthook

Python 3.10

inspect.get_annotations(), of a class

Python 3.10

types.UnionType, or None below it

Python 3.10

It also exports pathlib, ModuleNotFoundError, collections.abc.Collection and functools.cached_property() straight from the standard library, since 1.5.0 requires Python 3.8 or later (#2051).

pcapkit.utilities.compat.final(f)[source]

typing.final() from Python 3.11 on, and typing_extensions.final below it. Both record __final__ = True on the decorated object at runtime, which Info and Schema read to refuse a class marked @final without info_final() or schema_final(). Plain typing.final() records nothing below 3.11 (gh-90500).

Changed in version 1.5.0: Taken from typing_extensions below Python 3.11 rather than 3.8, so that __final__ is recorded on every supported version (#778).

pcapkit.utilities.compat.unquote(string, encoding='utf-8', errors='replace')[source]

urllib.parse.unquote(), which accepts bytes from Python 3.9 on. Below 3.9, a bytes string is unquoted to octets with urllib.parse.unquote_to_bytes() and then decoded with encoding and errors.

pcapkit.utilities.compat.default_threading_excepthook

The interpreter’s own default thread exception hook, even when threading.excepthook() has been replaced: threading.__excepthook__ from Python 3.10 on, and _thread._excepthook on 3.8 and 3.9.

class pcapkit.utilities.compat.cached_property(func)[source]

functools.cached_property() itself.

Changed in version 1.5.0: No longer a backport below Python 3.8, which 1.5.0 does not install on (#2051).