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
27 changes: 4 additions & 23 deletions pcapkit/const/ipv6/extension_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

"""

from aenum import IntEnum, extend_enum
from aenum import IntEnum

from pcapkit.corekit.enums import EnumRegistry

__all__ = ['ExtensionHeader']


class ExtensionHeader(IntEnum):
class ExtensionHeader(EnumRegistry, IntEnum):
"""[ExtensionHeader] IPv6 Extension Header Types"""

#: HOPOPT, IPv6 Hop-by-Hop Option [:rfc:`8200`]
Expand Down Expand Up @@ -53,24 +55,3 @@ class ExtensionHeader(IntEnum):

#: Use for experimentation and testing [:rfc:`3692`]
Use_for_experimentation_and_testing_254 = 254

@staticmethod
def get(key: 'int | str', default: 'int' = -1) -> 'ExtensionHeader':
"""Backport support for original codes.

Args:
key: Key to get enum item.
default: Default value if not found. The placeholder ``-1`` stands
for *no default*, in which case an unresolvable key propagates
the lookup error instead of falling back.

:meta private:
"""
if isinstance(key, int):
try:
return ExtensionHeader(key)
except ValueError:
if default == -1:
raise
return ExtensionHeader(default)
return ExtensionHeader[key] # type: ignore[misc]
25 changes: 3 additions & 22 deletions pcapkit/const/mh/binding_ack_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

from aenum import IntFlag

from pcapkit.corekit.enums import EnumRegistry

__all__ = ['BindingACKFlag']


class BindingACKFlag(IntFlag):
class BindingACKFlag(EnumRegistry, IntFlag):
"""[BindingACKFlag] Binding Acknowledgment Flags"""

#: K [:rfc:`6275`]
Expand All @@ -39,27 +41,6 @@ class BindingACKFlag(IntFlag):
#: D [:rfc:`8885`]
D = 0x02

@staticmethod
def get(key: 'int | str', default: 'int' = -1) -> 'BindingACKFlag':
"""Backport support for original codes.

Args:
key: Key to get enum item.
default: Default value if not found. The placeholder ``-1`` stands
for *no default*, in which case an unresolvable key propagates
the lookup error instead of falling back.

:meta private:
"""
if isinstance(key, int):
try:
return BindingACKFlag(key)
except ValueError:
if default == -1:
raise
return BindingACKFlag(default)
return BindingACKFlag[key] # type: ignore[misc]

@classmethod
def _missing_(cls, value: 'int') -> 'BindingACKFlag':
"""Lookup function used when value is not found.
Expand Down
25 changes: 3 additions & 22 deletions pcapkit/const/mh/binding_update_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

from aenum import IntFlag

from pcapkit.corekit.enums import EnumRegistry

__all__ = ['BindingUpdateFlag']


class BindingUpdateFlag(IntFlag):
class BindingUpdateFlag(EnumRegistry, IntFlag):
"""[BindingUpdateFlag] Binding Update Flags"""

#: A [:rfc:`6275`]
Expand Down Expand Up @@ -54,27 +56,6 @@ class BindingUpdateFlag(IntFlag):
#: D [:rfc:`8885`]
D = 0x0010

@staticmethod
def get(key: 'int | str', default: 'int' = -1) -> 'BindingUpdateFlag':
"""Backport support for original codes.

Args:
key: Key to get enum item.
default: Default value if not found. The placeholder ``-1`` stands
for *no default*, in which case an unresolvable key propagates
the lookup error instead of falling back.

:meta private:
"""
if isinstance(key, int):
try:
return BindingUpdateFlag(key)
except ValueError:
if default == -1:
raise
return BindingUpdateFlag(default)
return BindingUpdateFlag[key] # type: ignore[misc]

@classmethod
def _missing_(cls, value: 'int') -> 'BindingUpdateFlag':
"""Lookup function used when value is not found.
Expand Down
25 changes: 3 additions & 22 deletions pcapkit/const/mh/handover_ack_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

from aenum import IntFlag

from pcapkit.corekit.enums import EnumRegistry

__all__ = ['HandoverACKFlag']


class HandoverACKFlag(IntFlag):
class HandoverACKFlag(EnumRegistry, IntFlag):
"""[HandoverACKFlag] Handover Acknowledge Flags"""

#: Buffer flag [:rfc:`5949`]
Expand All @@ -27,27 +29,6 @@ class HandoverACKFlag(IntFlag):
#: Forwarding flag [:rfc:`5949`]
F = 0x20

@staticmethod
def get(key: 'int | str', default: 'int' = -1) -> 'HandoverACKFlag':
"""Backport support for original codes.

Args:
key: Key to get enum item.
default: Default value if not found. The placeholder ``-1`` stands
for *no default*, in which case an unresolvable key propagates
the lookup error instead of falling back.

:meta private:
"""
if isinstance(key, int):
try:
return HandoverACKFlag(key)
except ValueError:
if default == -1:
raise
return HandoverACKFlag(default)
return HandoverACKFlag[key] # type: ignore[misc]

@classmethod
def _missing_(cls, value: 'int') -> 'HandoverACKFlag':
"""Lookup function used when value is not found.
Expand Down
25 changes: 3 additions & 22 deletions pcapkit/const/mh/handover_initiate_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

from aenum import IntFlag

from pcapkit.corekit.enums import EnumRegistry

__all__ = ['HandoverInitiateFlag']


class HandoverInitiateFlag(IntFlag):
class HandoverInitiateFlag(EnumRegistry, IntFlag):
"""[HandoverInitiateFlag] Handover Initiate Flags"""

#: Assigned Address Configuration flag [:rfc:`5568`]
Expand All @@ -30,27 +32,6 @@ class HandoverInitiateFlag(IntFlag):
#: Forwarding flag [:rfc:`5949`]
F = 0x10

@staticmethod
def get(key: 'int | str', default: 'int' = -1) -> 'HandoverInitiateFlag':
"""Backport support for original codes.

Args:
key: Key to get enum item.
default: Default value if not found. The placeholder ``-1`` stands
for *no default*, in which case an unresolvable key propagates
the lookup error instead of falling back.

:meta private:
"""
if isinstance(key, int):
try:
return HandoverInitiateFlag(key)
except ValueError:
if default == -1:
raise
return HandoverInitiateFlag(default)
return HandoverInitiateFlag[key] # type: ignore[misc]

@classmethod
def _missing_(cls, value: 'int') -> 'HandoverInitiateFlag':
"""Lookup function used when value is not found.
Expand Down
28 changes: 2 additions & 26 deletions pcapkit/const/tcp/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@

"""

from typing import TYPE_CHECKING

from aenum import IntFlag

if TYPE_CHECKING:
from typing import Optional
from pcapkit.corekit.enums import EnumRegistry

__all__ = ['Flags']

class Flags(IntFlag):
class Flags(EnumRegistry, IntFlag):
"""[Flags] TCP Header Flags"""

#: Reserved for future use [:rfc:`9293`]
Expand Down Expand Up @@ -58,27 +55,6 @@ class Flags(IntFlag):
#: No more data from sender (FIN) [:rfc:`9293`]
FIN = 1 << 15

@staticmethod
def get(key: 'int | str', default: 'Optional[int]' = -1) -> 'Flags':
"""Backport support for original codes.

Args:
key: Key to get enum item.
default: Default value if not found. The placeholder ``-1`` stands
for *no default*, in which case an unresolvable key propagates
the lookup error instead of falling back.

:meta private:
"""
if isinstance(key, int):
try:
return Flags(key)
except ValueError:
if default == -1:
raise
return Flags(default)
return Flags[key] # type: ignore[misc]

@classmethod
def _missing_(cls, value: 'int') -> 'Flags':
"""Lookup function used when value is not found.
Expand Down
3 changes: 3 additions & 0 deletions pcapkit/corekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class :class:`~pcapkit.corekit.infoclass.Info`,

"""
from pcapkit.corekit.io import SeekableReader
from pcapkit.corekit.enums import EnumRegistry
from pcapkit.corekit.fields import *
from pcapkit.corekit.infoclass import Info, info_final
from pcapkit.corekit.module import ModuleDescriptor
Expand All @@ -25,6 +26,8 @@ class :class:`~pcapkit.corekit.infoclass.Info`,
from pcapkit.corekit.version import VersionInfo

__all__ = [
'EnumRegistry',

'Info', 'info_final',

'ProtoChain',
Expand Down
Loading
Loading