Public Signatures¶
How a public callable takes its arguments: the functions of pcapkit.interface,
the public classes of pcapkit.foundation, and
Protocol and its subclasses. Ruled by the owner on
#2834, over one configuration object held in a context variable, which would
move each call’s contract out of its signature. A public signature that breaks a rule
here is brought into line by a change of its own.
The Rules¶
The primary input stays positional, and everything after it is keyword-only, so adding a parameter moves no other.
One name per concept.
layer,protocol,context,strictandstoremean the same wherever they appear. A format isformat, neverfmt;timeoutis a number of seconds, never a flag; a callback is added byregister_callback(callback, *, index=None), under no second name; andanalyzeis the one spelling, for a keyword as for a method.A wrapper mirrors the signature of what it wraps – a
pcapkit.interfacefunction that of the class it builds, and apcapkit.foundation.registryfunction that of the classmethod it calls (The Registry Protocol) – and a test pins the two equal.A real default is written in the signature.
Nonemeans off, never a default chosen out of sight.A keyword set is closed. An unknown keyword is refused, never accepted and ignored.
Feature Options¶
A feature’s options are grouped in a *Options class, whose fields take the
keyword names of the class the feature configures. The feature’s own keyword takes:
Value |
Means |
|---|---|
|
the feature is off |
a list of registered names |
shorthand for the options object naming them, its other fields at their defaults |
the options object |
the feature is on, as the object configures it |
So an option for a feature that is off cannot be passed at all, rather than being
silently ignored. [] meaning off was ruled in review of #2868
(#2836), and so were these:
The
*Optionsclasses are exported frompcapkit.interface, and so frompcapkit, beside the functions that take them.A field with no real default, such as the output file or the protocol names, stays required rather than gaining a guessed one.
An unknown name, for
layeras for a format or a protocol, raisesFormatError, and a feature keyword of the wrong type raisesRegistryError, aTypeError.
A PCAPKIT_* tunable is a process-wide limit or policy; an option is per
call. A setting a caller varies from one call to the next is a keyword, and one that
bounds the whole process, as TCP_GAP_LIMIT does, is
a pcapkit.utilities.config tunable. The Options suffix keeps the classes
from reading as those tunables.
Protocols¶
Calling a protocol class with a file parses, and with keywords alone builds, ruled
on #3081 over the parse-only call of #2840. Each shape has an explicit
form, from_file() and
from_fields():
Proto(file, length=None, /, *, layer=None, protocol=None, context=None)
Proto(*, context=None, **fields)
Proto.from_file(file, length=None, /, *, layer=None, protocol=None, context=None)
Proto.from_fields(*, context=None, **fields)
lengthis positional besidefile, as #2834 specified for the protocols: the one exception to rule 1, since it bounds the input rather than configuring the call.A parse takes no field and a construction no stop, so each keyword set is closed. Given no file,
layerandprotocolare fields where the class takes one of that name, asIPv4,PPPandIP_Pseudotakeprotocol, and are refused otherwise, aslengthis. A keyword is always a keyword:file=andlength=are fields too, never the positional parameters of their names (#3081). Each shape is an overload, so a type checker readsprotocolthere as the field on a construction and as the stop on a parse.layeris a layer name andprotocola protocol name, class or instance, andNoneis the only no stop, by rule 4.A parse that needs an input of its own takes it keyword-only, before the stops:
Class, and the classes deriving from it
Keywords
version, which names the member and must be the class’s own (Dispatching Bases)num,headernum,sct,ctxextensionframedbyteorderA construction takes each as a field where the class’s hooks do, and
versionnames the member there too.What a layer hands the layer it carries – the code it dispatched on, its packet data, its IP version – travels through one private channel,
_from_parent(), to the hooks, never through a public signature.analyze(),analyze()andanalyze()take the parse’s keywords, by rule 3.
Each misuse raises a TypeError, or one of the library’s errors where a value
rather than a keyword is wrong:
Misuse |
Raises |
|---|---|
a field, or an unknown keyword, given a file |
|
no octets, as |
|
a stop that is no field, or a |
|
a |
|
an unknown construction keyword |
|
a |
|
a |
|
another member’s |
Incompatible Changes¶
An incompatible signature change is made outright, with no shim. A shim taking the
old keywords hides what the call accepts from its signature, which these rules exist to
show. #2594 set the precedent, for the keyword groups of make().
No default flip keeps a shim either, reassemble()’s
strict included, over the one-release warning #2834 gave it. Ruled in review
of #2894 (#2837).