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

  1. The primary input stays positional, and everything after it is keyword-only, so adding a parameter moves no other.

  2. One name per concept. layer, protocol, context, strict and store mean the same wherever they appear. A format is format, never fmt; timeout is a number of seconds, never a flag; a callback is added by register_callback(callback, *, index=None), under no second name; and analyze is the one spelling, for a keyword as for a method.

  3. A wrapper mirrors the signature of what it wraps – a pcapkit.interface function that of the class it builds, and a pcapkit.foundation.registry function that of the classmethod it calls (The Registry Protocol) – and a test pins the two equal.

  4. A real default is written in the signature. None means off, never a default chosen out of sight.

  5. 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

None or []

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 *Options classes are exported from pcapkit.interface, and so from pcapkit, 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 layer as for a format or a protocol, raises FormatError, and a feature keyword of the wrong type raises RegistryError, a TypeError.

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)
  • length is positional beside file, 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, layer and protocol are fields where the class takes one of that name, as IPv4, PPP and IP_Pseudo take protocol, and are refused otherwise, as length is. A keyword is always a keyword: file= and length= are fields too, never the positional parameters of their names (#3081). Each shape is an overload, so a type checker reads protocol there as the field on a construction and as the stop on a parse.

  • layer is a layer name and protocol a protocol name, class or instance, and None is 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

    IP, ICMP, IGMP, LinuxSLL, HTTP, L2TP

    version, which names the member and must be the class’s own (Dispatching Bases)

    Frame

    num, header

    PCAPNG

    num, sct, ctx

    IPv6_Ext

    extension

    DNS

    framed

    Loopback, Netlink

    byteorder

    A construction takes each as a field where the class’s hooks do, and version names 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() and analyze() 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

TypeError, naming each

no octets, as Proto(None)

TypeError, naming from_fields

a stop that is no field, or a length, given no file

TypeError, naming each

a file or length keyword no field takes

UnexpectedKeyword, saying to pass them positionally to parse

an unknown construction keyword

UnexpectedKeyword, a TypeError and an UnsupportedCall

a layer naming no layer

FormatError

a protocol of no stop’s type

RegistryError, a TypeError

another member’s version

ProtocolError

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).