Skip to content

Commit e0db51b

Browse files
committed
docs(protocols): fifth whole-repo pass over application, misc and the protocol base (#1103)
- keep_short_read: the key is listed in Data.__included__, not an ordinary one (#2003) - register_frame/register_block/_option/_record/_secrets: meth is a method name or a (parser, constructor) pair, not a single callable - SHB pre_pack: the magic is not palindromic; NRB length is the Block Total Length - Frame._ghdr holds the data model; the CB padding comment names the right idiom; HTTP/2 __length_hint__ is a hint, not a total length - ngap.rst: unnamed values, not IEs; misc/index.rst grammar - document the helpers rendered text names: Schema._cut_short_read, keep_short_read, replay_short_read, _cut_last_line, _malformed_line_message Prose only; AST unchanged. tests/project docs tests and nearby protocol tests pass.
1 parent 4c3d301 commit e0db51b

9 files changed

Lines changed: 41 additions & 19 deletions

File tree

‎docs/source/pcapkit/protocols/application/ngap.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Known Limitations
9595
* **The specification version is that of the installed decoder, not this
9696
package's.** The IE and procedure enumerations were generated from
9797
``NGAP_Constants`` of |pycrate|_ 0.8.1 (Release-18-era). A |pycrate|_ that
98-
carries a newer NGAP will decode IEs that
98+
carries a newer NGAP will decode values that
9999
:class:`~pcapkit.const.ngap.procedure_code.ProcedureCode` and
100100
:class:`~pcapkit.const.ngap.protocol_ie.ProtocolIE` do not name. Such a
101101
value resolves to a non-registering member called ``Unassigned`` rather than

‎docs/source/pcapkit/protocols/index.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ Header Schema
202202
.. autoattribute:: __fields__
203203
:no-value:
204204

205+
.. automethod:: _cut_short_read
206+
205207
.. autoclass:: pcapkit.protocols.schema.schema.EnumSchema
206208
:no-members:
207209
:show-inheritance:
@@ -219,6 +221,10 @@ Header Schema
219221

220222
.. autodecorator:: pcapkit.protocols.schema.schema.schema_final
221223

224+
.. autofunction:: pcapkit.protocols.schema.schema.keep_short_read
225+
226+
.. autofunction:: pcapkit.protocols.schema.schema.replay_short_read
227+
222228
Internal Definitions
223229
~~~~~~~~~~~~~~~~~~~~
224230

‎docs/source/pcapkit/protocols/misc/index.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Auxiliary Protocols
66
.. module:: pcapkit.protocols.schema.misc
77

88
:mod:`pcapkit.protocols.misc` contains the auxiliary protocol implementations.
9-
Such includes the PCAP header classes, the PCAP-NG
9+
These include the PCAP header classes, the PCAP-NG
1010
:class:`~pcapkit.protocols.misc.pcapng.PCAPNG` class, the
1111
:class:`~pcapkit.protocols.misc.raw.Raw` class for not-supported protocols, and
1212
the :class:`~pcapkit.protocols.misc.null.NoPayload` class for indication of

‎docs/source/pcapkit/protocols/misc/pcapng.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ shared with the PCAP frame header and documented in
585585
.. autofunction:: pcapkit.protocols.schema.misc.pcapng.zigbee_key_trailing
586586
.. autofunction:: pcapkit.protocols.schema.misc.pcapng.zigbee_key_held
587587
.. autofunction:: pcapkit.protocols.schema.misc.pcapng._spb_data_length
588+
.. autofunction:: pcapkit.protocols.schema.misc.pcapng._cut_last_line
589+
.. autofunction:: pcapkit.protocols.schema.misc.pcapng._malformed_line_message
588590

589591
Data Models
590592
-----------

‎pcapkit/protocols/application/httpv2.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,9 @@ def register_frame(cls, code: 'Enum_Frame', meth: 'str | tuple[FrameParser, Fram
490490
491491
Args:
492492
code: HTTP frame type code.
493-
meth: Method name or callable to parse and/or construct the frame.
493+
meth: Name of the ``_read_http_${name}`` and ``_make_http_${name}``
494+
methods, or a ``(parser, constructor)`` pair of callables; see
495+
:attr:`__frame__`.
494496
495497
Warns:
496498
RegistryWarning: If a different entry is already registered for
@@ -512,7 +514,7 @@ def register_frame(cls, code: 'Enum_Frame', meth: 'str | tuple[FrameParser, Fram
512514
##########################################################################
513515

514516
def __length_hint__(self) -> 'Literal[9]':
515-
"""Total length of corresponding protocol."""
517+
"""Return an estimated length for the object."""
516518
return 9
517519

518520
##########################################################################

‎pcapkit/protocols/misc/pcap/frame.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def __post_init__(self, file: 'Optional[IO[bytes] | bytes]' = None, length: 'Opt
473473
"""
474474
#: int: frame index number
475475
self._fnum = num
476-
#: pcapkit.protocols.misc.pcap.header.Header: Global header of the PCAP file.
476+
#: pcapkit.protocols.data.misc.pcap.header.Header: Global header of the PCAP file.
477477
self._ghdr = header
478478

479479
#: pcapkit.const.reg.linktype.LinkType: next layer protocol index

‎pcapkit/protocols/misc/pcapng.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,9 @@ def register_block(cls, code: 'Enum_BlockType', meth: 'str | tuple[BlockParser,
10731073
10741074
Args:
10751075
code: PCAP-NG block type code.
1076-
meth: Method name or callable to parse and/or construct the block.
1076+
meth: Name of the ``_read_block_${name}`` and ``_make_block_${name}``
1077+
methods, or a ``(parser, constructor)`` pair of callables; see
1078+
:attr:`__block__`.
10771079
10781080
Warns:
10791081
RegistryWarning: If a different entry is already registered for
@@ -1096,7 +1098,9 @@ def register_option(cls, code: 'Enum_OptionType', meth: 'str | tuple[OptionParse
10961098
10971099
Args:
10981100
code: PCAP-NG option type code.
1099-
meth: Method name or callable to parse and/or construct the option.
1101+
meth: Name of the ``_read_option_${name}`` and
1102+
``_make_option_${name}`` methods, or a ``(parser, constructor)``
1103+
pair of callables; see :attr:`__option__`.
11001104
11011105
Warns:
11021106
RegistryWarning: If a different entry is already registered for
@@ -1120,7 +1124,9 @@ def register_record(cls, code: 'Enum_RecordType', meth: 'str | tuple[RecordParse
11201124
11211125
Args:
11221126
code: PCAP-NG name resolution record type code.
1123-
meth: Method name or callable to parse and/or construct the name resolution record.
1127+
meth: Name of the ``_read_record_${name}`` and
1128+
``_make_record_${name}`` methods, or a ``(parser, constructor)``
1129+
pair of callables; see :attr:`__record__`.
11241130
11251131
Warns:
11261132
RegistryWarning: If a different entry is already registered for
@@ -1143,7 +1149,9 @@ def register_secrets(cls, code: 'Enum_SecretsType', meth: 'str | tuple[SecretsPa
11431149
11441150
Args:
11451151
code: PCAP-NG decryption secrets type code.
1146-
meth: Method name or callable to parse and/or construct the decryption secrets.
1152+
meth: Name of the ``_read_secrets_${name}`` and
1153+
``_make_secrets_${name}`` methods, or a ``(parser, constructor)``
1154+
pair of callables; see :attr:`__secrets__`.
11471155
11481156
Warns:
11491157
RegistryWarning: If a different entry is already registered for
@@ -4851,7 +4859,7 @@ def _make_block_cb(self, block: 'Optional[Data_CustomBlock]' = None, *,
48514859

48524860
# NOTE: ``-n % 4`` is the octet count needed to reach the next 32-bit
48534861
# boundary, and zero when already there. Integer arithmetic throughout,
4854-
# unlike the ``math.ceil(n / 4) * 4 - n`` idiom used elsewhere in this
4862+
# unlike the ``math.ceil(n / 4) * 4`` idiom used elsewhere in this
48554863
# file, which routes a length through a float.
48564864
cb_data = data.pack() if isinstance(data, Schema) else data
48574865
cb_data += bytes(-len(cb_data) % 4)

‎pcapkit/protocols/schema/misc/pcapng.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,10 +1318,13 @@ def pre_pack(self, packet: 'dict[str, Any]') -> 'None':
13181318
This method is expected to directly modify any data stored
13191319
in the ``packet`` and thus no return is required.
13201320
1321-
The Byte-Order Magic is not carried by any field of the schema --
1322-
:attr:`magic` is the palindromic constant, identical in either byte
1323-
order -- so it is seeded here from the byte order the packet data
1324-
asks for, and from the host byte order when it asks for none.
1321+
:func:`shb_byteorder_callback` takes the byte order from the
1322+
Byte-Order Magic as :attr:`match` reads it, and a constructed block
1323+
has no :attr:`match` to read -- a forward match packs no octets --
1324+
nor can :attr:`magic` stand in, since it holds the same constant in
1325+
either byte order. So :attr:`match` is seeded here from the byte
1326+
order the packet data asks for, and from the host byte order when it
1327+
asks for none; a ``match`` already in ``packet`` is kept.
13251328
13261329
"""
13271330
if 'match' in packet:
@@ -2050,7 +2053,7 @@ def __init__(self, type: 'Enum_OptionType', length: 'int', ip: 'IPv6Address | by
20502053
class NameResolutionBlock(BlockType, code=Enum_BlockType.Name_Resolution_Block):
20512054
"""Header schema for PCAP-NG Name Resolution Block (NRB)."""
20522055

2053-
#: Record total length.
2056+
#: Block total length.
20542057
length: 'int' = UInt32Field(callback=byteorder_callback)
20552058
#: Name resolution records.
20562059
records: 'list[NameResolutionRecord]' = OptionAreaField(

‎pcapkit/protocols/schema/schema.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,10 +1486,11 @@ def keep_short_read(protocol: 'ProtocolBase') -> 'None':
14861486
Called by the layer base classes once a parse is done. When the data ended
14871487
inside one of the header's fields, ``info`` gains the ``__short_read__``
14881488
record :meth:`Schema.unpack` made, so that :func:`replay_short_read` can
1489-
cut the rebuild back to what was captured (:issue:`1458`). The key is an
1490-
ordinary one, so :meth:`Info.to_dict <pcapkit.corekit.infoclass.Info.to_dict>`
1491-
carries it and ``from_data(info.to_dict())`` replays it too; it is absent
1492-
for a header that was captured whole.
1489+
cut the rebuild back to what was captured (:issue:`1458`). The key is listed
1490+
in :attr:`Data.__included__ <pcapkit.protocols.data.data.Data.__included__>`,
1491+
so :meth:`Info.to_dict <pcapkit.corekit.infoclass.Info.to_dict>` carries it
1492+
and ``from_data(info.to_dict())`` replays it too; it is absent for a header
1493+
that was captured whole.
14931494
14941495
"""
14951496
header = cast('Optional[Schema]', getattr(protocol, '__header__', None))

0 commit comments

Comments
 (0)