Registry Helpers¶
pcapkit.interface.registry contains the helpers the
registrars use to compare registry entries and to put back
the entry a registry shipped with, so that an override of a
built-in can be undone (#1363, #1364).
They back the registrars of
Extractor –
register_engine(),
register_reassembly(),
register_traceflow() and
register_dumper() – and
TraceFlow.register_dumper,
which the functions in pcapkit.foundation.registry call in turn.
A registry entry is a class or a
ModuleDescriptor naming one; an
__output__ entry is a (dumper, ext) pair whose dumper
is such an entry.
- pcapkit.interface.registry.same_entry(entry, other)[source]¶
Tell whether two registry entries name the same class.
An entry is a class or a
ModuleDescriptor. Two descriptors are the same entry when they are equal, and a descriptor and a class are when the descriptor names that class. The class is looked up insys.modulesrather than imported: a class someone holds has its module loaded already, so a descriptor whose module is not loaded cannot name it, and an optional engine that is not installed is never imported to answer the question.The comparison is symmetric, and two classes are the same entry only when they are the same object.
- pcapkit.interface.registry.restore_shipped(registry, key, shipped, kind)[source]¶
Put the entry
registryshipped with back underkey.The public registrars call this when handed the built-in that shipped under
key, so an override can be undone (#1363). It stores the shipped object itself, a descriptor if a descriptor shipped, and it is a silent no-op when the incumbent already names the shipped class, as decided bysame_entry().
- pcapkit.interface.registry.restore_shipped_dumper(registry, format, shipped, ext)[source]¶
Put the dumper
registryshipped with back underformat.The
__output__counterpart ofrestore_shipped(): an entry is a(dumper, ext)pair, so the shipped pair itself is stored whenextmatches it, and the shipped dumper with the newextotherwise. A re-registration that only changesextstays silent, as the dumper registrars document.The incumbent is read with
dict.get(), so an__output__that is acollections.defaultdictgains no entry from the lookup.- Parameters:
- Warns:
RegistryWarning – If a different dumper is registered for
format; it is overwritten.