Skip to content

Commit d951177

Browse files
authored
fix(vendor): 16 crawlers' process() reads its own data argument (#2429) (#2430)
16 of the 24 dict-based crawlers' `process(self, data)` ignored the `data` argument and read the module-level `DATA` literal instead: `ipv4/qs_function`, `tos_del`, `tos_ecn`, `tos_pre`, `tos_rel`, `tos_thr`, `ts_flag`; `ipv6/option_action`, `qs_function`, `smf_dpd_mode`; `mh/binding_error`, `lla_code`; and `pcapng/filter_type`, `hash_algorithm`, `secrets_type`, `verdict_type`. 8 siblings, such as `ipv4/classification_level`, already use `data` correctly. Harmless today, since every real call site passes `request()`'s own `DATA`-returning value, so `data is DATA` always held in practice -- but a caller passing different data, such as a test fixture or a future `LINK`-based fetch (the open TODO in `pcapng/filter_type.py` already points that direction), got the module's table back regardless, with no error. `pcapkit-vendor` regenerates `pcapkit/const/`, not `pcapkit/vendor/` itself: these dict-based crawlers are hand-written, so no template needed the same fix and no `const/` regeneration follows from it. New test drives each crawler's `count()` and `process()` on a fabricated registry sharing none of the module's names, proving the rendered output now reflects the argument rather than the module global; confirmed to fail against the unfixed crawlers first. Closes #2429.
1 parent cfbe5dc commit d951177

19 files changed

Lines changed: 183 additions & 16 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ This resolves [#548](https://github.com/JarryShaw/PyPCAPKit/issues/548), which r
457457
- the generated const comments render as written: a URL reference followed by another bracket no longer autolinks into it, a leading enumerator such as `(S)` is escaped, and a hyphenated word is no longer split across lines ([#1846](https://github.com/JarryShaw/PyPCAPKit/issues/1846), [#1847](https://github.com/JarryShaw/PyPCAPKit/issues/1847), [#1871](https://github.com/JarryShaw/PyPCAPKit/pull/1871)).
458458
- without the `vendor` extra, `pcapkit-vendor` and `python -m pcapkit.vendor` exit 1 with one line naming the missing packages and `pypcapkit[vendor]`, where they died with a traceback, and `--help` and `--version` still work. Importing a crawler then raises `ModuleNotFoundError` ([#1850](https://github.com/JarryShaw/PyPCAPKit/issues/1850), [#1875](https://github.com/JarryShaw/PyPCAPKit/pull/1875)).
459459
- the ESP cipher and integrity crawlers strip the brackets off IANA's `[UNSPECIFIED]` "no document" cell before testing it against the unknown placeholder, so `pcapkit.const.esp.integrity` no longer reads `#: AUTH_DES_MAC [UNSPECIFIED] (DEPRECATED ...)` for `AUTH_DES_MAC` and `AUTH_KPDK_MD5` ([#2294](https://github.com/JarryShaw/PyPCAPKit/issues/2294), [#2371](https://github.com/JarryShaw/PyPCAPKit/pull/2371)).
460+
- some dict-based crawlers' `process(self, data)` ignored the `data` argument and read the module-level `DATA` literal instead, in `ipv4/{qs_function,tos_del,tos_ecn,tos_pre,tos_rel,tos_thr,ts_flag}.py`, `ipv6/{option_action,qs_function,smf_dpd_mode}.py`, `mh/{binding_error,lla_code}.py` and `pcapng/{filter_type,hash_algorithm,secrets_type,verdict_type}.py`. Harmless today, since every real call site passes `request()`'s own `DATA`-returning value, so `data is DATA` always held in practice -- but a caller passing different data, such as a test fixture or a future `LINK`-based fetch, got the module's table back regardless, with no error. The dict-based crawlers are hand-written rather than generated, so the fix needs no `const/` regeneration ([#2429](https://github.com/JarryShaw/PyPCAPKit/issues/2429), [#2430](https://github.com/JarryShaw/PyPCAPKit/pull/2430)).
460461

461462
### Project infrastructure
462463

‎docs/source/changelog/1.5.0.rst‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,6 +3350,18 @@ Fixed
33503350
placeholder, so :mod:`pcapkit.const.esp.integrity` no longer reads
33513351
``#: AUTH_DES_MAC [UNSPECIFIED] (DEPRECATED ...)`` for ``AUTH_DES_MAC`` and
33523352
``AUTH_KPDK_MD5`` (:issue:`2294`, :pr:`2371`).
3353+
* some dict-based crawlers' ``process(self, data)`` ignored the ``data``
3354+
argument and read the module-level ``DATA`` literal instead, in
3355+
``ipv4/{qs_function,tos_del,tos_ecn,tos_pre,tos_rel,tos_thr,ts_flag}.py``,
3356+
``ipv6/{option_action,qs_function,smf_dpd_mode}.py``,
3357+
``mh/{binding_error,lla_code}.py`` and
3358+
``pcapng/{filter_type,hash_algorithm,secrets_type,verdict_type}.py``. Harmless
3359+
today, since every real call site passes ``request()``'s own
3360+
``DATA``-returning value, so ``data is DATA`` always held in practice -- but a
3361+
caller passing different data, such as a test fixture or a future ``LINK``-based
3362+
fetch, got the module's table back regardless, with no error. The dict-based
3363+
crawlers are hand-written rather than generated, so the fix needs no ``const/``
3364+
regeneration (:issue:`2429`, :pr:`2430`).
33533365

33543366
Project infrastructure
33553367
----------------------

‎pcapkit/vendor/ipv4/qs_function.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def process(self, data: 'dict[int, str]') -> 'tuple[list[str], list[str]]': # t
6868
miss = [
6969
"return cls._unregistered_member(value, 'Unassigned')",
7070
]
71-
for code, name in DATA.items():
71+
for code, name in data.items():
7272
renm = self.rename(name, code) # type: ignore[arg-type]
7373
enum.append(f"{renm} = {code}".ljust(76))
7474
return enum, miss

‎pcapkit/vendor/ipv4/tos_del.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def process(self, data: 'dict[int, str]') -> 'tuple[list[str], list[str]]': # t
6868
miss = [
6969
"return cls._unregistered_member(value, 'Unassigned')",
7070
]
71-
for code, name in DATA.items():
71+
for code, name in data.items():
7272
renm = self.rename(name, code).upper() # type: ignore[arg-type]
7373
enum.append(f"{renm} = {code}".ljust(76))
7474
return enum, miss

‎pcapkit/vendor/ipv4/tos_ecn.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def process(self, data: 'dict[int, str]') -> 'tuple[list[str], list[str]]': # t
8585
miss = [
8686
"return cls._unregistered_member(value, 'Unassigned')",
8787
]
88-
for code, name in DATA.items():
88+
for code, name in data.items():
8989
renm = self.rename(name, code)
9090
enum.append(f"{renm} = 0b{bin(code)[2:].zfill(2)}".ljust(76))
9191
return enum, miss

‎pcapkit/vendor/ipv4/tos_pre.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def process(self, data: 'dict[int, str]') -> 'tuple[list[str], list[str]]': # t
7474
miss = [
7575
"return cls._unregistered_member(value, 'Unassigned')",
7676
]
77-
for code, name in DATA.items():
77+
for code, name in data.items():
7878
renm = self.rename(name, code) # type: ignore[arg-type]
7979
enum.append(f"{renm} = {code}".ljust(76))
8080
return enum, miss

‎pcapkit/vendor/ipv4/tos_rel.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def process(self, data: 'dict[int, str]') -> 'tuple[list[str], list[str]]': # t
6868
miss = [
6969
"return cls._unregistered_member(value, 'Unassigned')",
7070
]
71-
for code, name in DATA.items():
71+
for code, name in data.items():
7272
renm = self.rename(name, code).upper() # type: ignore[arg-type]
7373
enum.append(f"{renm} = {code}".ljust(76))
7474
return enum, miss

‎pcapkit/vendor/ipv4/tos_thr.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def process(self, data: 'dict[int, str]') -> 'tuple[list[str], list[str]]': # t
6868
miss = [
6969
"return cls._unregistered_member(value, 'Unassigned')",
7070
]
71-
for code, name in DATA.items():
71+
for code, name in data.items():
7272
renm = self.rename(name, code).upper() # type: ignore[arg-type]
7373
enum.append(f"{renm} = {code}".ljust(76))
7474
return enum, miss

‎pcapkit/vendor/ipv4/ts_flag.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def process(self, data: 'dict[int, str]') -> 'tuple[list[str], list[str]]': # t
6969
miss = [
7070
"return cls._unregistered_member(value, 'Unassigned')",
7171
]
72-
for code, name in DATA.items():
72+
for code, name in data.items():
7373
renm = self.rename(name, code) # type: ignore[arg-type]
7474
enum.append(f"{renm} = {code}".ljust(76))
7575
return enum, miss

‎pcapkit/vendor/ipv6/option_action.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def process(self, data: 'dict[int, str]') -> 'tuple[list[str], list[str]]': # t
8080
miss = [
8181
"return cls._unregistered_member(value, 'Unassigned')",
8282
]
83-
for code, name in DATA.items():
83+
for code, name in data.items():
8484
renm = self.rename(name, code) # type: ignore[arg-type]
8585
enum.append(f"{renm} = {code}".ljust(76))
8686
return enum, miss

0 commit comments

Comments
 (0)