Skip to content

Commit 1fd97c2

Browse files
authored
docs(corekit): second pass over corekit, const and vendor (#1103) (#1786)
- Version directives: `versionchanged` on `ModuleDescriptor.klass` (#832), `TransportProtocol` (#808, #860, #923), `AppType` (#732, #758, #860) and `Method.get` (#908); `Command`'s timed note becomes one (#860), and `Method`'s gains #870 and #908. Template and generated module change alike. - Stale claims: `AppType.get` does not mint (`numbers.py`), `Vendor._dest_path` handles any depth, `ForwardMatchField.__call__` names its own class, and `field.py`/`field.rst` cite issue #911. - Timed wording rewritten in the `Method`, `Command`, `OptionType` and `AppType` templates (const mirrored), the IPX crawlers, `vendor/__main__.py`, `default.py`, `enum.py` and `fields/misc.py`. - Render: `Info.__new__`'s `Note:` moves above `Args:`, as on `Schema.__new__`; `LINE` strips inline literals inside `**{name}**`, fixing `const/ipv6/smf_dpd_mode.py`. tests/project and 51 referencing test files pass. AST guard: identical bar 5 templates; with all strings blanked only `vendor/default.py` differs. Refs #1103
1 parent f9b467d commit 1fd97c2

25 files changed

Lines changed: 267 additions & 254 deletions

File tree

‎docs/source/pcapkit/corekit/fields/field.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Base Fields
66
.. versionremoved:: 1.5.0
77

88
``pcapkit.corekit.fields.field.NoValueType``, now
9-
:class:`pcapkit.corekit.sentinels.NoValueType` (:issue:`922`,
9+
:class:`pcapkit.corekit.sentinels.NoValueType` (:issue:`911`,
1010
:issue:`1744`), and ``pcapkit.corekit.fields.field.NoValue``, now
1111
:data:`pcapkit.corekit.sentinels.NO_VALUE` (:issue:`937`).
1212

‎pcapkit/const/ftp/command.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class FEATCode(EnumRegistry, StrEnum):
3737
minting the per-command ones at import time as an incidental side
3838
effect of building :class:`Command`'s own rows. GitHub issue :issue:`860`:
3939
that import-time mutation was the same defect shape :issue:`775` removed
40-
from :class:`~pcapkit.const.pcapng.filter_type.FilterType`, just not
41-
previously noticed here. ``_missing_`` still unmints for a keyword that
40+
from :class:`~pcapkit.const.pcapng.filter_type.FilterType`. ``_missing_``
41+
still unmints for a keyword that
4242
turns up on the wire but names none of these -- the extendability the
4343
owner conditionally asked to keep on GitHub issue :issue:`860`: unsure what a
4444
FEAT value absent from the RFC's list means in the CSV table, the owner
@@ -243,16 +243,16 @@ class defines neither ``get`` nor ``_missing_`` of its own to reconcile
243243
class Command(EnumRegistry, StrEnum):
244244
"""[Command] FTP Command
245245
246-
.. note::
246+
.. versionchanged:: 1.5.0
247247
248-
Neither ``_missing_`` nor ``get()`` mints any more. The owner ruled on
248+
Neither ``_missing_`` nor ``get()`` mints a member. The owner ruled on
249249
GitHub issue :issue:`860` that ``get`` should not mint: only IANA-registered
250250
values are legitimate members, a new one is properly created through
251251
:meth:`register`, and ``get`` is not given enough information to create
252252
one. Concretely true here -- a bare wire command word carries no
253-
:attr:`feat`/:attr:`desc`/:attr:`type`/:attr:`conf`, so minting one used
254-
to register a permanent member with all four hollowed out to their
255-
defaults; :meth:`register` is the path that can actually supply them.
253+
:attr:`feat`/:attr:`desc`/:attr:`type`/:attr:`conf`, so a minted member
254+
had all four hollowed out to their defaults; :meth:`register` is the
255+
path that can actually supply them.
256256
257257
"""
258258

@@ -568,10 +568,10 @@ def get(key: 'str', default: 'Optional[str]' = None) -> 'Command':
568568
# unchanged. Two calls naming the same command in different
569569
# case, e.g. ``get('xyzw')`` and ``get('XYZW')``, therefore build
570570
# results that are *not* equal -- each is exactly what its own
571-
# caller passed, which minting's ``_member_map_`` cache used to
572-
# paper over by returning the *first* casing seen for every
573-
# later call regardless of case. Losing that is the one
574-
# observable behaviour change in GitHub issue #860's conversion.
571+
# caller passed. Minting instead returned, through the
572+
# ``_member_map_`` cache, the *first* casing seen for every later
573+
# call regardless of case; that is the one observable behaviour
574+
# change in GitHub issue #860's conversion.
575575
return Command._unregistered_member(default if default is not None else key, name)
576576
return Command[name] # type: ignore[misc]
577577

‎pcapkit/const/http/method.py‎

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class Method(EnumRegistry, StrEnum):
3131
legitimate members, and a new one is created through :meth:`register`,
3232
which can supply :attr:`safe` and :attr:`idempotent` where a bare wire
3333
method verb carries neither. ``get()`` matches ``key`` case-sensitively,
34-
as :rfc:`9110` makes the method token (:issue:`896`).
34+
as :rfc:`9110` makes the method token (:issue:`896`), and checks it
35+
against member values as well as names (:issue:`908`). A member's
36+
:class:`str` payload is its value, so ``Method.GET == 'GET'``
37+
(:issue:`870`).
3538
3639
"""
3740

@@ -199,21 +202,13 @@ def _unregistered_member(cls, value: 'str', name: 'str') -> 'Method':
199202
declared, never reformatted. Only :attr:`name` -- the
200203
identifier, not the value -- is canonicalised.
201204
202-
A *registered* member of this class used to carry something
203-
different here: GitHub issue :issue:`870` found that
204-
:meth:`__new__` called ``str.__new__(cls)`` with no
205-
argument at all, so every one of the 40 declared members'
206-
own :class:`str` payload was permanently empty regardless
207-
of ``value`` (``str(Method.GET) == ''``, and
208-
``Method.GET == 'GET'`` was :obj:`False`) -- true on
209-
``main`` at ``60b85e3a4`` as well as when this docstring
210-
was first written. :issue:`870` fixed :meth:`__new__` to
211-
``str.__new__(cls, value)``, mirroring
205+
A *registered* member carries its value the same way:
206+
:meth:`__new__` passes ``value`` to ``str.__new__``, as
212207
:class:`~pcapkit.const.ftp.command.Command`'s own
213-
``__new__``, so a registered member's payload now agrees
214-
with an *unregistered* member built through this method:
215-
both carry their own value as real :class:`str` content
216-
(``str(Method('frob')) == 'frob'``).
208+
``__new__`` does (:issue:`870`), so both kinds of member
209+
carry their own value as real :class:`str` content
210+
(``str(Method.GET) == 'GET'`` and
211+
``str(Method('frob')) == 'frob'``).
217212
name: Bare label for the unregistered member -- here, the
218213
canonical upper-case form of ``value``, matching the name
219214
every *registered* member of this class is looked up by,
@@ -231,32 +226,31 @@ def get(cls, key: 'str', default: 'Optional[str]' = None) -> 'Method':
231226
"""Backport support for original codes.
232227
233228
Delegates to :meth:`~pcapkit.corekit.enum.EnumLookup.get` for the
234-
lookup itself, per GitHub issue :issue:`908`: the previous override checked
235-
only ``_member_map_`` (names), never ``_value2member_map_``
236-
(values), so the two IANA methods whose member *name* differs from
237-
their *value* -- ``BASELINE_CONTROL`` / ``'BASELINE-CONTROL'`` and
229+
lookup itself, so ``key`` is checked against member values as well
230+
as names (GitHub issue :issue:`908`). That is what resolves the two
231+
IANA methods whose member *name* differs from their *value* --
232+
``BASELINE_CONTROL`` / ``'BASELINE-CONTROL'`` and
238233
``VERSION_CONTROL`` / ``'VERSION-CONTROL'``, a hyphen being unusable
239-
in a Python identifier -- failed to resolve through ``get`` even
240-
though :meth:`_missing_` (and so the constructor) already found
241-
them via that same value-side lookup.
242-
243-
The base is a :class:`classmethod`
244-
(:meth:`~pcapkit.corekit.enum.EnumLookup.get`), and a zero-argument
245-
``super()`` needs a first argument to bind, so this override had to
246-
move from :class:`staticmethod` to :class:`classmethod` to delegate
247-
at all -- see GitHub issue :issue:`908`'s own correction of the fix it
248-
originally proposed. Callers are unaffected by the switch itself:
249-
``Method.get('X')`` binds identically either way.
250-
251-
``default`` keeps its existing meaning here rather than adopting
252-
the base's ``NO_DEFAULT`` sentinel and its value-only fallback --
253-
widening it would be caller-visible, since the base's ``default``
254-
must already name a *registered* value (resolved through
255-
``_value2member_map_``), while this override's ``default`` instead
256-
supplies the *value* of a freshly minted unregistered member.
257-
Nothing in this tree calls ``get`` with a non-``None`` ``default``
258-
to notice today, but widening the signature is a separate change
259-
from this defect and stays out of scope.
234+
in a Python identifier -- which :meth:`_missing_` (and so the
235+
constructor) also finds by value.
236+
237+
It is a :class:`classmethod`, as the base is, because a
238+
zero-argument ``super()`` needs a first argument to bind
239+
(:issue:`908`). ``Method.get('X')`` binds the same as it would on a
240+
:class:`staticmethod`.
241+
242+
``default`` does not follow the base's ``NO_DEFAULT`` sentinel and
243+
value-only fallback: the base's ``default`` must name a
244+
*registered* value (resolved through ``_value2member_map_``), while
245+
this override's ``default`` supplies the *value* of the
246+
unregistered member it builds on a miss.
247+
248+
.. versionchanged:: 1.5.0
249+
250+
A non-:class:`str` ``key`` raises :exc:`ValueError`
251+
(:issue:`908`). ``get(42)`` and ``get(None)`` raised
252+
:exc:`AttributeError` from ``key.upper()``, and ``get(b'GET')``
253+
raised :exc:`TypeError`.
260254
261255
Args:
262256
key: Key to get enum item. Looked up case-**sensitively**,
@@ -267,26 +261,20 @@ def get(cls, key: 'str', default: 'Optional[str]' = None) -> 'Method':
267261
command codes are not. Checked against both member names
268262
and values, via the base's own precedence -- name before
269263
value -- so a value-only match such as
270-
``'BASELINE-CONTROL'`` now resolves too, closing GitHub
271-
issue :issue:`908`.
264+
``'BASELINE-CONTROL'`` resolves too (:issue:`908`).
272265
default: Value for the unregistered member built when ``key``
273266
matches neither a name nor a value. ``None``, the
274-
default, uses ``key`` itself -- unchanged from before
275-
GitHub issue :issue:`908`.
267+
default, uses ``key`` itself.
276268
277269
Raises:
278270
ValueError: If ``key`` is not a :class:`str`. This reaches the
279271
caller from the base's non-``str`` branch, which calls
280272
``cls(key)`` and so ``_missing_``, and is **not** caught by
281273
the ``except KeyError`` fallback below -- only a failed
282-
*name* lookup is. The non-``str`` surface therefore moved
283-
with GitHub issue :issue:`908`: ``get(42)`` and ``get(None)`` used
284-
to raise :exc:`AttributeError` from ``key.upper()``, and
285-
``get(b'GET')`` used to *return* a member whose name and
286-
value were both the :class:`bytes` object. Raising is the
287-
intended behaviour -- a ``bytes``-valued ``Method`` is not a
288-
thing this registry should hand back -- but it is a change,
289-
so it is stated rather than left to be discovered.
274+
*name* lookup is. Raising is the intended behaviour for
275+
``get(b'GET')`` as well: a member whose name and
276+
value were both the :class:`bytes` object is not a thing
277+
this registry should hand back.
290278
291279
:meta private:
292280
"""

‎pcapkit/const/ipv6/smf_dpd_mode.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
.. module:: pcapkit.const.ipv6.smf_dpd_mode
77
8-
This module contains the constant enumeration for **Simplified Multicast Forwarding Duplicate Packet Detection (``SMF_DPD``) Options**,
8+
This module contains the constant enumeration for **Simplified Multicast Forwarding Duplicate Packet Detection (SMF_DPD) Options**,
99
which is automatically generated from :class:`pcapkit.vendor.ipv6.smf_dpd_mode.SMFDPDMode`.
1010
1111
"""

‎pcapkit/const/pcapng/option_type.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,28 +344,28 @@ def get(key: 'int | str', default: 'int' = -1, *, namespace: 'str' = 'opt') -> '
344344
temp_ns.update(OptionType.__members_ns__.get(namespace, {}))
345345
if key in temp_ns:
346346
return temp_ns[key]
347-
# NOTE: GitHub issue #860. This used to extend_enum(...) a
347+
# NOTE: GitHub issue #860. An extend_enum(...) here would mint a
348348
# permanent member as a side effect of a mere lookup -- exactly
349349
# the ``get``/``_missing_`` minting the owner's ruling forbids,
350350
# here on the wire-facing path
351351
# (:meth:`pcapkit.protocols.misc.pcapng.PCAPNG._make_pcapng_options`
352352
# calls this with raw option-code bytes off the wire).
353353
# ``_unregistered_member`` never touches ``__members_ns__``
354-
# either, so a genuinely unknown option code no longer grows
355-
# either lookup table.
354+
# either, so a genuinely unknown option code grows neither
355+
# lookup table.
356356
return OptionType._unregistered_member(key, '%s_unknown' % namespace)
357357
if key in OptionType.__members__:
358358
return getattr(OptionType, key)
359359
# NOTE: a member's value is its formatted ``'{name} [{value}]'``
360360
# string, so ``get(member.value)`` resolves it as ``cls(value)`` would.
361361
if key in OptionType._value2member_map_: # type: ignore[misc]
362362
return OptionType._value2member_map_[key] # type: ignore[misc,return-value]
363-
# NOTE: same ruling, the str-keyed path: this used to mint ``key``
364-
# itself as the member's name with ``default`` as its value. Neither
363+
# NOTE: same ruling, the str-keyed path: rather than mint ``key``
364+
# itself as the member's name with ``default`` as its value -- neither
365365
# ``get`` nor ``_missing_`` has enough information to register one
366-
# properly -- there is no namespace, description or anything else
367-
# IANA would attach to it -- so this now returns an unregistered
368-
# pseudo-member with the same attributes the old mint would have set.
366+
# properly, as there is no namespace, description or anything else
367+
# IANA would attach to it -- this returns an unregistered
368+
# pseudo-member with the same attributes such a mint would set.
369369
return OptionType._unregistered_member(default, key)
370370

371371
@classmethod

‎pcapkit/const/reg/apptype/apptype.py‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@
2727

2828

2929
class TransportProtocol(EnumLookup, IntEnum):
30-
"""Transport layer protocol."""
30+
"""Transport layer protocol.
31+
32+
.. versionchanged:: 1.5.0
33+
34+
An ``aenum.IntEnum`` rather than an ``aenum.IntFlag`` (:issue:`808`),
35+
numbered sequentially: ``sctp`` is ``3`` and ``dccp`` is ``4``, where
36+
they were ``4`` and ``8``, and no :class:`int` is decoded as a ``|``
37+
composite (:issue:`860`). :meth:`get` refuses a name no member
38+
declares, with :exc:`~pcapkit.utilities.exceptions.EnumKeyError`,
39+
rather than minting a member for it (:issue:`808`, :issue:`923`).
40+
41+
"""
3142

3243
# mypy has no aenum plugin, so this class is a plain class to it: every
3344
# member below is cast rather than left as a bare auto()-valued one --
@@ -222,6 +233,15 @@ class AppType(EnumRegistry, StrEnum):
222233
makes it subclassable at all, since :mod:`aenum` refuses to extend an
223234
enumeration that already has members.
224235
236+
.. versionchanged:: 1.5.0
237+
238+
Split by transport protocol (:issue:`732`): :mod:`pcapkit.const.reg.apptype`
239+
is a package, and every assignment is a member of one of the four
240+
registries above rather than of this class. ``get()`` raises
241+
:exc:`ValueError` for a port outside ``0``-``65535`` (:issue:`758`), and
242+
returns an unregistered member rather than minting one for a port the
243+
registry does not assign (:issue:`860`).
244+
225245
Note:
226246
The rows below are the registry entries whose **transport protocol column
227247
is empty**. A blank transport is not an assignment to anything, so there
@@ -2528,9 +2548,9 @@ def _dispatch(cls, key: 'int', proto: 'TransportProtocol | str | int') -> 'Type[
25282548
of the work for :issue:`808` -- so it is looked up as the one whole
25292549
value it already is, exactly like any other bare int: refused
25302550
when that whole value names no registry, resolved when it
2531-
happens to equal one instead. Since GitHub issue :issue:`860` moved
2532-
this class off power-of-two spacing, a hand-built composite
2533-
is no longer guaranteed to be the former -- see
2551+
happens to equal one instead. With the sequential values of
2552+
GitHub issue :issue:`860`, a hand-built composite
2553+
is not guaranteed to be the former -- see
25342554
:meth:`_dispatch`'s own body for a value that resolves.
25352555
25362556
Returns:
@@ -2755,10 +2775,10 @@ def register(cls, port: 'int', name: 'str') -> 'AppType': # pylint: disable=arg
27552775
The counterpart of :meth:`register_alias`: that method requires
27562776
``port`` to already carry a member and adds a further name for it;
27572777
this requires the opposite -- ``port`` unclaimed in this registry --
2758-
and mints the first. :meth:`get` can no longer do this itself as of
2778+
and mints the first. :meth:`get` does not do this itself, per
27592779
GitHub issue :issue:`860` (the owner's ruling there: only IANA-registered values
27602780
are legitimate, a new entry is properly created through :meth:`register`,
2761-
and ``get`` lacks the information to create one), so this is now the only
2781+
and ``get`` lacks the information to create one), so this is the only
27622782
way to add a service this registry does not already carry.
27632783
27642784
Deliberately scoped like :meth:`register_alias` to **this**
@@ -2900,9 +2920,9 @@ def _unregistered_member(cls, value: 'int', name: 'str',
29002920
its :data:`__registry__` side table alike.
29012921
29022922
Used by :meth:`_missing_` and :meth:`get` for a port neither resolves
2903-
to a real, IANA-registered service, so that such a lookup no longer
2904-
grows either table -- contrast :meth:`register`, the explicit,
2905-
caller-named path that still does.
2923+
to a real, IANA-registered service, so that such a lookup grows
2924+
neither table -- contrast :meth:`register`, the explicit,
2925+
caller-named path that does.
29062926
29072927
Reconstructs :attr:`svc`, :attr:`port` and :attr:`proto` the same way
29082928
:meth:`__new__` would:

‎pcapkit/corekit/enum.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
into, which is :meth:`EnumLookup._validate_value`. Legality is
3636
every enumeration's concern; mutation is only the open registries'.
3737
38-
Supporting measurement, taken on this tree at the time of the split: **0** of the
38+
Supporting measurement, taken when :issue:`877` split the tiers: **0** of the
3939
26 non-registry enumerations define ``register``, ``register_alias``,
4040
``register_aliases`` or ``_unregistered_member``, and there are **0**
4141
:class:`EnumRegistry` subclasses outside :mod:`pcapkit.const`. The mutating half

‎pcapkit/corekit/fields/field.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
.. versionremoved:: 1.5.0
1010
1111
``pcapkit.corekit.fields.field.NoValueType``, now
12-
:class:`pcapkit.corekit.sentinels.NoValueType` (:issue:`922`,
12+
:class:`pcapkit.corekit.sentinels.NoValueType` (:issue:`911`,
1313
:issue:`1744`), and ``pcapkit.corekit.fields.field.NoValue``, now
1414
:data:`pcapkit.corekit.sentinels.NO_VALUE` (:issue:`937`).
1515

0 commit comments

Comments
 (0)