Common Utilities¶
pcapkit.dumpkit.common holds the utilities shared by
pcapkit.dumpkit, chiefly customised hooks for dictdumper.dumper.Dumper
classes.
- pcapkit.dumpkit.common.make_dumper(output)[source]¶
Create a customised
Dumperclass.- Parameters:
output (
Type[dictdumper.dumper.Dumper]) – Output class to customise.- Return type:
- Returns:
Customised
Dumpersubclass ofoutput.
Changed in version 1.5.0: Several dumped shapes change. A nameless flag value renders its value as the name,
Flags::0 [0]rather thanFlags::None [0](#648). AnOrderedMultiDictdumps as a list of one-key mappings in wire order, not grouped by key (#1263). AnIPv4NetworkorIPv6Networkdumps as its string, a timezone as its offset in seconds, andNULLandNO_VALUEas'<NULL>'and'<NO_VALUE>'(#1258). Inplistoutput,Noneis kept (#1257), and a string carrying a character XML forbids is written as<data>(#1262).Changed in version 1.6.0: A field an
Inforenamed for clashing with a builtin name, such as a reassembled datagram’spacket, is written under its own name rather than left out, and reading it resolves a deferredpacketas indexing does. A protocol object, such as thatpacket, is written as itsinfo, as a frame is, rather than by its attributes (#2733).
- class pcapkit.dumpkit.common.Dumper(fname, **kwargs)[source]¶
Bases:
DumperBaseBase
Dumperobject.A
Dumperthat registers itself, on request, in theExtractorandTraceFlowoutput dumper registries.Example
Registration is opt-in. Pass keyword argument
fmtat class definition to register the dumper under that output format:class MyDumper(Dumper, fmt='my_format', ext='.mine'): ...
Omit it and the subclass is not registered:
class MyMixin(Dumper): # not registered ...
Such a class can be registered later. The hook writes every output registry, so the manual equivalent is the module-level registrar, not one class’ own method:
from pcapkit.foundation.registry.foundation import register_dumper register_dumper('my_mixin', MyMixin, ext='.mine')
Changed in version 1.5.0: Registration is opt-in, under the
fmtclass keyword; 1.4.x registered every subclass, under itskindwhen the keyword was omitted (#514).- classmethod __init_subclass__(fmt=None, ext=None, *args, **kwargs)[source]¶
Initialise subclass.
Registers the subclass in the
ExtractorandTraceFlowoutput dumper registries.- Parameters:
fmt (
str|None) – Output format to register the subclass under, lowercased.None(the default) skips registration entirely.ext (
str|None) – Output file extension;Noneinfers it fromfmt. Only meaningful alongsidefmt.*args (
Any) – Arbitrary positional arguments.**kwargs (
Any) – Arbitrary keyword arguments.
- Raises:
UnsupportedCall – If
extis given withoutfmt, or if any unrecognised class keyword is given.- Return type:
Registration is opt-in: the subclass is registered if and only if
fmtis given, so a subclass can decline it without inheritingDumperBase, asEnumSchema.__init_subclass__guards on itscodekeyword.Note
fmtis not inferred fromkind, which needs an instance, hence a file created while theclassstatement runs.
Internal Definitions¶
- pcapkit.dumpkit.common.render_enum(o)[source]¶
Render an enumeration member as
Type::name [value].This is the spelling of every dumped enumeration in the
json,tree,text,txt,plistandxmloutput of bothExtractorandTraceFlow.- Parameters:
o (
Enum|aenum.Enum) – Enumeration member to render.- Return type:
- Returns:
The member’s
Type::name [value]rendering.
Note
A
Flagvalue made entirely of undeclared bits, at zero or not, hasnameNone, which would renderFlags(0)as'Flags::None [0]', indistinguishable from a member namedNone(#648). Its decimal value is used instead, as the enumeration libraries spell an undeclared residue (BindingUpdateFlag(32777).nameis'A|9'), and no identifier begins with a digit:BindingUpdateFlag(9)renders as'BindingUpdateFlag::9 [9]'andFlags(0)as'Flags::0 [0]'. A stdlibenum.IntFlaganswersname is Noneidentically on CPython 3.14.7, so this is not anaenumquirk.
- class pcapkit.dumpkit.common.DumperBase(fname, **kwargs)[source]¶
Bases:
dictdumper.dumper.DumperBase
Dumperobject.Note
This class is for internal use only. For customisation, please use
Dumperinstead.