Skip to content

Commit 1b4f970

Browse files
authored
refactor(protocols)!: group each protocol's protocol, schema and data into one package (#2534) (#2753)
The output of codemod-v2.py on 4f62f52, with no hand edits. - protocols/<layer>/<proto>.py and its schema/ and data/ modules become protocols/<layer>/<proto>/{protocol,schema,data}.py; each package __init__ exports its class alone, eagerly, and binds each public class its schema and data modules define as Schema_<name> and Data_<name>, outside __all__, in a block per role under a "# Header Schemas" or "# Data Models" heading, as ruled in review of #2753. A [tool.isort] section in pyproject.toml keeps isort off these files, filter_files included; protocol-family-grouping.rst shows the layout and the doc-claims test pins every __init__ to it. - The TLS record data models SSL reads move from tls/data.py to a new ssl/data.py, as pieces the family shares; tls/data.py keeps TLS. - The schema/ and data/ trees and their aggregations go, with no alias: schema/schema.py is protocols/schema.py, data/data.py and data/protocol.py merge into protocols/data.py, and ipv6_option merges into ipv6_ext.schema. - ProtocolBase.__init_subclass__ finds a class's schema and data in its own package and imports Raw's on demand. - Imports, ModuleDescriptor strings, docs targets, paths and test specs are rewritten; released changelogs get every role target, 1.6.0 stays with #2483. - versionremoved records every name v1.5.1 shipped that no longer resolves at its old path, read from the tag by a new util/shipped_names.py into a checked-in fixture; a re-export points at its defining module, and the address patterns #2614 removed unrecorded get their note too. - The 1744 test gains TestShippedNames, which fails on any such name left unrecorded; test_public_api leaves the ruled aliases out of its unlisted names; tests that walked or pinned the old trees follow the new layout, two that pinned only the aggregations are deleted, and a new test pins the layout and the aliases. All modules import, protocol models are unchanged, every unittest leg and project guard passes, and a non-editable docs build is warning-free.
1 parent 4f62f52 commit 1b4f970

1,022 files changed

Lines changed: 20982 additions & 16016 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Mechanical points that decide real cases:
119119
- **A private base class must stay documented when a documented subclass carries
120120
`:show-inheritance:`.** Sphinx renders that subclass's `Bases:` line as a link into the private
121121
class's page, so dropping the directive breaks a link a public page renders. This keeps
122-
`pcapkit.protocols.schema.misc.pcapng._OPT_Option` and the other per-block option bases with
122+
`pcapkit.protocols.misc.pcapng.schema._OPT_Option` and the other per-block option bases with
123123
documented subclasses, plus `_IPField`, `_IPInterfaceField` and `_TextField`.
124124
- **Dunders keep their directives.** A `__dunder__` is reached through public syntax, not by name
125125
(`len()` calls `__len__`, `obj[key]` calls `__getitem__`), so overriding one changes behaviour a

‎docs/source/changelog/1.5.0.rst‎

Lines changed: 133 additions & 133 deletions
Large diffs are not rendered by default.

‎docs/source/conf.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import pcapkit
5454
from pcapkit.corekit.infoclass import Info
5555
from pcapkit.corekit.sentinels import NO_VALUE
56-
from pcapkit.protocols.schema.schema import Schema
56+
from pcapkit.protocols.schema import Schema
5757

5858
if TYPE_CHECKING:
5959
from types import FunctionType, ModuleType
@@ -122,9 +122,9 @@
122122
# These are deliberately opt-in per site rather than an automatic ``#NNN`` rule,
123123
# because no digit-keyed pattern can tell a citation from a packet-diagram label:
124124
# ``#\d{3}`` misses every two- and four-digit number, while ``#\d+`` catches the
125-
# one-digit RFC diagram labels in ``pcapkit/protocols/internet/hip.py``,
126-
# ``pcapkit/protocols/transport/sctp.py`` and
127-
# ``pcapkit/protocols/schema/internet/hip.py`` -- ``DH GROUP ID #1``,
125+
# one-digit RFC diagram labels in ``pcapkit/protocols/internet/hip/protocol.py``,
126+
# ``pcapkit/protocols/transport/sctp/protocol.py`` and
127+
# ``pcapkit/protocols/internet/hip/schema.py`` -- ``DH GROUP ID #1``,
128128
# ``Gap Ack Block #1`` and the like -- which are not references to anything. A role
129129
# nobody writes cannot corrupt them.
130130
#
@@ -446,7 +446,7 @@ def bind_guarded_names(mock_imports: 'List[str]', module: 'ModuleType') -> None:
446446
:exc:`NameError` for it and the schema class signatures fell back to the bare
447447
``_VT``. The Python domain then found both
448448
:data:`pcapkit.corekit.multidict._VT` and
449-
:data:`pcapkit.protocols.schema.schema._VT` for it, warned, and linked the
449+
:data:`pcapkit.protocols.schema._VT` for it, warned, and linked the
450450
first, which is the wrong one. Binding what the library recorded restores
451451
what the releases before 3.14 did.
452452

‎docs/source/contributing/conventions/const-vendor-pairing.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ predated the crawler and had drifted from it in the ways cross-review of
7676
IANA counterpart and no reference anywhere in the codebase (IANA leaves 0
7777
inside its 0-19 ``Unassigned`` band, unnamed); it is dropped, and value 0
7878
now resolves to ``Unassigned`` like the rest of that band.
79-
:class:`~pcapkit.protocols.application.ssl.SSL` never checked this member
79+
:class:`~pcapkit.protocols.application.ssl.protocol.SSL` never checked this member
8080
by name -- its wire-type allowlist already excluded value 0 by construction
8181
-- so the sentinel's removal is behaviourally a no-op there too.
8282
* the committed ``HandshakeType`` cited RFC 5246, 6066 and 4680 for several

‎docs/source/contributing/conventions/extension-header-subclassing.rst‎

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ Extension-Header Base Classes
44
-----------------------------
55

66
Every IPv6 extension header in this package subclasses
7-
:class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext`. Some name a **second** base
7+
:class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext`. Some name a **second** base
88
as well, and which ones do is a ruling rather than an accident. The owner ruled, in
9-
review of the rename that made :class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext` the
9+
review of the rename that made :class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext` the
1010
shared base (:issue:`917`), that a header usable *only* as an extension header inherits
11-
:class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext` and nothing else --
12-
:class:`~pcapkit.protocols.internet.ipv6_frag.IPv6_Frag` being the example -- while one
11+
:class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext` and nothing else --
12+
:class:`~pcapkit.protocols.internet.ipv6_frag.protocol.IPv6_Frag` being the example -- while one
1313
that is usable as a standalone protocol in its own right inherits both
14-
:class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext` and
14+
:class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext` and
1515
:class:`~pcapkit.protocols.internet.internet.Internet` (or
16-
:class:`~pcapkit.protocols.internet.ipsec.IPsec`), as
17-
:class:`~pcapkit.protocols.internet.esp.ESP` does.
16+
:class:`~pcapkit.protocols.internet.ipsec.protocol.IPsec`), as
17+
:class:`~pcapkit.protocols.internet.esp.protocol.ESP` does.
1818

1919
The family as it stands:
2020

@@ -25,26 +25,26 @@ The family as it stands:
2525
* - Header
2626
- Bases
2727
- Classification
28-
* - :class:`~pcapkit.protocols.internet.hopopt.HOPOPT`,
29-
:class:`~pcapkit.protocols.internet.ipv6_route.IPv6_Route`,
30-
:class:`~pcapkit.protocols.internet.ipv6_frag.IPv6_Frag`,
31-
:class:`~pcapkit.protocols.internet.ipv6_opts.IPv6_Opts`,
32-
:class:`~pcapkit.protocols.internet.mh.MH`
33-
- :class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext`
28+
* - :class:`~pcapkit.protocols.internet.hopopt.protocol.HOPOPT`,
29+
:class:`~pcapkit.protocols.internet.ipv6_route.protocol.IPv6_Route`,
30+
:class:`~pcapkit.protocols.internet.ipv6_frag.protocol.IPv6_Frag`,
31+
:class:`~pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts`,
32+
:class:`~pcapkit.protocols.internet.mh.protocol.MH`
33+
- :class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext`
3434
- extension-header only
35-
* - :class:`~pcapkit.protocols.internet.ah.AH`,
36-
:class:`~pcapkit.protocols.internet.esp.ESP`
37-
- :class:`~pcapkit.protocols.internet.ipsec.IPsec`,
38-
:class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext`
35+
* - :class:`~pcapkit.protocols.internet.ah.protocol.AH`,
36+
:class:`~pcapkit.protocols.internet.esp.protocol.ESP`
37+
- :class:`~pcapkit.protocols.internet.ipsec.protocol.IPsec`,
38+
:class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext`
3939
- **also standalone**
40-
* - :class:`~pcapkit.protocols.internet.hip.HIP`
41-
- :class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext`,
40+
* - :class:`~pcapkit.protocols.internet.hip.protocol.HIP`
41+
- :class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext`,
4242
:class:`~pcapkit.protocols.internet.internet.Internet`
4343
- **also standalone**
4444

45-
:class:`~pcapkit.protocols.internet.ipsec.IPsec` is itself an
45+
:class:`~pcapkit.protocols.internet.ipsec.protocol.IPsec` is itself an
4646
:class:`~pcapkit.protocols.internet.internet.Internet` subclass, which is the
47-
parenthetical :class:`~pcapkit.protocols.internet.ipsec.IPsec` alternative in the ruling:
47+
parenthetical :class:`~pcapkit.protocols.internet.ipsec.protocol.IPsec` alternative in the ruling:
4848
naming it satisfies the convention, and it is the right second base for a header whose
4949
standalone form is an IPsec one.
5050

@@ -58,15 +58,15 @@ measurably so:
5858

5959
.. code-block:: pycon
6060
61-
>>> from pcapkit.protocols.internet.ipv4 import IPv4
61+
>>> from pcapkit.protocols.internet.ipv4.protocol import IPv4
6262
>>> from pcapkit.protocols.internet.internet import Internet
6363
>>> IPv4.__proto__ is Internet.__proto__
6464
True
6565
6666
The protocol-number registry is **one shared object**, so *every* extension header
6767
is reachable as an IPv4 payload in this library --
68-
:class:`~pcapkit.protocols.internet.hopopt.HOPOPT` and
69-
:class:`~pcapkit.protocols.internet.ipv6_frag.IPv6_Frag` included. Registry
68+
:class:`~pcapkit.protocols.internet.hopopt.protocol.HOPOPT` and
69+
:class:`~pcapkit.protocols.internet.ipv6_frag.protocol.IPv6_Frag` included. Registry
7070
membership therefore says nothing at all about standalone-ness, and a classification
7171
derived from it would make every one of them standalone.
7272

@@ -81,22 +81,22 @@ The IPv4-Payload Test
8181
So the census is read out of the specifications, on the owner's instruction: work
8282
through the RFCs to establish, for each defined IPv6 extension header, whether it is
8383
extension-header-only or a standalone protocol as well, and decide from that whether it
84-
inherits :class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext` alone or names additional bases.
84+
inherits :class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext` alone or names additional bases.
8585

8686
And the limb that decides is **whether a primary source shows the header carried
8787
directly as an IPv4 payload**:
8888

89-
* :class:`~pcapkit.protocols.internet.ah.AH` -- :rfc:`4302#section-3.1.1`, *"In the
89+
* :class:`~pcapkit.protocols.internet.ah.protocol.AH` -- :rfc:`4302#section-3.1.1`, *"In the
9090
context of IPv4, this calls for placing AH after the IP header"*, with a
9191
before-and-after IPv4 diagram.
92-
* :class:`~pcapkit.protocols.internet.esp.ESP` -- :rfc:`4303#section-3.1.1`, the
92+
* :class:`~pcapkit.protocols.internet.esp.protocol.ESP` -- :rfc:`4303#section-3.1.1`, the
9393
same sentence and the same diagram for ESP.
94-
* :class:`~pcapkit.protocols.internet.hip.HIP` -- :rfc:`7401#appendix-C.2`,
94+
* :class:`~pcapkit.protocols.internet.hip.protocol.HIP` -- :rfc:`7401#appendix-C.2`,
9595
*"IPv4 HIP Packet (I1 Packet)"*, whose worked checksum is over an IPv4 header
9696
carrying ``Next Header: 139``. :rfc:`7401#section-5.1` also calls the HIP header
9797
*"logically an IPv6 extension header"*, so HIP is genuinely both.
9898

99-
:class:`~pcapkit.protocols.internet.mh.MH` is the instructive failure, because it
99+
:class:`~pcapkit.protocols.internet.mh.protocol.MH` is the instructive failure, because it
100100
**is** a protocol in its own right and still does not qualify:
101101
:rfc:`6275#section-6.1.1` defines its checksum over a pseudo-header of *"IPv6 header
102102
fields"* whose addresses are *"the addresses that appear in the Source and
@@ -105,7 +105,7 @@ is no IPv4 variant of that computation -- and the IPv4 equivalent function is no
105105
protocol 135 at all, since :rfc:`5944` carries Mobile IPv4 over UDP port 434.
106106
``Shim6`` (140) has the same shape and the same verdict; this package carries no parser
107107
class for it, so nothing implements the classification, but a future one inherits
108-
:class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext` alone.
108+
:class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext` alone.
109109

110110
.. important::
111111

@@ -115,13 +115,13 @@ class for it, so nothing implements the classification, but a future one inherit
115115
review of :issue:`917` and not
116116
taken, so MH and ``Shim6`` stay extension-only. A header that is a protocol in its
117117
own right but structurally cannot be an IPv4 payload names
118-
:class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext` alone.
118+
:class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext` alone.
119119

120120
Explicit Base Declarations
121121
~~~~~~~~~~~~~~~~~~~~~~~~~~
122122

123123
Name the second base **explicitly**, even where it is already in the MRO.
124-
:class:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext` derives
124+
:class:`~pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext` derives
125125
:class:`~pcapkit.protocols.internet.internet.Internet`, so every extension header
126126
reaches :class:`~pcapkit.protocols.internet.internet.Internet` transitively and an
127127
``__mro__`` check cannot tell the two groups apart. The declaration is the only place the
@@ -140,7 +140,7 @@ held to the convention whether or not anyone remembers this page.
140140
ESP's Two Facts
141141
~~~~~~~~~~~~~~~
142142

143-
Two facts about :class:`~pcapkit.protocols.internet.esp.ESP` coexist, and each is
143+
Two facts about :class:`~pcapkit.protocols.internet.esp.protocol.ESP` coexist, and each is
144144
routinely mistaken for a refutation of the other.
145145

146146
**It is an extension header.** IANA's *IPv6 Extension Header Types* registry lists
@@ -157,14 +157,14 @@ carries the same extension-mode contract as its siblings.
157157
**And it terminates the chain walk.** :rfc:`4303` places ESP's Next Header byte
158158
inside the *encrypted* trailer, so with no key material there is nothing to continue
159159
on: ESP's own data model reports ``next`` as :obj:`None`, and
160-
:meth:`IPv6._decode_next_layer <pcapkit.protocols.internet.ipv6.IPv6._decode_next_layer>`
160+
:meth:`IPv6._decode_next_layer <pcapkit.protocols.internet.ipv6.protocol.IPv6._decode_next_layer>`
161161
ends the ordinary way one iteration later -- not because ESP lacks a parser, which
162162
it has, but because it cannot hand the walk a successor.
163163

164164
The full reasoning, including how ESP's terminal case differs from 253/254's, is
165165
written where the code is and is deliberately not restated at length here: see
166-
:meth:`IPv6._import_next_layer <pcapkit.protocols.internet.ipv6.IPv6._import_next_layer>`
167-
and the module docstring of :mod:`pcapkit.protocols.internet.ipv6_ext`.
166+
:meth:`IPv6._import_next_layer <pcapkit.protocols.internet.ipv6.protocol.IPv6._import_next_layer>`
167+
and the module docstring of :mod:`pcapkit.protocols.internet.ipv6_ext.protocol`.
168168

169169
.. caution::
170170

‎docs/source/contributing/conventions/index.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ House Conventions
1919
:meth:`~pcapkit.protocols.protocol.Protocol.__index__` returns;
2020
* :ref:`extension-header-subclassing` -- a protocol class hierarchy;
2121
* :ref:`protocol-family-grouping` -- how a protocol family's base and members
22-
spell :meth:`~pcapkit.protocols.protocol.Protocol.id`, how a protocol class
23-
is named after its module, and how quietly a next-layer fallback keeps a
24-
refused layer as :class:`~pcapkit.protocols.misc.raw.Raw`;
22+
spell :meth:`~pcapkit.protocols.protocol.Protocol.id`, how a protocol's
23+
package, modules and classes are named, and how quietly a next-layer fallback keeps a
24+
refused layer as :class:`~pcapkit.protocols.misc.raw.protocol.Raw`;
2525
* :ref:`protocol-member-order` -- the order of members in a protocol class body;
2626
* :ref:`protocol-layer-placement` -- which subpackage a dissector belongs in;
2727
* :ref:`process` -- the repository rather than any of its code;

‎docs/source/contributing/conventions/process.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ carrying it are that kind:
304304
:issue:`759` raising one where a
305305
single-bit lookup used to return a member;
306306
* a public attribute's meaning --
307-
:issue:`618` swapping :attr:`Frame.len <pcapkit.protocols.data.misc.pcap.frame.Frame.len>`
308-
and :attr:`Frame.cap_len <pcapkit.protocols.data.misc.pcap.frame.Frame.cap_len>`
307+
:issue:`618` swapping :attr:`Frame.len <pcapkit.protocols.misc.pcap.frame.data.Frame.len>`
308+
and :attr:`Frame.cap_len <pcapkit.protocols.misc.pcap.frame.data.Frame.cap_len>`
309309
between the PCAP and PCAP-NG readers;
310310
* a signature or a name a caller writes --
311311
:issue:`806` retyping

0 commit comments

Comments
 (0)