@@ -99,9 +99,10 @@ def get(cls, key: 'int | str', default: 'Any' = NO_DEFAULT) -> 'TransportProtoco
9999 name miss reaches the caller as
100100 :exc:`~pcapkit.utilities.exceptions.EnumKeyError` from the base.
101101 :class:`AppType` and its per-transport registries raise
102- :exc:`ValueError` from their own ``get()`` because it takes an
103- :class:`int` port and never accepts a name; that is not a name-miss
104- policy, so it sets none for this class to follow. The
102+ :exc:`~pcapkit.utilities.exceptions.EnumValueError` from their own
103+ ``get()`` because it takes an :class:`int` port and never accepts a
104+ name; that is not a name-miss policy, so it sets none for this class
105+ to follow. The
105106 maintainer's ruling given in review of the work for :issue:`808`, that
106107 :class:`TransportProtocol` is not to be extended at all, holds either
107108 way: the refusal is a refusal and mints nothing, whichever exception
@@ -2596,12 +2597,27 @@ def _dispatch(cls, key: 'int', proto: 'TransportProtocol | str | int') -> 'Type[
25962597 f'{ cls .__name__ } ' )
25972598
25982599 @classmethod
2599- def get (cls , key : 'int' , * , # type: ignore[override] # pylint: disable=arguments-differ
2600+ def get (cls , key : 'int' , default : 'Any' = NO_DEFAULT , * ,
26002601 proto : 'TransportProtocol | str | int' = TransportProtocol .undefined ) -> 'AppType' :
26012602 """Resolve port ``key`` to the member for its canonical service.
26022603
2604+ Takes the ``default`` :meth:`~pcapkit.corekit.enum.EnumLookup.get`
2605+ advertises, since an override honours the base's signature rather than
2606+ suppressing the mismatch (:issue:`935`), and answers a miss as the base
2607+ does, from :mod:`pcapkit.utilities.exceptions` (:issue:`923`).
2608+
26032609 Args:
26042610 key: Port number to look up.
2611+ default: An already-registered value to fall back to when ``key``
2612+ resolves to nothing: a member's ``value``, such as
2613+ ``'http [80 - tcp]'``, and not a port or a member, which hashes
2614+ as its port. Resolved as
2615+ :meth:`~pcapkit.corekit.enum.EnumLookup.get` resolves its own,
2616+ through ``_value2member_map_`` and so never minting, in the
2617+ registry ``key`` was dispatched to, or else in the class called
2618+ on, which on :class:`AppType` itself holds no members.
2619+ :data:`~pcapkit.corekit.sentinels.NO_DEFAULT`, the default, means
2620+ *no default*.
26052621 proto: Transport protocol carrying ``key``. Selects the registry to
26062622 search when called on :class:`AppType` itself, which holds no
26072623 members; ignored when called on one of those registries, each of
@@ -2628,53 +2644,60 @@ def get(cls, key: 'int', *, # type: ignore[override] # pylint: disable=argument
26282644 registry's own transport (:issue:`2048`).
26292645
26302646 Raises:
2631- ValueError: If called on a class that holds no members, i.e. on
2632- :class:`AppType` itself, with a ``proto`` naming no registry to
2633- delegate to. Also for a ``key`` that is not a port number, since
2634- this registry resolves ports and not service names -- including
2635- one outside ``0..65535``, whose rejection by :meth:`_missing_` this
2636- method propagates rather than minting over, so that ``get`` is
2637- never more permissive than ``AppType(...)``. Also covers a
2638- ``proto`` int that matches no registry at all, composite or
2639- not -- looked up as the whole value it is rather than
2640- decoded into the registries its bits would each name, so it
2641- is refused only when that whole value itself names none of
2642- them, not simply for being composite -- see
2643- :meth:`_dispatch`.
2647+ EnumValueError: If ``key`` resolves to nothing and there is no
2648+ usable ``default``: a ``key`` that is not a port number, since
2649+ this registry resolves ports and not service names, including
2650+ one outside ``0..65535``, which :meth:`_missing_` rejects rather
2651+ than minting over, so that ``get`` is never more permissive than
2652+ ``AppType(...)``; or, on :class:`AppType` itself, a ``proto``
2653+ naming no registry to delegate to, composite or not (see
2654+ :meth:`_dispatch`). A :exc:`ValueError`, and quiet, as from the
2655+ base.
2656+ EnumKeyError: If, on :class:`AppType` itself, ``proto`` is a name no
2657+ :class:`TransportProtocol` member carries, from
2658+ :meth:`TransportProtocol.get`.
26442659
26452660 """
2646- owner = cls ._dispatch (key , proto )
2661+ owner = cls
2662+ try :
2663+ owner = cls ._dispatch (key , proto )
26472664
2648- matched = owner .__registry__ .getlist (key ) # type: ignore[union-attr]
2649- if matched :
2650- canonical = owner .__canonical__ .get (key )
2651- if canonical is not None :
2652- for member in matched :
2653- if member .svc == canonical :
2654- return member
2655- # NOTE: IANA's oldest row, for a port whose collision postdates
2656- # :data:`__canonical__` -- including one ``aenum.extend_enum``
2657- # created, which must not displace what the registry already
2658- # answered with.
2659- return matched [0 ]
2665+ matched = owner .__registry__ .getlist (key ) # type: ignore[union-attr]
2666+ if matched :
2667+ canonical = owner .__canonical__ .get (key )
2668+ if canonical is not None :
2669+ for member in matched :
2670+ if member .svc == canonical :
2671+ return member
2672+ # NOTE: IANA's oldest row, for a port whose collision postdates
2673+ # :data:`__canonical__` -- including one ``aenum.extend_enum``
2674+ # created, which must not displace what the registry already
2675+ # answered with.
2676+ return matched [0 ]
26602677
2661- # NOTE: :meth:`_missing_` answers :obj:`None` for a port it holds no row
2662- # for, and that answer does not mint (GitHub issue #860), following the
2663- # owner's ruling there that ``get`` should not mint because it lacks the
2664- # information to create a new member: only IANA-registered values are
2665- # legitimate, and ``register`` is the proper way to add one. That ruling
2666- # was given for the FEATCode, Command and Method branches, and covers
2667- # this family under the same issue. A port outside ``0..65535`` *raises*
2668- # rather than reaching here at all. Minting on the ``None`` answer would
2669- # name a member ``PORT_{key}_{transport}`` -- GitHub issue #758's
2670- # defect, which also minted ``PORT_999999_tcp`` and ``PORT_-1_tcp``, the
2671- # latter a name no attribute access could reach -- so, as inside
2672- # :meth:`_missing_` itself, the port gets an unregistered member
2673- # instead: neither is a value anyone asked to be named. A port IANA
2674- # lists on other transports only is in no span on this one: 8011,
2675- # reserved on TCP and ``bier-echo`` on UDP, answers ``unknown`` on DCCP
2676- # and SCTP (#2048).
2677- ret = owner ._missing_ (key )
2678+ # NOTE: :meth:`_missing_` answers :obj:`None` for a port it holds no row
2679+ # for, and that answer does not mint (GitHub issue #860), following the
2680+ # owner's ruling there that ``get`` should not mint because it lacks the
2681+ # information to create a new member: only IANA-registered values are
2682+ # legitimate, and ``register`` is the proper way to add one. That ruling
2683+ # was given for the FEATCode, Command and Method branches, and covers
2684+ # this family under the same issue. A port outside ``0..65535`` *raises*
2685+ # rather than reaching here at all. Minting on the ``None`` answer would
2686+ # name a member ``PORT_{key}_{transport}`` -- GitHub issue #758's
2687+ # defect, which also minted ``PORT_999999_tcp`` and ``PORT_-1_tcp``, the
2688+ # latter a name no attribute access could reach -- so, as inside
2689+ # :meth:`_missing_` itself, the port gets an unregistered member
2690+ # instead: neither is a value anyone asked to be named. A port IANA
2691+ # lists on other transports only is in no span on this one: 8011,
2692+ # reserved on TCP and ``bier-echo`` on UDP, answers ``unknown`` on DCCP
2693+ # and SCTP (#2048).
2694+ ret = owner ._missing_ (key )
2695+ except ValueError as error :
2696+ # NOTE: answered as EnumLookup.get answers a value miss (#923, #2545),
2697+ # with ``default`` from the registry dispatched to, else from ``cls``.
2698+ if default is NO_DEFAULT or default not in owner ._value2member_map_ :
2699+ raise EnumValueError (str (error ), quiet = True ) from error
2700+ return owner ._value2member_map_ [default ]
26782701 if ret is None :
26792702 ret = owner ._unregistered_member (key , 'unknown' , owner .__transport__ )
26802703 return ret
0 commit comments