cborx 0.2.3__tar.gz → 0.2.4__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.
- {cborx-0.2.3/src/cborx.egg-info → cborx-0.2.4}/PKG-INFO +1 -1
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/__init__.py +1 -1
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/decoder.py +4 -1
- {cborx-0.2.3 → cborx-0.2.4/src/cborx.egg-info}/PKG-INFO +1 -1
- {cborx-0.2.3 → cborx-0.2.4}/tests/test_api.py +11 -0
- {cborx-0.2.3 → cborx-0.2.4}/tests/test_differential_cbor2.py +19 -1
- {cborx-0.2.3 → cborx-0.2.4}/LICENSE +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/README.md +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/pyproject.toml +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/setup.cfg +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/setup.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/_backend.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/_fast.c +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/_fast.pyx +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/_fastshim.h +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/_util.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/encoder.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/exceptions.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/py.typed +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx/types.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx.egg-info/SOURCES.txt +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx.egg-info/dependency_links.txt +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/src/cborx.egg-info/top_level.txt +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/tests/test_adversarial.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/tests/test_backends.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/tests/test_fuzz.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/tests/test_leaks.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/tests/test_readme_smoke.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/tests/test_rfc8949.py +0 -0
- {cborx-0.2.3 → cborx-0.2.4}/tests/test_roundtrip.py +0 -0
|
@@ -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.
|
|
9
|
+
__version__ = "0.2.4"
|
|
10
10
|
|
|
11
11
|
__all__ = [
|
|
12
12
|
"CBORDecodeError",
|
|
@@ -36,6 +36,7 @@ _FLOAT_UNPACK: dict[int, struct.Struct] = {25: _F16, 26: _F32, 27: _F64}
|
|
|
36
36
|
_FLOAT_SIZES = {25: 2, 26: 4, 27: 8}
|
|
37
37
|
_MINIMAL_ARG = {1: 24, 2: 0x100, 4: 0x10000, 8: 0x100000000}
|
|
38
38
|
_EPOCH_DATE = date(1970, 1, 1)
|
|
39
|
+
_EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc)
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
class _Frame:
|
|
@@ -474,7 +475,9 @@ def _decode_epoch(value: Any) -> datetime:
|
|
|
474
475
|
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
475
476
|
raise CBORDecodeError("tag 1 must wrap a number")
|
|
476
477
|
try:
|
|
477
|
-
|
|
478
|
+
# Epoch arithmetic avoids fromtimestamp, whose C library call
|
|
479
|
+
# rejects negative timestamps on Windows.
|
|
480
|
+
return _EPOCH + timedelta(seconds=value)
|
|
478
481
|
except (OverflowError, OSError, ValueError) as e:
|
|
479
482
|
raise CBORDecodeError(f"tag 1 timestamp {value!r} out of range") from e
|
|
480
483
|
|
|
@@ -357,6 +357,17 @@ def test_epoch_tag_rejects_bad_values() -> None:
|
|
|
357
357
|
loads(bytes.fromhex("c1f5")) # tag 1 wrapping true
|
|
358
358
|
|
|
359
359
|
|
|
360
|
+
def test_epoch_tag_decodes_negative_timestamps() -> None:
|
|
361
|
+
# Pre-epoch timestamps hit a C library call that rejects negative
|
|
362
|
+
# time_t on Windows. Decoding must not depend on platform support.
|
|
363
|
+
assert loads(bytes.fromhex("c13a01e1337f")) == datetime(
|
|
364
|
+
1969, 1, 1, tzinfo=timezone.utc
|
|
365
|
+
)
|
|
366
|
+
assert loads(bytes.fromhex("c1fbbfe0000000000000")) == datetime(
|
|
367
|
+
1969, 12, 31, 23, 59, 59, 500000, tzinfo=timezone.utc
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
|
|
360
371
|
def test_empty_and_nested_empty_containers() -> None:
|
|
361
372
|
obj = {"e": [], "m": {}, "n": [[], [{}], {"x": []}]}
|
|
362
373
|
assert loads(dumps(obj)) == obj
|
|
@@ -22,12 +22,17 @@ Deliberate scope differences, asserted rather than hidden:
|
|
|
22
22
|
* cbor2 calls tag_hook only for tags without a built-in decoder and
|
|
23
23
|
passes (tag, immutable). cborx calls tag_hook(decoder, tag) for
|
|
24
24
|
every tag, overriding built-in handling.
|
|
25
|
+
* cbor2 decodes tag 1 timestamps through the C runtime. On Windows
|
|
26
|
+
that rejects values before 1970 or after year 3000, so the
|
|
27
|
+
timestamp parity test generates datetimes inside that range there.
|
|
28
|
+
cborx uses epoch arithmetic and decodes the full range everywhere.
|
|
25
29
|
"""
|
|
26
30
|
|
|
27
31
|
import contextlib
|
|
28
32
|
import ipaddress
|
|
29
33
|
import math
|
|
30
34
|
import re
|
|
35
|
+
import sys
|
|
31
36
|
import uuid
|
|
32
37
|
from datetime import date, datetime, timedelta, timezone
|
|
33
38
|
from decimal import Decimal
|
|
@@ -45,6 +50,19 @@ cbor2 = pytest.importorskip("cbor2", reason="differential oracle not installed")
|
|
|
45
50
|
|
|
46
51
|
_FIXED_TZ = st.integers(-14 * 60, 14 * 60).map(lambda m: timezone(timedelta(minutes=m)))
|
|
47
52
|
|
|
53
|
+
# Range of tag 1 timestamps cbor2 can decode on the current platform.
|
|
54
|
+
# On Windows its C decoder calls gmtime, which accepts only
|
|
55
|
+
# 1970-01-01 through 3000-12-31 UTC. The bounds are padded by the
|
|
56
|
+
# maximum _FIXED_TZ offset (14h) so the UTC timestamp stays in range.
|
|
57
|
+
if sys.platform == "win32":
|
|
58
|
+
_TS_DATETIMES = st.datetimes(
|
|
59
|
+
min_value=datetime(1970, 1, 2), # noqa: DTZ001 # bounds are naive
|
|
60
|
+
max_value=datetime(3000, 12, 30), # noqa: DTZ001
|
|
61
|
+
timezones=_FIXED_TZ,
|
|
62
|
+
)
|
|
63
|
+
else:
|
|
64
|
+
_TS_DATETIMES = st.datetimes(timezones=_FIXED_TZ)
|
|
65
|
+
|
|
48
66
|
# Tags 28 and 29 carry shareable-reference semantics in cbor2 that
|
|
49
67
|
# cborx does not implement, so they are excluded from generated
|
|
50
68
|
# structures and covered by an explicit divergence test instead.
|
|
@@ -236,7 +254,7 @@ def test_encode_bytes_equal_canonical(obj: Any) -> None:
|
|
|
236
254
|
assert dumps(obj, canonical=True) == cbor2.dumps(_to_cbor2(obj), canonical=True)
|
|
237
255
|
|
|
238
256
|
|
|
239
|
-
@given(
|
|
257
|
+
@given(_TS_DATETIMES)
|
|
240
258
|
@settings(max_examples=100)
|
|
241
259
|
def test_datetime_as_timestamp_parity(dt: datetime) -> None:
|
|
242
260
|
ours = dumps(dt, datetime_as_timestamp=True)
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|