sdp: address review nits (import at top, InvalidPacketError)

- bumble/sdp.py: replace raise ValueError with raise InvalidPacketError
  in DataElement.list_from_bytes depth guard. InvalidPacketError
  already imported at line 34 and extends ValueError so the existing
  regression test continues to match.
- tests/sdp_test.py: remove duplicate 'import pytest' inside
  test_nested_sequence_recursion_guard; pytest already imported at
  module top (line 23).

Threading.local counter left as-is per zxzxwu's 'leave it here and
refactor later' comment on the PR.
This commit is contained in:
ibondarenko1
2026-04-24 11:38:36 -07:00
parent c55eb156b8
commit 16d0ed56cf
2 changed files with 1 additions and 3 deletions

View File

@@ -294,7 +294,7 @@ class DataElement:
def list_from_bytes(data): def list_from_bytes(data):
depth = getattr(_parse_state, "depth", 0) depth = getattr(_parse_state, "depth", 0)
if depth >= _MAX_DATA_ELEMENT_NESTING: if depth >= _MAX_DATA_ELEMENT_NESTING:
raise ValueError( raise InvalidPacketError(
f"SDP data element nesting exceeds max depth " f"SDP data element nesting exceeds max depth "
f"({_MAX_DATA_ELEMENT_NESTING})" f"({_MAX_DATA_ELEMENT_NESTING})"
) )

View File

@@ -461,8 +461,6 @@ def test_nested_sequence_recursion_guard():
break break
inner = bytes([0x36, (size >> 8) & 0xFF, size & 0xFF]) + inner inner = bytes([0x36, (size >> 8) & 0xFF, size & 0xFF]) + inner
import pytest
with pytest.raises(ValueError, match="nesting exceeds max depth"): with pytest.raises(ValueError, match="nesting exceeds max depth"):
DataElement.from_bytes(inner) DataElement.from_bytes(inner)