Base Protocol

pcapkit.protocols.application.application contains only Application, which is a base class for application layer protocols, eg. HTTP/1.*, HTTP/2 and etc.

Changed in version 1.5.0: _decode_next_layer() and _import_next_layer() accept the -1 sentinel, so an application layer protocol can carry the rest of its packet undissected as its payload; every call raised UnsupportedCall (#719).

class pcapkit.protocols.application.application.Application(file=None, length=None, **kwargs)[source]

Bases: ProtocolBase[_PT, _ST], Generic[_PT, _ST]

Abstract base class for application layer protocol family.

An application layer protocol has no further protocol layer above it, so _decode_next_layer() and _import_next_layer() refuse to dispatch on a protocol number. What they do permit is the -1 sentinel, which asks for the rest of the packet undissected and resolves to Raw – trailing bytes are not a further protocol layer – or to NoPayload when nothing remains.

property layer: Literal['Application']

Protocol layer.

_decode_next_layer(dict_, proto=None, length=None, *, packet=None)[source]

Decode next layer protocol.

Parameters:
  • dict_ (TypeVar(_PT, bound= Data)) – info buffer

  • proto (int | None) – next layer protocol index; only the -1 sentinel (the rest, undissected) is accepted

  • length (int | None) – valid (non-padding) length

  • packet (dict[str, Any] | None) – packet info (passed from self.unpack)

Return type:

TypeVar(_PT, bound= Data)

Returns:

Current protocol with the undissected remainder as payload.

Raises:

UnsupportedCall – proto is anything but -1, i.e. a real protocol dispatch, which this protocol doesn’t support.

_import_next_layer(proto, length=None, *, packet=None)[source]

Import next layer extractor.

Parameters:
  • proto (int) – next layer protocol index; only the -1 sentinel (the rest, undissected) is accepted

  • length (int | None) – valid (non-padding) length

  • packet (dict[str, Any] | None) – packet info (passed from self.unpack)

Return type:

ProtocolBase

Returns:

Instance of Raw, or of NoPayload when nothing remains.

Raises:

UnsupportedCall – proto is anything but -1, i.e. a real protocol dispatch, which this protocol doesn’t support.

__layer__: Literal['Application']

Layer of protocol.

__post_init__(file=None, length=None, **kwargs)[source]

Post initialisation hook.

Overloads:
  • self, file (IO[bytes] | bytes), length (Optional[int]), kwargs (Any) → None

  • self, kwargs (Any) → None

Parameters:
  • file (IO[bytes] | bytes | None) – Source packet stream.

  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

See also

For construction arguments, please refer to self.make.

classmethod __index__()[source]

Numeral registry index of the protocol.

Raises:

IntError – This protocol doesn’t support __index__().

Return type:

NoReturn