From abe864d789944cef39e6e44899b6f647c9f13019 Mon Sep 17 00:00:00 2001 From: Jarry Shaw Date: Sun, 1 Nov 2026 01:33:32 -0500 Subject: [PATCH] refactor(protocols): reorder link class members to the member-order convention (#2490) - arp: keep each address helper's reader and maker together, reader first: _read_addr_resolve, _make_addr_resolve, _read_proto_resolve, _make_proto_resolve. - l2tpv2: drop the second "Methods" banner, so id() sits in the one Methods section. Pure move: member set, member ASTs and non-banner comments are unchanged. --- pcapkit/protocols/link/arp.py | 40 ++++++++++++++++---------------- pcapkit/protocols/link/l2tpv2.py | 4 ---- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/pcapkit/protocols/link/arp.py b/pcapkit/protocols/link/arp.py index 4d67155c6d..abf2ee7d1e 100644 --- a/pcapkit/protocols/link/arp.py +++ b/pcapkit/protocols/link/arp.py @@ -374,26 +374,6 @@ def _read_addr_resolve(self, addr: 'bytes', htype: 'int') -> 'str': _addr = addr.hex() return _addr - def _read_proto_resolve(self, addr: 'bytes', ptype: 'int') -> 'str | IPv4Address | IPv6Address': - """Resolve protocol address according to protocol. - - Arguments: - addr: Protocol address. - ptype: Protocol type. - - Returns: - Protocol address. If ``ptype`` is ``0x0800`` (IPv4) and ``addr`` is - 4 octets, an :class:`~ipaddress.IPv4Address`; if ``0x86dd`` (IPv6) - and 16 octets, an :class:`~ipaddress.IPv6Address`; otherwise, the - address as a hex :class:`str`. - - """ - if ptype == Enum_EtherType.Internet_Protocol_version_4 and len(addr) == 4: # IPv4 - return ipaddress.IPv4Address(addr) - if ptype == Enum_EtherType.Internet_Protocol_version_6 and len(addr) == 16: # IPv6 - return ipaddress.IPv6Address(addr) - return addr.hex() - def _make_addr_resolve(self, addr: 'str | bytes | bytearray', htype: 'int') -> 'bytes': """Resolve hardware address according to protocol. @@ -441,6 +421,26 @@ def _make_addr_resolve(self, addr: 'str | bytes | bytearray', htype: 'int') -> ' f'{addr!r}') from None return bytes(addr) + def _read_proto_resolve(self, addr: 'bytes', ptype: 'int') -> 'str | IPv4Address | IPv6Address': + """Resolve protocol address according to protocol. + + Arguments: + addr: Protocol address. + ptype: Protocol type. + + Returns: + Protocol address. If ``ptype`` is ``0x0800`` (IPv4) and ``addr`` is + 4 octets, an :class:`~ipaddress.IPv4Address`; if ``0x86dd`` (IPv6) + and 16 octets, an :class:`~ipaddress.IPv6Address`; otherwise, the + address as a hex :class:`str`. + + """ + if ptype == Enum_EtherType.Internet_Protocol_version_4 and len(addr) == 4: # IPv4 + return ipaddress.IPv4Address(addr) + if ptype == Enum_EtherType.Internet_Protocol_version_6 and len(addr) == 16: # IPv6 + return ipaddress.IPv6Address(addr) + return addr.hex() + def _make_proto_resolve(self, addr: 'IPv4Address | IPv6Address | str | bytes', ptype: 'int', plen: 'Optional[int]' = None) -> 'bytes': """Resolve protocol address according to protocol. diff --git a/pcapkit/protocols/link/l2tpv2.py b/pcapkit/protocols/link/l2tpv2.py index bcdf6095f7..92dbd950d7 100644 --- a/pcapkit/protocols/link/l2tpv2.py +++ b/pcapkit/protocols/link/l2tpv2.py @@ -361,10 +361,6 @@ def make(self, trailer=trailer, ) - ########################################################################## - # Methods. - ########################################################################## - @classmethod def id(cls) -> 'tuple[Literal["L2TP"], Literal["L2TPv2"]]': """Index ID of the protocol.