Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/contributing/conventions/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ Format and Mechanics
adding coverage drops it from every source distribution.
* **Prose names the real defining module, not a re-export.** One strand of the
consistency sweep on :doc:`the roadmap </contributing/pep>`. The sentinels are the
worked example: all four are defined in :mod:`pcapkit.corekit.sentinels` and
re-exported by the modules that use them, and :ref:`sentinel-convention`'s table
names the defining module rather than any of the re-exports.
worked example: all four are defined in :mod:`pcapkit.corekit.sentinels`, and
:ref:`sentinel-convention`'s table names it rather than any of the modules that
use them, which no longer re-export them (:issue:`1744`).
* **A verbatim upstream port is exempt from these conventions.**
:ref:`sentinel-convention` already carries the case that settled it, the
``cached_property`` backport in :file:`pcapkit/utilities/compat.py`: the value of a
Expand Down
25 changes: 13 additions & 12 deletions docs/source/contributing/conventions/sentinel-convention.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ derives from it mechanically -- title-case each underscore-separated word and ap
- :mod:`pcapkit.corekit.sentinels`

GitHub issue :issue:`911`'s housing ruling -- one module for all four -- is why the table
names a single defining module. Each of the four modules that *uses* a sentinel keeps a
re-export of it, so ``from <module> import <name>`` keeps working for
:mod:`pcapkit.corekit.module`, :mod:`pcapkit.corekit.fields.field`,
:mod:`pcapkit.corekit.enum` and :mod:`pcapkit.protocols.protocol` alike, including a
caller's ``if TYPE_CHECKING:``-only import of the type.
names a single defining module, and it is the only import path. The modules that *use* a
sentinel import it from there but do not re-export it: :issue:`1744` dropped the
per-module re-exports, under the ruling on :issue:`1715` that a moved name keeps no
re-export at its old path. Import the object, and the type for an annotation, from
:mod:`pcapkit.corekit.sentinels`.

Where a sentinel name already exists and already follows SCREAMING_SNAKE, keep it;
renaming a published sentinel again costs every caller for no further gain.
Expand All @@ -56,12 +56,13 @@ private and not for public use, which is what this page and
adding a sentinel, add it to the table above whether or not it is public.

What reaches users is the **object only**. The owner ruled on GitHub issue :issue:`911`
that the objects alone -- ``NULL`` and its siblings -- are exported to users, so a public
sentinel names its instance in its module's ``__all__`` and leaves the type out of it.
The type stays importable by its dotted path, for an annotation or an ``is`` guard; it
is only ``import *`` that does not offer it. A private sentinel such as ``ABSENT`` is in
neither, which is what private means here -- dropping its leading underscore did not
add it to either list, and :class:`~pcapkit.corekit.sentinels.AbsentType` and
that the objects alone -- ``NULL`` and its siblings -- are exported to users, so a
public sentinel names its instance in :mod:`pcapkit.corekit.sentinels`'s ``__all__`` and
leaves the type out of it. The type stays importable by its dotted path there, for an
annotation or an ``is`` guard; it is only ``import *`` that does not offer it. A private
sentinel such as ``ABSENT`` is in neither, which is what private means here -- dropping
its leading underscore did not add it to either list, and
:class:`~pcapkit.corekit.sentinels.AbsentType` and
:data:`~pcapkit.corekit.sentinels.ABSENT` are documented on
:doc:`the sentinels API page </pcapkit/corekit/sentinels>` as private and not for
public use rather than left off it, since the name alone no longer says so.
Expand Down Expand Up @@ -121,7 +122,7 @@ inconsistencies**:
**reload** re-executes the class statement, so the guard does not survive one, and
code holding the pre-reload instance will fail ``is``. The module that matters there
is :mod:`pcapkit.corekit.sentinels`, where the class statement lives; reloading one
of the re-exporting modules has no effect on the sentinel.
of the modules that imports a sentinel from there has no effect on it.

``__bool__`` returning :obj:`False`
``NULL``, ``NO_VALUE`` and ``ABSENT`` have it, because each stands for an *absent
Expand Down
6 changes: 0 additions & 6 deletions docs/source/pcapkit/corekit/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,3 @@ adds the *mutating* half every registry under :mod:`pcapkit.const` inherits.

.. automethod:: _extend
.. automethod:: _unregistered_member

Auxiliaries
-----------

.. autoclass:: pcapkit.corekit.enum.NoDefaultType
.. autodata:: pcapkit.corekit.enum.NO_DEFAULT
13 changes: 6 additions & 7 deletions docs/source/pcapkit/corekit/fields/field.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Base Fields
:data:`pcapkit.utilities.config.ZERO_PAD_BUDGET_RATIO`, set with
:envvar:`PCAPKIT_ZERO_PAD_BUDGET_RATIO`.

.. versionremoved:: 1.5.0

``pcapkit.corekit.fields.field.NoValueType``, now
:class:`pcapkit.corekit.sentinels.NoValueType` (:issue:`922`,
:issue:`1744`).

.. autoclass:: pcapkit.corekit.fields.field.Field
:members:
:show-inheritance:
Expand All @@ -33,13 +39,6 @@ Base Fields
.. autoattribute:: _default
.. autoattribute:: _callback

Auxiliaries
-----------

.. autoclass:: pcapkit.corekit.fields.field.NoValueType
.. autodata:: pcapkit.corekit.fields.field.NO_VALUE
:no-value:

Internal Definitions
--------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/source/pcapkit/corekit/fields/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ Type Variables
:type: pcapkit.protocols.protocol.Protocol

.. data:: pcapkit.corekit.fields.misc._TN
:type: pcapkit.corekit.fields.field.NoValueType
:type: pcapkit.corekit.sentinels.NoValueType
12 changes: 3 additions & 9 deletions docs/source/pcapkit/corekit/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ with a class name.
Module name.

.. property:: name
:type: str | pcapkit.corekit.module.NullType
:type: str | pcapkit.corekit.sentinels.NullType

Class name, or :data:`NULL` when whatever built this descriptor never
got one -- see :attr:`klass`.

Auxiliaries
-----------

.. autoclass:: pcapkit.corekit.module.NullType
.. autodata:: pcapkit.corekit.module.NULL
Class name, or :data:`~pcapkit.corekit.sentinels.NULL` when whatever
built this descriptor never got one -- see :attr:`klass`.

Type Variables
--------------
Expand Down
6 changes: 2 additions & 4 deletions docs/source/pcapkit/corekit/sentinels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ singleton sentinel this package defines for itself: a value recognised only by
identity (``value is SENTINEL``), so it cannot be confused with a value a
caller might legitimately pass.

All four are defined here. The three public ones are also re-exported by
:mod:`pcapkit.corekit.module`, :mod:`pcapkit.corekit.fields.field` and
:mod:`pcapkit.corekit.enum` respectively, so ``from <module> import <name>``
works from either path.
All four are defined here, and this is their only import path: the modules
that use them do not re-export them (:issue:`1744`).

.. autoclass:: pcapkit.corekit.sentinels.NullType
.. autodata:: pcapkit.corekit.sentinels.NULL
Expand Down
2 changes: 0 additions & 2 deletions docs/source/pcapkit/foundation/reassembly/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,3 @@ Auxiliary Data
.. autoclass:: pcapkit.foundation.reassembly.data.data.Deferred
:members:
:show-inheritance:

``DeferredPacket`` is re-exported here from :mod:`pcapkit.corekit.packet`; see :doc:`/pcapkit/corekit/packet`.
12 changes: 12 additions & 0 deletions docs/source/pcapkit/foundation/registry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Foundation Registries

.. module:: pcapkit.foundation.registry.foundation

.. versionchanged:: 1.5.0

``NULL``, the default of every ``class_`` argument here, is now the
:data:`pcapkit.corekit.sentinels.NULL` sentinel; in 1.4.x it was the
string ``'(null)'`` (:issue:`833`).

Engine Registries
~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -53,6 +59,12 @@ Protocol Registries

.. module:: pcapkit.foundation.registry.protocols

.. versionchanged:: 1.5.0

``NULL``, the default of every ``class_`` argument here, is now the
:data:`pcapkit.corekit.sentinels.NULL` sentinel; in 1.4.x it was the
string ``'(null)'`` (:issue:`833`).

.. autofunction:: pcapkit.foundation.registry.protocols.register_protocol

.. autofunction:: pcapkit.foundation.registry.protocols.register_protocol_code
Expand Down
2 changes: 0 additions & 2 deletions docs/source/pcapkit/foundation/traceflow/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,3 @@ Auxiliary Data
.. autoclass:: pcapkit.foundation.traceflow.data.data.Deferred
:members:
:show-inheritance:

``DeferredPacket`` is re-exported here from :mod:`pcapkit.corekit.packet`; see :doc:`/pcapkit/corekit/packet`.
32 changes: 4 additions & 28 deletions docs/source/pcapkit/protocols/application/ngap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ which implements extractor for the NG Application Protocol
data models report with:
:class:`~pcapkit.protocols.application.ngap.PDUKind`,
:class:`~pcapkit.protocols.application.ngap.Criticality`,
:class:`~pcapkit.protocols.application.ngap.ProcedureCode` and
:class:`~pcapkit.protocols.application.ngap.ProtocolIE`.
:class:`~pcapkit.const.ngap.procedure_code.ProcedureCode` and
:class:`~pcapkit.const.ngap.protocol_ie.ProtocolIE`.

NGAP is the control plane between a 5G RAN node (gNB or ng-eNB) and an AMF.
It runs over SCTP and is named by the DATA chunk's *payload protocol
Expand Down Expand Up @@ -84,8 +84,8 @@ Known Limitations
package's.** The IE and procedure enumerations were generated from
``NGAP_Constants`` of |pycrate|_ 0.8.1 (Release-18-era: 81 procedure codes,
438 protocol IE IDs, highest 443). A |pycrate|_ that carries a newer NGAP will decode IEs that
:class:`~pcapkit.protocols.application.ngap.ProcedureCode` and
:class:`~pcapkit.protocols.application.ngap.ProtocolIE` do not name. Such a
:class:`~pcapkit.const.ngap.procedure_code.ProcedureCode` and
:class:`~pcapkit.const.ngap.protocol_ie.ProtocolIE` do not name. Such a
value resolves to a non-registering member called ``Unassigned`` rather than
failing or adding a member to either enumeration.
* **NGAP over a fragmented SCTP association is not reassembled.** A DATA chunk
Expand Down Expand Up @@ -124,30 +124,6 @@ Auxiliary Data
:members:
:show-inheritance:

.. autoclass:: pcapkit.protocols.application.ngap.ProcedureCode
:no-members:
:show-inheritance:

.. autoclass:: pcapkit.protocols.application.ngap.ProtocolIE
:no-members:
:show-inheritance:

.. note::

:class:`~pcapkit.protocols.application.ngap.ProcedureCode` and
:class:`~pcapkit.protocols.application.ngap.ProtocolIE` are rendered without
their members on purpose: between them they carry 519 of them, each named for
the 3GPP identifier it comes from, and a page listing all of them is longer
than the specification's own tables and no more useful. Read them from
``pcapkit/protocols/application/ngap.py``, or from
``pycrate_asn1dir.NGAP.NGAP_Constants``, which is where they were generated
from.

Unlike the enumerations under :mod:`pcapkit.const`, these are not crawled
from an IANA registry -- 3GPP publishes them in the ASN.1 of TS 38.413 rather
than in a registry with a stable page -- so there is no matching module under
:mod:`pcapkit.vendor`.

Header Schemas
--------------

Expand Down
8 changes: 7 additions & 1 deletion docs/source/pcapkit/protocols/misc/pcapng.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ Auxiliary Data
:class:`TLSKeyLabel <pcapkit.const.pcapng.tls_key_label.TLSKeyLabel>` is defined
in :mod:`pcapkit.const.pcapng.tls_key_label`, generated like its
:mod:`pcapkit.const.pcapng` siblings because :rfc:`9850#section-4.2` makes it an
IANA registry. This module re-exports it as ``TLSKeyLabel``.
IANA registry.

.. versionremoved:: 1.5.0

``pcapkit.protocols.misc.pcapng.TLSKeyLabel``, now
:class:`pcapkit.const.pcapng.tls_key_label.TLSKeyLabel` (:issue:`890`,
:issue:`1744`).

.. autoclass:: pcapkit.protocols.misc.pcapng.WireGuardKeyLabel
:members:
Expand Down
5 changes: 3 additions & 2 deletions examples/generators/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,11 +1577,12 @@ def _pcapng_secrets_registry() -> 'Any':

def _pcapng_secrets_overrides() -> 'dict[Any, dict[str, Any]]':
from pcapkit.const.pcapng.secrets_type import SecretsType as Enum_SecretsType
from pcapkit.const.pcapng.tls_key_label import TLSKeyLabel as Enum_TLSKeyLabel
from pcapkit.corekit.multidict import OrderedMultiDict
from pcapkit.protocols.misc.pcapng import TLSKeyLabel, WireGuardKeyLabel
from pcapkit.protocols.misc.pcapng import WireGuardKeyLabel
return {
Enum_SecretsType.TLS_Key_Log: {
'entries': {TLSKeyLabel.CLIENT_RANDOM: OrderedMultiDict(
'entries': {Enum_TLSKeyLabel.CLIENT_RANDOM: OrderedMultiDict(
[(bytes(range(0x20, 0x40)), bytes(range(0x40, 0x70)))])}},
Enum_SecretsType.WireGuard_Key_Log: {
'entries': OrderedMultiDict(
Expand Down
3 changes: 2 additions & 1 deletion pcapkit/const/ftp/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

from aenum import IntEnum, IntFlag, StrEnum, auto

from pcapkit.corekit.enum import NO_DEFAULT, EnumLookup, EnumRegistry
from pcapkit.corekit.enum import EnumLookup, EnumRegistry
from pcapkit.corekit.sentinels import NO_DEFAULT

if TYPE_CHECKING:
from typing import Any, Optional, Type
Expand Down
3 changes: 2 additions & 1 deletion pcapkit/const/reg/apptype/apptype.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

from aenum import IntEnum, StrEnum, auto, extend_enum

from pcapkit.corekit.enum import NO_DEFAULT, EnumLookup, EnumRegistry
from pcapkit.corekit.enum import EnumLookup, EnumRegistry
from pcapkit.corekit.sentinels import NO_DEFAULT

__all__ = ['TransportProtocol', 'AppType']

Expand Down
11 changes: 6 additions & 5 deletions pcapkit/corekit/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@

from aenum import extend_enum

from pcapkit.corekit.sentinels import NO_DEFAULT, NoDefaultType # pylint: disable=unused-import
from pcapkit.corekit.sentinels import NO_DEFAULT
from pcapkit.utilities.exceptions import BaseError, EnumKeyError, EnumValueError

if TYPE_CHECKING:
from typing import Any

from typing_extensions import Self

__all__ = ['NO_DEFAULT', 'EnumLookup', 'EnumRegistry']
__all__ = ['EnumLookup', 'EnumRegistry']


class EnumLookup:
Expand Down Expand Up @@ -362,9 +362,10 @@ def get(cls, key: 'Any', default: 'Any' = NO_DEFAULT) -> 'Self':
``key`` does not resolve. Resolved through a plain
``_value2member_map_`` lookup, never through
``cls(default)``, so it cannot mint -- see :issue:`864`.
:data:`NO_DEFAULT` stands for *no default*; that and a
``default`` naming no registered member both fall through to
the same lookup error ``key`` itself would have raised.
:data:`~pcapkit.corekit.sentinels.NO_DEFAULT` stands for *no
default*; that and a ``default`` naming no registered member
both fall through to the same lookup error ``key`` itself would
have raised.

Returns:
The canonical member for ``key``, or for ``default``.
Expand Down
11 changes: 9 additions & 2 deletions pcapkit/corekit/fields/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
:data:`pcapkit.utilities.config.ZERO_PAD_BUDGET_RATIO`, set with
:envvar:`PCAPKIT_ZERO_PAD_BUDGET_RATIO`.

.. versionremoved:: 1.5.0

``pcapkit.corekit.fields.field.NoValueType``, now
:class:`pcapkit.corekit.sentinels.NoValueType` (:issue:`922`,
:issue:`1744`).

"""

import abc
Expand All @@ -29,17 +35,18 @@
import struct
from typing import TYPE_CHECKING, Generic, TypeVar, cast

from pcapkit.corekit.sentinels import NO_VALUE, NoValueType # pylint: disable=unused-import
from pcapkit.corekit.sentinels import NO_VALUE
from pcapkit.utilities import config
from pcapkit.utilities.exceptions import FieldValueError, NoDefaultValue, ProtocolError

__all__ = ['NO_VALUE', 'Field']
__all__ = ['Field']

if TYPE_CHECKING:
from typing import IO, Any, Callable, Iterator, Optional

from typing_extensions import Self

from pcapkit.corekit.sentinels import NoValueType
from pcapkit.protocols.schema.schema import Schema

_T = TypeVar('_T')
Expand Down
5 changes: 3 additions & 2 deletions pcapkit/corekit/fields/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import re
from typing import TYPE_CHECKING, Generic, TypeVar, cast

from pcapkit.corekit.fields.field import NO_VALUE, Field
from pcapkit.corekit.fields.field import Field
from pcapkit.corekit.sentinels import NO_VALUE
from pcapkit.utilities.exceptions import FieldValueError

__all__ = [
Expand All @@ -22,7 +23,7 @@

from typing_extensions import Literal, Self

from pcapkit.corekit.fields.field import NoValueType
from pcapkit.corekit.sentinels import NoValueType


_T = TypeVar('_T', 'IPv4Address', 'IPv6Address',
Expand Down
5 changes: 3 additions & 2 deletions pcapkit/corekit/fields/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import io
from typing import TYPE_CHECKING, TypeVar, cast

from pcapkit.corekit.fields.field import NO_VALUE, FieldBase
from pcapkit.corekit.fields.field import FieldBase
from pcapkit.corekit.sentinels import NO_VALUE
from pcapkit.utilities.compat import Mapping
from pcapkit.utilities.exceptions import FieldError, NoDefaultValue
from pcapkit.utilities.warnings import RegistryWarning, warn
Expand All @@ -20,7 +21,7 @@

from typing_extensions import Self

from pcapkit.corekit.fields.field import NoValueType
from pcapkit.corekit.sentinels import NoValueType
from pcapkit.protocols.protocol import ProtocolBase
from pcapkit.protocols.schema.schema import Schema

Expand Down
5 changes: 3 additions & 2 deletions pcapkit/corekit/fields/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import aenum

from pcapkit.corekit.fields.field import NO_VALUE, Field
from pcapkit.corekit.fields.field import Field
from pcapkit.corekit.sentinels import NO_VALUE
from pcapkit.utilities.exceptions import BaseError, FieldValueError, IntError, ProtocolError

__all__ = [
Expand All @@ -28,7 +29,7 @@
from typing_extensions import Literal, Self

from pcapkit.const.reg.apptype import AppType, TransportProtocol
from pcapkit.corekit.fields.field import NoValueType
from pcapkit.corekit.sentinels import NoValueType

_T = TypeVar('_T', bound='int')

Expand Down
Loading
Loading