Skip to content

Commit c49e4e3

Browse files
authored
docs(protocols): second whole-repo pass over application, misc and the protocol base (#1103) (#1800)
Version directives, 1.1.0-1.4.1 backfill: - Protocol: versionchanged 1.3.0. The built-in families moved onto ProtocolBase, so a built-in protocol is not an instance of Protocol, and a Protocol subclass registers itself in pcapkit.protocols.__proto__. - data.misc.raw.Raw: versionchanged 1.3.3. packet left its fields when the base data class took it over, so the constructor takes protocol and error only. Accuracy: - ProtocolBase.unpack: since #1769, pack() sets __header__ only on the call __post_init__ makes during construction, so the note names that call and from_schema() rather than pack() in general. - HTTP.make: Returns said bytes; it returns the versioned make()'s schema. - pcapkit.protocols.__proto__: the values are ProtocolBase subclasses, and the built-in ones are not Protocol subclasses. AST guard identical on all four files; tests/project and the pack, HTTP and docstring-contract tests pass. Refs #1103
1 parent 2f193ab commit c49e4e3

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎pcapkit/protocols/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
'RARP', 'DRARP',
7171
]
7272

73-
#: dict[str, ~typing.Type[Protocol]]: Protocol registry.
73+
#: dict[str, ~typing.Type[~pcapkit.protocols.protocol.ProtocolBase]]: Protocol registry.
7474
__proto__ = {} # type: dict[str, Type[ProtocolBase]]
7575
for name in __all__:
7676
__proto__[name.upper()] = globals()[name]

‎pcapkit/protocols/application/http.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def make(self,
342342
**kwargs: Arbitrary keyword arguments.
343343
344344
Returns:
345-
bytes: Constructed packet data.
345+
The header schema the versioned ``make`` constructs.
346346
347347
Raises:
348348
ProtocolError: If ``version`` is unknown, or if ``preface`` is

‎pcapkit/protocols/data/misc/raw.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414

1515
@info_final
1616
class Raw(Protocol):
17-
"""Raw packet is an unknown protocol."""
17+
"""Raw packet is an unknown protocol.
18+
19+
.. versionchanged:: 1.3.3
20+
21+
``packet`` is not a field of this class, so its constructor takes
22+
``protocol`` and ``error`` only.
23+
:class:`~pcapkit.protocols.protocol.ProtocolBase` sets ``packet`` on
24+
the data model of every protocol it constructs.
25+
26+
"""
1827

1928
#: Original enumeration of this protocol.
2029
protocol: 'Optional[int]'

‎pcapkit/protocols/protocol.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,9 +841,10 @@ def unpack(self, length: 'Optional[int]' = None, **kwargs: 'Any') -> '_PT':
841841
global packet data to underlying methods. This is useful when
842842
the packet data is not available in the current instance.
843843
844-
When :meth:`pack` or :meth:`from_schema` has already set
845-
:attr:`self.__header__ <Protocol.__header__>`, that schema is
846-
kept, unless it still holds raw :obj:`bytes` where parsing its
844+
When :attr:`self.__header__ <Protocol.__header__>` is already set,
845+
by :meth:`from_schema` or by the :meth:`pack` call that
846+
:meth:`__post_init__` makes to construct the instance, that schema
847+
is kept, unless it still holds raw :obj:`bytes` where parsing its
847848
packed octets yields a schema -- e.g. a raw option given to
848849
``make()`` -- which :meth:`read` cannot consume. The header is
849850
then replaced by the parsed one (:issue:`1312`).
@@ -2489,6 +2490,13 @@ class Protocol(ProtocolBase, Generic[_PT, _ST]):
24892490
:doc:`/ext`. The built-in protocol families do not derive from this class
24902491
but from :class:`ProtocolBase`, whose metaclass is :class:`ProtocolMeta`.
24912492
2493+
.. versionchanged:: 1.3.0
2494+
2495+
The built-in protocol families derive from :class:`ProtocolBase`, so a
2496+
built-in protocol is not an instance of this class, where every one
2497+
was; and a subclass is registered in :data:`pcapkit.protocols.__proto__`
2498+
when it is defined.
2499+
24922500
"""
24932501

24942502
def __init_subclass__(cls, /, schema: 'Optional[Type[_ST]]' = None,

0 commit comments

Comments
 (0)