cborx 0.2.5__tar.gz → 0.2.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {cborx-0.2.5/src/cborx.egg-info → cborx-0.2.6}/PKG-INFO +3 -1
  2. {cborx-0.2.5 → cborx-0.2.6}/README.md +1 -0
  3. {cborx-0.2.5 → cborx-0.2.6}/pyproject.toml +9 -5
  4. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/__init__.py +1 -1
  5. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/encoder.py +0 -1
  6. {cborx-0.2.5 → cborx-0.2.6/src/cborx.egg-info}/PKG-INFO +3 -1
  7. {cborx-0.2.5 → cborx-0.2.6}/tests/test_adversarial.py +3 -2
  8. {cborx-0.2.5 → cborx-0.2.6}/tests/test_backends.py +30 -25
  9. {cborx-0.2.5 → cborx-0.2.6}/tests/test_differential_cbor2.py +41 -30
  10. {cborx-0.2.5 → cborx-0.2.6}/LICENSE +0 -0
  11. {cborx-0.2.5 → cborx-0.2.6}/setup.cfg +0 -0
  12. {cborx-0.2.5 → cborx-0.2.6}/setup.py +0 -0
  13. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/_backend.py +0 -0
  14. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/_fast.c +0 -0
  15. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/_fast.pyx +0 -0
  16. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/_fastshim.h +0 -0
  17. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/_util.py +0 -0
  18. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/decoder.py +0 -0
  19. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/exceptions.py +0 -0
  20. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/py.typed +0 -0
  21. {cborx-0.2.5 → cborx-0.2.6}/src/cborx/types.py +0 -0
  22. {cborx-0.2.5 → cborx-0.2.6}/src/cborx.egg-info/SOURCES.txt +0 -0
  23. {cborx-0.2.5 → cborx-0.2.6}/src/cborx.egg-info/dependency_links.txt +0 -0
  24. {cborx-0.2.5 → cborx-0.2.6}/src/cborx.egg-info/top_level.txt +0 -0
  25. {cborx-0.2.5 → cborx-0.2.6}/tests/test_api.py +0 -0
  26. {cborx-0.2.5 → cborx-0.2.6}/tests/test_fuzz.py +0 -0
  27. {cborx-0.2.5 → cborx-0.2.6}/tests/test_leaks.py +0 -0
  28. {cborx-0.2.5 → cborx-0.2.6}/tests/test_readme_smoke.py +0 -0
  29. {cborx-0.2.5 → cborx-0.2.6}/tests/test_rfc8949.py +0 -0
  30. {cborx-0.2.5 → cborx-0.2.6}/tests/test_roundtrip.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cborx
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: CBOR (RFC 8949) encoder/decoder. Zero dependencies, optional compiled fast path.
5
5
  Author: Quad4
6
6
  License-Expression: 0BSD
@@ -8,6 +8,7 @@ Project-URL: Homepage, https://quad4.io
8
8
  Project-URL: Repository, https://github.com/Quad4-Software/cborx
9
9
  Project-URL: Issues, https://github.com/Quad4-Software/cborx/issues
10
10
  Project-URL: Changelog, https://github.com/Quad4-Software/cborx/blob/master/CHANGELOG.md
11
+ Project-URL: Documentation, https://quad4-software.github.io/cborx/
11
12
  Keywords: cbor,rfc8949,serialization,codec,binary
12
13
  Classifier: Development Status :: 4 - Beta
13
14
  Classifier: Intended Audience :: Developers
@@ -25,6 +26,7 @@ Dynamic: license-file
25
26
  [![CodeQL](https://github.com/Quad4-Software/cborx/actions/workflows/codeql.yml/badge.svg)](https://github.com/Quad4-Software/cborx/actions/workflows/codeql.yml)
26
27
  [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/Quad4-Software/cborx/badge)](https://securityscorecards.dev/viewer/?uri=github.com/Quad4-Software/cborx)
27
28
  [![PyPI](https://img.shields.io/pypi/v/cborx)](https://pypi.org/project/cborx/)
29
+ [![Docs](https://img.shields.io/badge/docs-quad4--software.github.io%2Fcborx-blue)](https://quad4-software.github.io/cborx/)
28
30
  [![License: 0BSD](https://img.shields.io/badge/license-0BSD-blue)](LICENSE)
29
31
 
30
32
  CBOR (RFC 8949) encoder/decoder for Python. Zero runtime dependencies.
@@ -4,6 +4,7 @@
4
4
  [![CodeQL](https://github.com/Quad4-Software/cborx/actions/workflows/codeql.yml/badge.svg)](https://github.com/Quad4-Software/cborx/actions/workflows/codeql.yml)
5
5
  [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/Quad4-Software/cborx/badge)](https://securityscorecards.dev/viewer/?uri=github.com/Quad4-Software/cborx)
6
6
  [![PyPI](https://img.shields.io/pypi/v/cborx)](https://pypi.org/project/cborx/)
7
+ [![Docs](https://img.shields.io/badge/docs-quad4--software.github.io%2Fcborx-blue)](https://quad4-software.github.io/cborx/)
7
8
  [![License: 0BSD](https://img.shields.io/badge/license-0BSD-blue)](LICENSE)
8
9
 
9
10
  CBOR (RFC 8949) encoder/decoder for Python. Zero runtime dependencies.
@@ -25,6 +25,7 @@ Homepage = "https://quad4.io"
25
25
  Repository = "https://github.com/Quad4-Software/cborx"
26
26
  Issues = "https://github.com/Quad4-Software/cborx/issues"
27
27
  Changelog = "https://github.com/Quad4-Software/cborx/blob/master/CHANGELOG.md"
28
+ Documentation = "https://quad4-software.github.io/cborx/"
28
29
 
29
30
  [tool.setuptools]
30
31
  package-dir = {"" = "src"}
@@ -40,16 +41,19 @@ cborx = ["py.typed", "_fast.pyx", "_fastshim.h"]
40
41
 
41
42
  [dependency-groups]
42
43
  dev = [
43
- "pytest>=9.1.1",
44
+ "pytest>=9.2.0",
44
45
  "pytest-cov>=7.1.0",
45
- "ruff>=0.16.8",
46
+ "ruff>=0.17.3",
46
47
  "bandit>=1.9.4",
47
- "mypy>=2.3.1",
48
- "hypothesis>=6.168.0",
49
- "cbor2>=6.1.4,<7",
48
+ "mypy>=2.4.1",
49
+ "hypothesis>=6.168.5",
50
+ "cbor2>=6.1.5,<7",
50
51
  "cython>=3.3.0",
51
52
  "setuptools>=68",
52
53
  ]
54
+ docs = [
55
+ "zensical>=0.0.67",
56
+ ]
53
57
 
54
58
  [tool.ruff]
55
59
  target-version = "py310"
@@ -6,7 +6,7 @@ from .encoder import CBOREncoder, DefaultCallback, dump, dumps
6
6
  from .exceptions import CBORDecodeError, CBOREncodeError, CBORError
7
7
  from .types import CBORSimpleValue, CBORTag, UndefinedType, undefined
8
8
 
9
- __version__ = "0.2.5"
9
+ __version__ = "0.2.6"
10
10
 
11
11
  __all__ = [
12
12
  "CBORDecodeError",
@@ -14,7 +14,6 @@ from .exceptions import CBOREncodeError
14
14
  from .types import CBORSimpleValue, CBORTag, UndefinedType, undefined
15
15
 
16
16
  _UINT64_MAX = (1 << 64) - 1
17
- _EPOCH_DATE = date(1970, 1, 1)
18
17
  _PACK_F16 = struct.Struct(">Be")
19
18
  _PACK_F32 = struct.Struct(">Bf")
20
19
  _PACK_F64 = struct.Struct(">Bd")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cborx
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: CBOR (RFC 8949) encoder/decoder. Zero dependencies, optional compiled fast path.
5
5
  Author: Quad4
6
6
  License-Expression: 0BSD
@@ -8,6 +8,7 @@ Project-URL: Homepage, https://quad4.io
8
8
  Project-URL: Repository, https://github.com/Quad4-Software/cborx
9
9
  Project-URL: Issues, https://github.com/Quad4-Software/cborx/issues
10
10
  Project-URL: Changelog, https://github.com/Quad4-Software/cborx/blob/master/CHANGELOG.md
11
+ Project-URL: Documentation, https://quad4-software.github.io/cborx/
11
12
  Keywords: cbor,rfc8949,serialization,codec,binary
12
13
  Classifier: Development Status :: 4 - Beta
13
14
  Classifier: Intended Audience :: Developers
@@ -25,6 +26,7 @@ Dynamic: license-file
25
26
  [![CodeQL](https://github.com/Quad4-Software/cborx/actions/workflows/codeql.yml/badge.svg)](https://github.com/Quad4-Software/cborx/actions/workflows/codeql.yml)
26
27
  [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/Quad4-Software/cborx/badge)](https://securityscorecards.dev/viewer/?uri=github.com/Quad4-Software/cborx)
27
28
  [![PyPI](https://img.shields.io/pypi/v/cborx)](https://pypi.org/project/cborx/)
29
+ [![Docs](https://img.shields.io/badge/docs-quad4--software.github.io%2Fcborx-blue)](https://quad4-software.github.io/cborx/)
28
30
  [![License: 0BSD](https://img.shields.io/badge/license-0BSD-blue)](LICENSE)
29
31
 
30
32
  CBOR (RFC 8949) encoder/decoder for Python. Zero runtime dependencies.
@@ -7,12 +7,13 @@ from typing import Any, cast
7
7
 
8
8
  import pytest
9
9
 
10
- import cborx
11
10
  from cborx import (
12
11
  CBORDecodeError,
12
+ CBORDecoder,
13
13
  CBOREncodeError,
14
14
  CBOREncoder,
15
15
  CBORSimpleValue,
16
+ CBORTag,
16
17
  DuplicateMode,
17
18
  dumps,
18
19
  loads,
@@ -480,7 +481,7 @@ def test_multibyte_memoryview_trailing_check() -> None:
480
481
  def test_bytearray_mutation_during_decode() -> None:
481
482
  ba = bytearray(bytes.fromhex("d903e7") + b"\x01" + b"AAAAA")
482
483
 
483
- def hook(_dec: cborx.CBORDecoder, tag: cborx.CBORTag) -> Any:
484
+ def hook(_dec: CBORDecoder, tag: CBORTag) -> Any:
484
485
  del ba[4:]
485
486
  return tag.value
486
487
 
@@ -14,8 +14,15 @@ from typing import Any
14
14
 
15
15
  import pytest
16
16
 
17
- import cborx
18
- from cborx import _backend
17
+ from cborx import (
18
+ CBORDecodeError,
19
+ CBORSimpleValue,
20
+ CBORTag,
21
+ _backend,
22
+ dumps,
23
+ loads,
24
+ undefined,
25
+ )
19
26
  from cborx.decoder import CBORDecoder
20
27
  from cborx.encoder import CBOREncoder
21
28
 
@@ -33,12 +40,12 @@ VALUES: list[Any] = [
33
40
  True, False, None,
34
41
  [], [1, "a", b"b", 2.5, None, True],
35
42
  {}, {"a": 1, "b": [1, 2], 3: "c"},
36
- cborx.CBORTag(0, "2024-01-01T00:00:00Z"),
37
- cborx.CBORTag(1, 1700000000),
38
- cborx.CBORTag(42, [1, 2]),
39
- cborx.CBORSimpleValue(0),
40
- cborx.CBORSimpleValue(255),
41
- cborx.undefined,
43
+ CBORTag(0, "2024-01-01T00:00:00Z"),
44
+ CBORTag(1, 1700000000),
45
+ CBORTag(42, [1, 2]),
46
+ CBORSimpleValue(0),
47
+ CBORSimpleValue(255),
48
+ undefined,
42
49
  datetime(2024, 6, 1, 12, 30, 45, tzinfo=timezone.utc),
43
50
  datetime(2024, 6, 1, 12, 30, 45), # noqa: DTZ001
44
51
  date(2024, 6, 1),
@@ -104,22 +111,20 @@ def _pure_decode(data: Any, **kwargs: Any) -> Any:
104
111
  @pytest.mark.parametrize("canonical", [False, True])
105
112
  @skip_no_fast
106
113
  def test_encode_parity(obj: Any, canonical: bool) -> None:
107
- assert cborx.dumps(obj, canonical=canonical) == _pure_dumps(
108
- obj, canonical=canonical
109
- )
114
+ assert dumps(obj, canonical=canonical) == _pure_dumps(obj, canonical=canonical)
110
115
 
111
116
 
112
117
  @pytest.mark.parametrize("obj", VALUES, ids=repr)
113
118
  @skip_no_fast
114
119
  def test_encode_parity_indefinite(obj: Any) -> None:
115
- assert cborx.dumps(obj, indefinite=True) == _pure_dumps(obj, indefinite=True)
120
+ assert dumps(obj, indefinite=True) == _pure_dumps(obj, indefinite=True)
116
121
 
117
122
 
118
123
  @pytest.mark.parametrize("obj", VALUES, ids=repr)
119
124
  @skip_no_fast
120
125
  def test_roundtrip_parity(obj: Any) -> None:
121
- encoded = cborx.dumps(obj)
122
- fast_val = cborx.loads(encoded)
126
+ encoded = dumps(obj)
127
+ fast_val = loads(encoded)
123
128
  pure_val = _pure_decode(encoded)
124
129
  assert _same(fast_val, pure_val), (fast_val, pure_val)
125
130
 
@@ -128,14 +133,14 @@ def test_roundtrip_parity(obj: Any) -> None:
128
133
  @skip_no_fast
129
134
  def test_decode_parity(wire: bytes) -> None:
130
135
  try:
131
- fast_val = cborx.loads(wire)
136
+ fast_val = loads(wire)
132
137
  fast_err = None
133
- except cborx.CBORDecodeError as e:
138
+ except CBORDecodeError as e:
134
139
  fast_val, fast_err = None, e
135
140
  try:
136
141
  pure_val = _pure_decode(wire)
137
142
  pure_err = None
138
- except cborx.CBORDecodeError as e:
143
+ except CBORDecodeError as e:
139
144
  pure_val, pure_err = None, e
140
145
  assert (fast_err is None) == (pure_err is None), wire.hex()
141
146
  if fast_err is None:
@@ -147,7 +152,7 @@ def test_decode_parity(wire: bytes) -> None:
147
152
 
148
153
  @skip_no_fast
149
154
  def test_decode_options_parity() -> None:
150
- wire = cborx.dumps({"b": 1, "a": 2})
155
+ wire = dumps({"b": 1, "a": 2})
151
156
  option_sets: tuple[dict[str, Any], ...] = (
152
157
  {"canonical": True},
153
158
  {"duplicate_keys": "first"},
@@ -160,7 +165,7 @@ def test_decode_options_parity() -> None:
160
165
  for kwargs in option_sets:
161
166
  for data in (wire, b"\x9f\x01\x02\xff", b"\xc8\x01", b"\xff"):
162
167
  try:
163
- fast_val = cborx.loads(data, **kwargs)
168
+ fast_val = loads(data, **kwargs)
164
169
  fast_err = None
165
170
  except Exception as e: # noqa: BLE001
166
171
  fast_val, fast_err = None, e
@@ -179,8 +184,8 @@ def test_decode_options_parity() -> None:
179
184
 
180
185
  @skip_no_fast
181
186
  def test_decode_pos_and_trailing_parity() -> None:
182
- data = cborx.dumps([1]) + cborx.dumps([2])
183
- assert cborx.loads(data, allow_trailing=True) == [1]
187
+ data = dumps([1]) + dumps([2])
188
+ assert loads(data, allow_trailing=True) == [1]
184
189
  saved = _backend.fast
185
190
  _backend.fast = None
186
191
  try:
@@ -188,14 +193,14 @@ def test_decode_pos_and_trailing_parity() -> None:
188
193
  finally:
189
194
  _backend.fast = saved
190
195
  assert CBORDecoder().decode_item(data, 2) == ([2], 4)
191
- with pytest.raises(cborx.CBORDecodeError):
192
- cborx.loads(data)
193
- with pytest.raises(cborx.CBORDecodeError):
196
+ with pytest.raises(CBORDecodeError):
197
+ loads(data)
198
+ with pytest.raises(CBORDecodeError):
194
199
  CBORDecoder().decode_item(data, -1)
195
200
  saved = _backend.fast
196
201
  _backend.fast = None
197
202
  try:
198
- with pytest.raises(cborx.CBORDecodeError):
203
+ with pytest.raises(CBORDecodeError):
199
204
  CBORDecoder().decode_item(data, -1)
200
205
  finally:
201
206
  _backend.fast = saved
@@ -43,8 +43,19 @@ import pytest
43
43
  from hypothesis import given, settings
44
44
  from hypothesis import strategies as st
45
45
 
46
- import cborx
47
- from cborx import CBORSimpleValue, CBORTag, dumps, loads, undefined
46
+ from cborx import (
47
+ CBORDecodeError,
48
+ CBORDecoder,
49
+ CBOREncodeError,
50
+ CBOREncoder,
51
+ CBORError,
52
+ CBORSimpleValue,
53
+ CBORTag,
54
+ UndefinedType,
55
+ dumps,
56
+ loads,
57
+ undefined,
58
+ )
48
59
 
49
60
  cbor2 = pytest.importorskip("cbor2", reason="differential oracle not installed")
50
61
 
@@ -105,11 +116,11 @@ _TREES: st.SearchStrategy[Any] = st.recursive(
105
116
 
106
117
  def _to_cbor2(obj: Any) -> Any:
107
118
  """Convert cborx-side values into their cbor2 equivalents."""
108
- if isinstance(obj, cborx.CBORTag):
119
+ if isinstance(obj, CBORTag):
109
120
  return cbor2.CBORTag(obj.tag, _to_cbor2(obj.value))
110
- if isinstance(obj, cborx.CBORSimpleValue):
121
+ if isinstance(obj, CBORSimpleValue):
111
122
  return cbor2.CBORSimpleValue(obj.value)
112
- if isinstance(obj, cborx.UndefinedType):
123
+ if isinstance(obj, UndefinedType):
113
124
  return cbor2.undefined
114
125
  if isinstance(obj, dict):
115
126
  return {_to_cbor2(k): _to_cbor2(v) for k, v in obj.items()}
@@ -152,14 +163,14 @@ def _norm_semantic(obj: Any) -> Any:
152
163
 
153
164
  def _norm_taglike(obj: Any) -> Any:
154
165
  """Normalize tag, simple and undefined wrappers from either library."""
155
- if isinstance(obj, (cborx.CBORTag, cbor2.CBORTag)):
166
+ if isinstance(obj, (CBORTag, cbor2.CBORTag)):
156
167
  if obj.tag == 258 and isinstance(obj.value, (list, tuple)):
157
168
  # Tag 258 content is a set: order is not meaningful.
158
169
  return ("tag", 258, frozenset(_norm(v) for v in obj.value))
159
170
  return ("tag", obj.tag, _norm(obj.value))
160
- if isinstance(obj, (cborx.CBORSimpleValue, cbor2.CBORSimpleValue)):
171
+ if isinstance(obj, (CBORSimpleValue, cbor2.CBORSimpleValue)):
161
172
  return ("simple", obj.value)
162
- if isinstance(obj, (cborx.UndefinedType, type(cbor2.undefined))):
173
+ if isinstance(obj, (UndefinedType, type(cbor2.undefined))):
163
174
  return ("undefined",)
164
175
  return _UNKNOWN
165
176
 
@@ -317,7 +328,7 @@ def _mutated_cbor(draw: Any) -> bytes:
317
328
  encoder = draw(
318
329
  st.sampled_from(
319
330
  [
320
- lambda o: dumps(o),
331
+ dumps,
321
332
  lambda o: dumps(o, canonical=True),
322
333
  lambda o: dumps(o, indefinite=True),
323
334
  lambda o: cbor2.dumps(_to_cbor2(o)),
@@ -390,11 +401,11 @@ def _wire_tags(data: bytes) -> set[int]:
390
401
  """Collect the tag numbers present on the wire via a tag_hook tap."""
391
402
  seen: set[int] = set()
392
403
 
393
- def tap(_dec: cborx.CBORDecoder, tag: CBORTag) -> Any:
404
+ def tap(_dec: CBORDecoder, tag: CBORTag) -> Any:
394
405
  seen.add(tag.tag)
395
406
  return tag
396
407
 
397
- with contextlib.suppress(cborx.CBORError):
408
+ with contextlib.suppress(CBORError):
398
409
  loads(data, allow_trailing=True, tag_hook=tap)
399
410
  return seen
400
411
 
@@ -419,7 +430,7 @@ def _only_cbor2_ok(data: bytes, theirs: Any) -> None:
419
430
  return
420
431
  if _has_break_sentinel(theirs):
421
432
  return
422
- with pytest.raises(cborx.CBORDecodeError, match="unhashable"):
433
+ with pytest.raises(CBORDecodeError, match="unhashable"):
423
434
  loads(data, allow_trailing=True)
424
435
 
425
436
 
@@ -435,9 +446,8 @@ def _assert_decode_agreement(data: bytes) -> None:
435
446
  theirs_err = ""
436
447
  try:
437
448
  ours = loads(data, allow_trailing=True)
438
- except cborx.CBORError:
449
+ except CBORError:
439
450
  ours_ok = False
440
- ours = None
441
451
  else:
442
452
  ours_ok = True
443
453
 
@@ -519,7 +529,7 @@ def test_date_tag_error_parity() -> None:
519
529
  def test_default_callback_matches_cbor2_native_encoding() -> None:
520
530
  """cborx's default hook can emit byte-identical semantic encodings."""
521
531
 
522
- def default(_encoder: cborx.CBOREncoder, obj: Any) -> Any:
532
+ def default(_encoder: CBOREncoder, obj: Any) -> Any:
523
533
  if isinstance(obj, Fraction):
524
534
  return CBORTag(30, [obj.numerator, obj.denominator])
525
535
  if isinstance(obj, Decimal):
@@ -528,7 +538,7 @@ def test_default_callback_matches_cbor2_native_encoding() -> None:
528
538
  return CBORTag(4, [int(t.exponent), -mantissa if t.sign else mantissa])
529
539
  if isinstance(obj, uuid.UUID):
530
540
  return CBORTag(37, obj.bytes)
531
- raise cborx.CBOREncodeError(f"cannot encode {type(obj).__name__}")
541
+ raise CBOREncodeError(f"cannot encode {type(obj).__name__}")
532
542
 
533
543
  for obj in (Fraction(22, 7), Decimal("-1.5"), uuid.uuid5(uuid.NAMESPACE_DNS, "x")):
534
544
  ours = dumps(obj, default=default)
@@ -551,7 +561,7 @@ def test_shareable_reference_divergence() -> None:
551
561
  def test_unhashable_key_divergence() -> None:
552
562
  wire = cbor2.dumps({(1, 2): 3})
553
563
  assert cbor2.loads(wire) == {(1, 2): 3}
554
- with pytest.raises(cborx.CBORDecodeError):
564
+ with pytest.raises(CBORDecodeError):
555
565
  loads(wire)
556
566
 
557
567
 
@@ -560,26 +570,27 @@ def test_naive_datetime_divergence() -> None:
560
570
  with pytest.raises(cbor2.CBOREncodeError):
561
571
  cbor2.dumps(naive)
562
572
  ours = dumps(naive)
563
- assert cbor2.loads(ours) == naive
573
+ assert loads(ours) == naive
574
+ with pytest.raises(cbor2.CBORDecodeError):
575
+ cbor2.loads(ours)
564
576
 
565
577
 
566
578
  def test_trailing_bytes_divergence() -> None:
567
579
  wire = dumps(1) + dumps(2)
568
580
  assert cbor2.loads(wire) == 1
569
- with pytest.raises(cborx.CBORDecodeError):
581
+ with pytest.raises(CBORDecodeError):
570
582
  loads(wire)
571
583
  assert loads(wire, allow_trailing=True) == 1
572
584
 
573
585
 
574
586
  def test_stray_break_divergence() -> None:
575
- # cbor2 surfaces a bare break byte as an opaque marker object and
576
- # even accepts it as a map key. cborx rejects it per RFC 8949.
577
- marker = cbor2.loads(b"\xff")
578
- assert type(marker) is object
579
- with pytest.raises(cborx.CBORDecodeError):
580
- loads(b"\xff")
581
- with pytest.raises(cborx.CBORDecodeError):
582
- loads(bytes.fromhex("a1ff01"))
587
+ # Both codecs reject a bare break byte per RFC 8949. Older cbor2
588
+ # releases surfaced it as an opaque marker object instead.
589
+ for wire in (b"\xff", bytes.fromhex("a1ff01")):
590
+ with pytest.raises(CBORDecodeError):
591
+ loads(wire)
592
+ with pytest.raises(cbor2.CBORDecodeError):
593
+ cbor2.loads(wire)
583
594
 
584
595
 
585
596
  def test_tag_hook_semantics_divergence() -> None:
@@ -598,7 +609,7 @@ def test_tag_hook_semantics_divergence() -> None:
598
609
 
599
610
  seen2: list[int] = []
600
611
 
601
- def cborx_hook(_dec: cborx.CBORDecoder, tag: CBORTag) -> Any:
612
+ def cborx_hook(_dec: CBORDecoder, tag: CBORTag) -> Any:
602
613
  seen2.append(tag.tag)
603
614
  return tag.value
604
615
 
@@ -628,7 +639,7 @@ def test_encode_error_parity() -> None:
628
639
  class Widget:
629
640
  pass
630
641
 
631
- with pytest.raises(cborx.CBOREncodeError):
642
+ with pytest.raises(CBOREncodeError):
632
643
  dumps(Widget())
633
644
  with pytest.raises(cbor2.CBOREncodeError):
634
645
  cbor2.dumps(Widget())
@@ -642,7 +653,7 @@ def test_decode_error_type_parity() -> None:
642
653
  b"\xa1\x01", # odd map item count
643
654
  ]
644
655
  for data in bad_inputs:
645
- with pytest.raises(cborx.CBORDecodeError):
656
+ with pytest.raises(CBORDecodeError):
646
657
  loads(data)
647
658
  with pytest.raises(cbor2.CBORDecodeError):
648
659
  cbor2.loads(data)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes