tba-codec-jcs 0.4.0.dev2__py3-none-any.whl

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.
@@ -0,0 +1,33 @@
1
+ """RFC 8785 canonical JSON serialization."""
2
+
3
+ import json
4
+ from typing import Any
5
+
6
+ import rfc8785
7
+
8
+
9
+ def canonicalize(value: Any) -> bytes:
10
+ """Return RFC 8785 canonical JSON encoded as UTF-8."""
11
+ try:
12
+ return rfc8785.dumps(value)
13
+ except rfc8785.CanonicalizationError as exc:
14
+ raise ValueError(str(exc)) from exc
15
+
16
+
17
+ def _unique_pairs(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
18
+ result: dict[str, Any] = {}
19
+ for key, value in pairs:
20
+ if key in result:
21
+ raise ValueError(f"duplicate JSON object member: {key!r}")
22
+ result[key] = value
23
+ return result
24
+
25
+
26
+ def canonicalize_json(document: str | bytes | bytearray) -> bytes:
27
+ """Parse JSON with duplicate-name rejection and emit canonical bytes."""
28
+ if isinstance(document, (bytes, bytearray)):
29
+ document = bytes(document).decode("utf-8")
30
+ return canonicalize(json.loads(document, object_pairs_hook=_unique_pairs))
31
+
32
+
33
+ __all__ = ["canonicalize", "canonicalize_json"]
tba_codec_jcs/py.typed ADDED
File without changes
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: tba-codec-jcs
3
+ Version: 0.4.0.dev2
4
+ Summary: RFC 8785 JSON Canonicalization Scheme codec.
5
+ License-Expression: Apache-2.0
6
+ Requires-Python: >=3.10,<3.16
7
+ Classifier: Programming Language :: Python :: 3.10
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Classifier: Programming Language :: Python :: 3.14
12
+ Classifier: Programming Language :: Python :: 3.15
13
+ Requires-Dist: rfc8785 (>=0.1.4,<0.2)
14
+ Description-Content-Type: text/markdown
15
+
16
+ # tba-codec-jcs
17
+
18
+ <!-- BEGIN TBA README HEADER -->
19
+ <p align="center">
20
+ <a href="https://github.com/tigrbl/tigrbl_auth#readme"><img src="https://raw.githubusercontent.com/tigrbl/tigrbl_auth/master/docs/assets/tba-brand.png" alt="TBA · Tigrbl Auth" width="240"></a>
21
+ </p>
22
+ <p align="center">
23
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/03-codecs/tba-codec-jcs/pyproject.toml"><img alt="Checkout: 0.4.0.dev2" src="https://img.shields.io/badge/Checkout-0.4.0.dev2-1f6feb"></a>
24
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/03-codecs/tba-codec-jcs/pyproject.toml"><img alt="Python: &gt;=3.10,&lt;3.16" src="https://img.shields.io/badge/Python-%3E%3D3.10%2C%3C3.16-3776ab"></a>
25
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/03-codecs/tba-codec-jcs/pyproject.toml"><img alt="License: Apache-2.0" src="https://img.shields.io/badge/License-Apache--2.0-525252"></a>
26
+ <a href="https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/03-codecs"><img alt="Layer: 03 codecs" src="https://img.shields.io/badge/Layer-03%20codecs-0a7f5a"></a>
27
+ <a href="https://pypi.org/project/tba-codec-jcs/"><img alt="PyPI version for tba-codec-jcs" src="https://img.shields.io/pypi/v/tba-codec-jcs?label=tba-codec-jcs%20PyPI"></a>
28
+ </p>
29
+ <p align="center">
30
+ <a href="https://pepy.tech/project/tba-codec-jcs"><img alt="Monthly PyPI downloads for tba-codec-jcs" src="https://static.pepy.tech/badge/tba-codec-jcs/month"></a>
31
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/03-codecs/tba-codec-jcs/README.md#verification"><img alt="Evidence: verification" src="https://img.shields.io/badge/Evidence-verification-8250df"></a>
32
+ </p>
33
+ <!-- END TBA README HEADER -->
34
+
35
+ Use `canonicalize` for JSON values or `canonicalize_json` for raw JSON. Both produce canonical UTF-8 bytes using the rfc8785 library. The raw JSON entry point rejects duplicate keys.
36
+
37
+ This package owns TBA’s strict JCS API. New callers should import from `tba_codec_jcs`.
38
+ The [RFC 8785 conformance suite](../../../tests/conformance/backlog/test_rfc8785_jcs.py) verifies this package.
39
+
40
+ [Specification](https://www.rfc-editor.org/rfc/rfc8785.html)
41
+
42
+ ## Quick start
43
+
44
+ Build the package from the repository root.
45
+
46
+ ```bash
47
+ uv build --wheel pkgs/03-codecs/tba-codec-jcs
48
+ ```
49
+
50
+ ## Verification
51
+
52
+ Check that the build produces a wheel with the package version declared in `pyproject.toml`.
53
+
@@ -0,0 +1,5 @@
1
+ tba_codec_jcs/__init__.py,sha256=eORRhst-M6GKGm0D68_rXeIcjckioVKvokJygEdS2dU,983
2
+ tba_codec_jcs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ tba_codec_jcs-0.4.0.dev2.dist-info/METADATA,sha256=a5bf3lmIvrTCuFRb7M8f4_vAgK5K3pUN8O8ZYZY8_88,2933
4
+ tba_codec_jcs-0.4.0.dev2.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
5
+ tba_codec_jcs-0.4.0.dev2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.5.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any