jsonpatch 1.43__tar.gz → 1.44__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.
- {jsonpatch-1.43/jsonpatch.egg-info → jsonpatch-1.44}/PKG-INFO +1 -1
- {jsonpatch-1.43 → jsonpatch-1.44}/jsonpatch-stubs/__init__.pyi +6 -5
- {jsonpatch-1.43 → jsonpatch-1.44/jsonpatch.egg-info}/PKG-INFO +1 -1
- {jsonpatch-1.43 → jsonpatch-1.44}/jsonpatch.py +9 -4
- {jsonpatch-1.43 → jsonpatch-1.44}/tests.py +27 -1
- {jsonpatch-1.43 → jsonpatch-1.44}/typetests/usage.py +10 -1
- {jsonpatch-1.43 → jsonpatch-1.44}/AUTHORS +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/LICENSE +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/MANIFEST.in +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/README.md +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/doc/commandline.rst +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/doc/index.rst +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/doc/mod-jsonpatch.rst +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/doc/tutorial.rst +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/ext_tests.py +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/jsonpatch.egg-info/SOURCES.txt +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/jsonpatch.egg-info/dependency_links.txt +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/jsonpatch.egg-info/entry_points.txt +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/jsonpatch.egg-info/requires.txt +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/jsonpatch.egg-info/top_level.txt +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/jsonpatch_cli.py +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/property_tests.py +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/pyproject.toml +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/pytest.ini +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/requirements.txt +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/setup.cfg +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/setup.py +0 -0
- {jsonpatch-1.43 → jsonpatch-1.44}/tests.js +0 -0
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
# also accepts arbitrary Mapping / Sequence types, which a recursive JSON type
|
|
10
10
|
# would reject.
|
|
11
11
|
|
|
12
|
-
from collections.abc import Callable, Iterable, Iterator, Mapping
|
|
12
|
+
from collections.abc import Callable, Iterable, Iterator, Mapping
|
|
13
|
+
from types import MappingProxyType
|
|
13
14
|
from typing import Any, ClassVar
|
|
14
15
|
|
|
15
16
|
# Re-exported, as jsonpatch.py imports them and users rely on that, e.g. to
|
|
@@ -57,7 +58,7 @@ class PatchOperation:
|
|
|
57
58
|
pointer_cls: type[JsonPointer]
|
|
58
59
|
location: str
|
|
59
60
|
pointer: JsonPointer
|
|
60
|
-
operation:
|
|
61
|
+
operation: dict[str, Any]
|
|
61
62
|
def __init__(self, operation: _Operation, pointer_cls: type[JsonPointer] = ...) -> None: ...
|
|
62
63
|
def apply(self, obj: Any) -> Any: ...
|
|
63
64
|
def __hash__(self) -> int: ...
|
|
@@ -92,12 +93,12 @@ class CopyOperation(PatchOperation): ...
|
|
|
92
93
|
class JsonPatch:
|
|
93
94
|
json_dumper: ClassVar[Callable[..., str]]
|
|
94
95
|
json_loader: ClassVar[Callable[..., Any]]
|
|
95
|
-
operations: ClassVar[
|
|
96
|
+
operations: ClassVar[MappingProxyType[str, type[PatchOperation]]]
|
|
96
97
|
pointer_cls: type[JsonPointer]
|
|
97
|
-
patch:
|
|
98
|
+
patch: list[dict[str, Any]]
|
|
98
99
|
def __init__(self, patch: Iterable[_Operation], pointer_cls: type[JsonPointer] = ...) -> None: ...
|
|
99
100
|
def __bool__(self) -> bool: ...
|
|
100
|
-
def __iter__(self) -> Iterator[
|
|
101
|
+
def __iter__(self) -> Iterator[dict[str, Any]]: ...
|
|
101
102
|
def __hash__(self) -> int: ...
|
|
102
103
|
def __eq__(self, other: object) -> bool: ...
|
|
103
104
|
def __ne__(self, other: object) -> bool: ...
|
|
@@ -55,7 +55,7 @@ _EXACT_MATCH_LIMIT = 500 ** 2
|
|
|
55
55
|
|
|
56
56
|
# Will be parsed by setup.py to determine package metadata
|
|
57
57
|
__author__ = 'Stefan Kögl <stefan@skoegl.net>'
|
|
58
|
-
__version__ = '1.
|
|
58
|
+
__version__ = '1.44'
|
|
59
59
|
__website__ = 'https://github.com/stefankoegl/python-json-patch'
|
|
60
60
|
__license__ = 'BSD-3-Clause'
|
|
61
61
|
|
|
@@ -373,7 +373,8 @@ class PatchOperation(object):
|
|
|
373
373
|
except TypeError:
|
|
374
374
|
raise InvalidJsonPatch("Invalid 'path'", op=operation)
|
|
375
375
|
|
|
376
|
-
|
|
376
|
+
# Setters update operation members, even when the input is read-only.
|
|
377
|
+
self.operation = operation if isinstance(operation, dict) else dict(operation)
|
|
377
378
|
|
|
378
379
|
def _from_pointer(self):
|
|
379
380
|
"""Builds the pointer of the 'from' member like __init__ builds the
|
|
@@ -791,7 +792,7 @@ class JsonPatch(object):
|
|
|
791
792
|
if isinstance(patch, (str, bytes, Mapping)):
|
|
792
793
|
raise InvalidJsonPatch("Document is expected to be sequence of operations")
|
|
793
794
|
try:
|
|
794
|
-
self.patch =
|
|
795
|
+
self.patch = list(patch)
|
|
795
796
|
except TypeError:
|
|
796
797
|
raise InvalidJsonPatch("Document is expected to be sequence of operations")
|
|
797
798
|
|
|
@@ -799,7 +800,7 @@ class JsonPatch(object):
|
|
|
799
800
|
# is correct by retrieving each patch element.
|
|
800
801
|
# Much of the validation is done in the initializer
|
|
801
802
|
# though some is delayed until the patch is applied.
|
|
802
|
-
for op in self.patch:
|
|
803
|
+
for index, op in enumerate(self.patch):
|
|
803
804
|
# We're only checking for strings in the following check
|
|
804
805
|
# for two reasons:
|
|
805
806
|
#
|
|
@@ -815,6 +816,10 @@ class JsonPatch(object):
|
|
|
815
816
|
op=op)
|
|
816
817
|
|
|
817
818
|
self._get_operation(op)
|
|
819
|
+
# Keep validation errors tied to the original input, but expose
|
|
820
|
+
# concrete, JSON-serializable operation dictionaries on success.
|
|
821
|
+
if not isinstance(op, dict):
|
|
822
|
+
self.patch[index] = dict(op)
|
|
818
823
|
|
|
819
824
|
def __str__(self):
|
|
820
825
|
"""str(self) -> self.to_string()"""
|
|
@@ -1818,9 +1818,35 @@ class JsonPatchCreationTest(unittest.TestCase):
|
|
|
1818
1818
|
({'op': 'add', 'path': '/a', 'value': 1},)):
|
|
1819
1819
|
with self.subTest(operations=operations):
|
|
1820
1820
|
patch = jsonpatch.JsonPatch(operations)
|
|
1821
|
-
self.
|
|
1821
|
+
self.assertIsInstance(patch.patch, list)
|
|
1822
|
+
self.assertEqual(patch.patch, list(operations))
|
|
1822
1823
|
self.assertEqual(patch.apply({}), {'a': 1} if operations else {})
|
|
1823
1824
|
|
|
1825
|
+
def test_creation_normalizes_abstract_operations(self):
|
|
1826
|
+
operation = MappingProxyType({'op': 'add', 'path': '/a', 'value': 1})
|
|
1827
|
+
for operations in ([operation], (operation,), iter([operation])):
|
|
1828
|
+
with self.subTest(operations=type(operations).__name__):
|
|
1829
|
+
patch = jsonpatch.JsonPatch(operations)
|
|
1830
|
+
self.assertIsInstance(patch.patch, list)
|
|
1831
|
+
self.assertIsInstance(patch.patch[0], dict)
|
|
1832
|
+
self.assertIsInstance(next(iter(patch)), dict)
|
|
1833
|
+
self.assertEqual(json.loads(patch.to_string()), [dict(operation)])
|
|
1834
|
+
patch.patch[0]['path'] = '/b'
|
|
1835
|
+
self.assertEqual(patch.apply({}), {'b': 1})
|
|
1836
|
+
self.assertEqual(operation['path'], '/a')
|
|
1837
|
+
|
|
1838
|
+
def test_operation_normalizes_read_only_mapping(self):
|
|
1839
|
+
operation = MappingProxyType({
|
|
1840
|
+
'op': 'move', 'from': '/a/0', 'path': '/b/0'})
|
|
1841
|
+
move = jsonpatch.MoveOperation(operation)
|
|
1842
|
+
self.assertIsInstance(move.operation, dict)
|
|
1843
|
+
move.key = 1
|
|
1844
|
+
move.from_key = 2
|
|
1845
|
+
self.assertEqual(move.operation['path'], '/b/1')
|
|
1846
|
+
self.assertEqual(move.operation['from'], '/a/2')
|
|
1847
|
+
self.assertEqual(operation['path'], '/b/0')
|
|
1848
|
+
self.assertEqual(operation['from'], '/a/0')
|
|
1849
|
+
|
|
1824
1850
|
def test_creation_fails_with_invalid_patch(self):
|
|
1825
1851
|
invalid_patches = [
|
|
1826
1852
|
{ 'path': '/foo', 'value': 'bar'},
|
|
@@ -9,6 +9,7 @@ unused ignores), so they test that wrong usage is rejected.
|
|
|
9
9
|
|
|
10
10
|
import json
|
|
11
11
|
from collections.abc import Mapping
|
|
12
|
+
from types import MappingProxyType
|
|
12
13
|
from typing import Any
|
|
13
14
|
|
|
14
15
|
import jsonpointer
|
|
@@ -45,12 +46,19 @@ assert_type(patch.apply(doc, in_place=True, atomic=True), Any)
|
|
|
45
46
|
assert_type(patch.to_string(), str)
|
|
46
47
|
assert_type(patch.to_string(dumps=json.dumps), str)
|
|
47
48
|
assert_type(bool(patch), bool)
|
|
48
|
-
assert_type(
|
|
49
|
+
assert_type(patch.patch, list[dict[str, Any]])
|
|
50
|
+
assert_type(list(patch), list[dict[str, Any]])
|
|
51
|
+
assert_type(next(iter(patch)), dict[str, Any])
|
|
52
|
+
assert_type(jsonpatch.make_patch(doc, {}).patch, list[dict[str, Any]])
|
|
53
|
+
abstract_op: Mapping[str, str] = MappingProxyType({'op': 'remove', 'path': '/foo'})
|
|
54
|
+
JsonPatch(iter((abstract_op,)))
|
|
55
|
+
assert_type(PatchOperation(abstract_op).operation, dict[str, Any])
|
|
49
56
|
assert_type(JsonPatch.from_string('[]'), JsonPatch)
|
|
50
57
|
assert_type(JsonPatch.from_string(b'[]', loads=json.loads), JsonPatch)
|
|
51
58
|
assert_type(JsonPatch.from_string(bytearray(b'[]')), JsonPatch)
|
|
52
59
|
assert_type(JsonPatch.from_diff(doc, {}, optimization=False), JsonPatch)
|
|
53
60
|
assert_type(JsonPatch.operations['add'], type[PatchOperation])
|
|
61
|
+
assert_type(JsonPatch.operations, MappingProxyType[str, type[PatchOperation]])
|
|
54
62
|
|
|
55
63
|
|
|
56
64
|
class MyPatch(JsonPatch):
|
|
@@ -69,6 +77,7 @@ assert_type(operation.path, str)
|
|
|
69
77
|
assert_type(operation.key, int | str)
|
|
70
78
|
operation.key = 1
|
|
71
79
|
assert_type(operation.pointer, JsonPointer)
|
|
80
|
+
assert_type(operation.operation, dict[str, Any])
|
|
72
81
|
move = jsonpatch.MoveOperation({'op': 'move', 'from': '/a', 'path': '/b'})
|
|
73
82
|
assert_type(move.from_key, int | str)
|
|
74
83
|
|
|
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
|