smithy-json 0.2.0__tar.gz → 0.2.2__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.
- smithy_json-0.2.2/.changes/0.2.1.json +8 -0
- smithy_json-0.2.2/.changes/0.2.2.json +8 -0
- smithy_json-0.2.2/CHANGELOG.md +28 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/PKG-INFO +2 -2
- {smithy_json-0.2.0 → smithy_json-0.2.2}/pyproject.toml +1 -1
- {smithy_json-0.2.0 → smithy_json-0.2.2}/src/smithy_json/__init__.py +1 -1
- {smithy_json-0.2.0 → smithy_json-0.2.2}/src/smithy_json/_private/serializers.py +26 -3
- smithy_json-0.2.0/CHANGELOG.md +0 -18
- {smithy_json-0.2.0 → smithy_json-0.2.2}/.changes/0.0.1.json +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/.changes/0.1.0.json +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/.changes/0.2.0.json +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/.gitignore +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/NOTICE +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/README.md +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/src/smithy_json/_private/__init__.py +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/src/smithy_json/_private/deserializers.py +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/src/smithy_json/_private/documents.py +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/src/smithy_json/py.typed +0 -0
- {smithy_json-0.2.0 → smithy_json-0.2.2}/src/smithy_json/settings.py +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"changes": [
|
|
3
|
+
{
|
|
4
|
+
"type": "enhancement",
|
|
5
|
+
"description": "Fixed string serialization to escape all control characters (U+0000-U+001F) per [RFC 8259](https://www.rfc-editor.org/rfc/rfc8259#section-7), preventing invalid JSON output for multiline and other control-character-containing strings. ([#647](https://github.com/smithy-lang/smithy-python/pull/647))"
|
|
6
|
+
}
|
|
7
|
+
]
|
|
8
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## v0.2.2
|
|
4
|
+
|
|
5
|
+
### Enhancements
|
|
6
|
+
* Fixed string serialization to escape all control characters (U+0000-U+001F) per [RFC 8259](https://www.rfc-editor.org/rfc/rfc8259#section-7), preventing invalid JSON output for multiline and other control-character-containing strings. ([#647](https://github.com/smithy-lang/smithy-python/pull/647))
|
|
7
|
+
|
|
8
|
+
## v0.2.1
|
|
9
|
+
|
|
10
|
+
### Dependencies
|
|
11
|
+
* Removed strict pinning on `smithy-core` in favor of client managed versions.
|
|
12
|
+
|
|
13
|
+
## v0.2.0
|
|
14
|
+
|
|
15
|
+
### Dependencies
|
|
16
|
+
* Bump `smithy-core` from `~=0.1.0` to `~=0.2.0`.
|
|
17
|
+
|
|
18
|
+
## v0.1.0
|
|
19
|
+
|
|
20
|
+
### Enhancements
|
|
21
|
+
* Use shared settings for JSON codec
|
|
22
|
+
* Pass JSON document class through settings
|
|
23
|
+
* Use natural dict ordering for member index
|
|
24
|
+
|
|
25
|
+
## v0.0.1
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
* Added support for json primitives in Smithy clients.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: smithy-json
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: JSON serialization and deserialization support for Smithy tooling.
|
|
5
5
|
Project-URL: Changelog, https://github.com/smithy-lang/smithy-python/blob/develop/packages/smithy-json/CHANGELOG.md
|
|
6
6
|
Project-URL: Code, https://github.com/smithy-lang/smithy-python/blob/develop/packages/smithy-json/
|
|
@@ -25,7 +25,7 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
|
25
25
|
Classifier: Topic :: Software Development :: Libraries
|
|
26
26
|
Requires-Python: >=3.12
|
|
27
27
|
Requires-Dist: ijson>=3.3.0
|
|
28
|
-
Requires-Dist: smithy-core
|
|
28
|
+
Requires-Dist: smithy-core
|
|
29
29
|
Description-Content-Type: text/markdown
|
|
30
30
|
|
|
31
31
|
# smithy-json
|
|
@@ -13,7 +13,7 @@ from ._private.documents import JSONDocument
|
|
|
13
13
|
from ._private.serializers import JSONShapeSerializer as _JSONShapeSerializer
|
|
14
14
|
from .settings import JSONSettings
|
|
15
15
|
|
|
16
|
-
__version__ = "0.2.
|
|
16
|
+
__version__ = "0.2.2"
|
|
17
17
|
__all__ = ("JSONCodec", "JSONDocument", "JSONSettings")
|
|
18
18
|
|
|
19
19
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import re
|
|
4
5
|
from base64 import b64encode
|
|
5
6
|
from collections.abc import Callable, Mapping, Sequence
|
|
6
7
|
from contextlib import AbstractContextManager
|
|
@@ -27,6 +28,30 @@ from . import Flushable
|
|
|
27
28
|
_INF: float = float("inf")
|
|
28
29
|
_NEG_INF: float = float("-inf")
|
|
29
30
|
|
|
31
|
+
# RFC 8259 §7: All control characters U+0000 through U+001F MUST be escaped.
|
|
32
|
+
_ESCAPE_MAP: dict[str, str] = {
|
|
33
|
+
"\\": "\\\\",
|
|
34
|
+
'"': '\\"',
|
|
35
|
+
"\n": "\\n",
|
|
36
|
+
"\r": "\\r",
|
|
37
|
+
"\t": "\\t",
|
|
38
|
+
"\b": "\\b",
|
|
39
|
+
"\f": "\\f",
|
|
40
|
+
}
|
|
41
|
+
_CHARS_TO_ESCAPE = re.compile(r'[\\"\x00-\x1f]')
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _escape_char(match: re.Match[str]) -> str:
|
|
45
|
+
c = match.group()
|
|
46
|
+
if c in _ESCAPE_MAP:
|
|
47
|
+
return _ESCAPE_MAP[c]
|
|
48
|
+
return f"\\u{ord(c):04x}"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _escape_string(value: str) -> str:
|
|
52
|
+
"""Escape a string value per RFC 8259 §7."""
|
|
53
|
+
return _CHARS_TO_ESCAPE.sub(_escape_char, value)
|
|
54
|
+
|
|
30
55
|
|
|
31
56
|
class JSONShapeSerializer(ShapeSerializer):
|
|
32
57
|
def __init__(self, sink: BytesWriter, settings: JSONSettings) -> None:
|
|
@@ -271,9 +296,7 @@ class StreamingJSONEncoder:
|
|
|
271
296
|
|
|
272
297
|
def write_string(self, value: str) -> None:
|
|
273
298
|
self._sink.write(b'"')
|
|
274
|
-
self._sink.write(
|
|
275
|
-
value.replace("\\", "\\\\").replace('"', '\\"').encode("utf-8")
|
|
276
|
-
)
|
|
299
|
+
self._sink.write(_escape_string(value).encode("utf-8"))
|
|
277
300
|
self._sink.write(b'"')
|
|
278
301
|
|
|
279
302
|
def write_int(self, value: int) -> None:
|
smithy_json-0.2.0/CHANGELOG.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## v0.2.0
|
|
4
|
-
|
|
5
|
-
### Dependencies
|
|
6
|
-
* Bump `smithy-core` from `~=0.1.0` to `~=0.2.0`.
|
|
7
|
-
|
|
8
|
-
## v0.1.0
|
|
9
|
-
|
|
10
|
-
### Enhancements
|
|
11
|
-
* Use shared settings for JSON codec
|
|
12
|
-
* Pass JSON document class through settings
|
|
13
|
-
* Use natural dict ordering for member index
|
|
14
|
-
|
|
15
|
-
## v0.0.1
|
|
16
|
-
|
|
17
|
-
### Features
|
|
18
|
-
* Added support for json primitives in Smithy clients.
|
|
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
|