Format and Value Rules

pcapkit.utilities.conformance holds what a reader calls where a value it can read past is wrong, as ruled on #3234: nonconforming() where the value breaks a format or value rule its specification sets – a length cap, a reserved or must-be-zero field, an out-of-range value, a forbidden combination – and anomalous() where the specification is silent but the value is odd. A construction is refused the first and a parse warns of it, while both only warn of the second, unless the engine pcapkit is set to mimic accepts or refuses the value. A failure that leaves nothing more to decode is neither, and its parse still refuses. The protocols share these, and they import pcapkit only from pcapkit.utilities, so they live there (Choosing Between utilities and corekit).

Added in version 1.10.0.

pcapkit.utilities.conformance.nonconforming(message, *, mimic=None)[source]

Refuse or report a value that breaks a format or value rule, as the layer was built.

A reader calls it once per offending field. How the layer being read was built, as constructing tells, and mimic decide what it does:

mimic

Parse

Rebuild (from_data)

Construction (from_fields)

None

warns

warns

raises

'accept'

nothing

nothing

nothing

'refuse'

raises

warns

raises

So a header made from its fields holds to the rule unless the engine mimicked accepts the value, and one parsed and then rebuilt from its data round-trips byte-exactly, reporting what its parse reported: a rebuild is never refused (#3234).

Parameters:
  • message (str) – What is wrong, led by the protocol’s alias.

  • mimic (Literal['accept', 'refuse'] | None) – What the engine pcapkit is set to mimic does with the value at this site, given by the caller where that setting covers it: 'accept' reads and builds it silently, and 'refuse' refuses it. None where no mimic setting covers the site.

Raises:

ProtocolError – As the table says. It is quiet under a next-layer fallback, as any refusal is (#2588).

Warns:

ProtocolWarning – As the table says, through warn().

pcapkit.utilities.conformance.anomalous(message, *, mimic=None)[source]

Report an odd value its specification is silent on, which the reader reads on past.

A reader calls it once per offending field. It follows nonconforming(), but for a construction with no mimic given, which it warns of rather than refuses, since no rule refuses the value:

mimic

Parse

Rebuild (from_data)

Construction (from_fields)

None

warns

warns

warns

'accept'

nothing

nothing

nothing

'refuse'

raises

warns

raises

Parameters:
Raises:

ProtocolError – As the table says, quiet under a next-layer fallback.

Warns:

ProtocolWarning – As the table says, through warn().