jsonpatch 1.37__py3-none-any.whl → 1.39__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.
- {jsonpatch-1.37.dist-info → jsonpatch-1.39.dist-info}/METADATA +1 -1
- jsonpatch-1.39.dist-info/RECORD +9 -0
- jsonpatch.py +32 -24
- jsonpatch_cli.py +12 -0
- jsonpatch-1.37.dist-info/RECORD +0 -9
- {jsonpatch-1.37.dist-info → jsonpatch-1.39.dist-info}/WHEEL +0 -0
- {jsonpatch-1.37.dist-info → jsonpatch-1.39.dist-info}/entry_points.txt +0 -0
- {jsonpatch-1.37.dist-info → jsonpatch-1.39.dist-info}/licenses/AUTHORS +0 -0
- {jsonpatch-1.37.dist-info → jsonpatch-1.39.dist-info}/licenses/LICENSE +0 -0
- {jsonpatch-1.37.dist-info → jsonpatch-1.39.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
jsonpatch.py,sha256=JHVEKitWJsb_89w6zcg8B2Q4whNvJOLU2uKQEzW4ROQ,44263
|
|
2
|
+
jsonpatch_cli.py,sha256=IRfXFLpY4qF6QRGSZA227tIZo7ly_RXjImOrMvz8Lag,6043
|
|
3
|
+
jsonpatch-1.39.dist-info/licenses/AUTHORS,sha256=hOtEnBGbfDegKjzMDEl5vuVJyczbI2PlYE2ho4LjGNQ,140
|
|
4
|
+
jsonpatch-1.39.dist-info/licenses/LICENSE,sha256=Q5PrZzP6HjZ_QXabOC9PG-e_Da6x4kPtkrP12Lr9I28,1481
|
|
5
|
+
jsonpatch-1.39.dist-info/METADATA,sha256=UTTMETeu0ZinFeuu2bwHdtutUbDVW8MoEEGRRfFt62o,3672
|
|
6
|
+
jsonpatch-1.39.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
jsonpatch-1.39.dist-info/entry_points.txt,sha256=aY9ormBVRZHHDaAeMcdqTBwZ-ax7GvBTSQ33I75xtZM,98
|
|
8
|
+
jsonpatch-1.39.dist-info/top_level.txt,sha256=efUF341HUk8WcQKnFt8ZLKEKNrm1kFT76Flr38Fjno0,24
|
|
9
|
+
jsonpatch-1.39.dist-info/RECORD,,
|
jsonpatch.py
CHANGED
|
@@ -37,7 +37,8 @@ import collections
|
|
|
37
37
|
import copy
|
|
38
38
|
import functools
|
|
39
39
|
import json
|
|
40
|
-
from collections.abc import Mapping, MutableMapping, MutableSequence,
|
|
40
|
+
from collections.abc import (Mapping, MutableMapping, MutableSequence,
|
|
41
|
+
Sequence)
|
|
41
42
|
from difflib import SequenceMatcher
|
|
42
43
|
from types import MappingProxyType
|
|
43
44
|
|
|
@@ -54,7 +55,7 @@ _EXACT_MATCH_LIMIT = 500 ** 2
|
|
|
54
55
|
|
|
55
56
|
# Will be parsed by setup.py to determine package metadata
|
|
56
57
|
__author__ = 'Stefan Kögl <stefan@skoegl.net>'
|
|
57
|
-
__version__ = '1.
|
|
58
|
+
__version__ = '1.39'
|
|
58
59
|
__website__ = 'https://github.com/stefankoegl/python-json-patch'
|
|
59
60
|
__license__ = 'BSD-3-Clause'
|
|
60
61
|
|
|
@@ -100,13 +101,13 @@ _jsonloads = functools.partial(json.loads, object_pairs_hook=multidict)
|
|
|
100
101
|
|
|
101
102
|
|
|
102
103
|
def apply_patch(doc, patch, in_place=False, pointer_cls=JsonPointer):
|
|
103
|
-
"""Apply
|
|
104
|
+
"""Apply patch operations to the specified JSON document.
|
|
104
105
|
|
|
105
|
-
:param doc:
|
|
106
|
-
:type doc:
|
|
106
|
+
:param doc: JSON document, including arrays and scalar values.
|
|
107
|
+
:type doc: object
|
|
107
108
|
|
|
108
|
-
:param patch:
|
|
109
|
-
:type patch:
|
|
109
|
+
:param patch: Iterable of operation dicts or a raw JSON-encoded string.
|
|
110
|
+
:type patch: iterable or str
|
|
110
111
|
|
|
111
112
|
:param in_place: While ``True`` patch will modify target document.
|
|
112
113
|
By default patch will be applied to document copy.
|
|
@@ -115,8 +116,8 @@ def apply_patch(doc, patch, in_place=False, pointer_cls=JsonPointer):
|
|
|
115
116
|
:param pointer_cls: JSON pointer class to use.
|
|
116
117
|
:type pointer_cls: Type[JsonPointer]
|
|
117
118
|
|
|
118
|
-
:return:
|
|
119
|
-
:rtype:
|
|
119
|
+
:return: Resulting document, which may have a different type from ``doc``.
|
|
120
|
+
:rtype: object
|
|
120
121
|
|
|
121
122
|
>>> doc = {'foo': 'bar'}
|
|
122
123
|
>>> patch = [{'op': 'add', 'path': '/baz', 'value': 'qux'}]
|
|
@@ -145,11 +146,11 @@ def make_patch(src, dst, pointer_cls=JsonPointer):
|
|
|
145
146
|
transforms `src` into `dst`, so it has to be applied to `src` (or to a
|
|
146
147
|
document equal to it).
|
|
147
148
|
|
|
148
|
-
:param src:
|
|
149
|
-
:type src:
|
|
149
|
+
:param src: Source JSON document, including arrays and scalar values.
|
|
150
|
+
:type src: object
|
|
150
151
|
|
|
151
|
-
:param dst:
|
|
152
|
-
:type dst:
|
|
152
|
+
:param dst: Target JSON document, including arrays and scalar values.
|
|
153
|
+
:type dst: object
|
|
153
154
|
|
|
154
155
|
:param pointer_cls: JSON pointer class to use.
|
|
155
156
|
:type pointer_cls: Type[JsonPointer]
|
|
@@ -262,6 +263,8 @@ class RemoveOperation(PatchOperation):
|
|
|
262
263
|
except (KeyError, IndexError):
|
|
263
264
|
msg = "can't remove a non-existent object '{0}'".format(part)
|
|
264
265
|
raise JsonPatchConflict(msg)
|
|
266
|
+
except TypeError as ex:
|
|
267
|
+
raise JsonPatchConflict(str(ex))
|
|
265
268
|
|
|
266
269
|
return obj
|
|
267
270
|
|
|
@@ -457,7 +460,11 @@ class CopyOperation(PatchOperation):
|
|
|
457
460
|
|
|
458
461
|
|
|
459
462
|
class JsonPatch(object):
|
|
460
|
-
"""A JSON Patch is
|
|
463
|
+
"""A JSON Patch is an iterable of Patch Operations.
|
|
464
|
+
|
|
465
|
+
Accepts sequences, iterators, generators, and other iterables of operation
|
|
466
|
+
dictionaries. Non-sequence inputs are materialized before validation so
|
|
467
|
+
the resulting patch can be applied repeatedly.
|
|
461
468
|
|
|
462
469
|
>>> patch = JsonPatch([
|
|
463
470
|
... {'op': 'add', 'path': '/foo', 'value': 'bar'},
|
|
@@ -515,13 +522,12 @@ class JsonPatch(object):
|
|
|
515
522
|
})
|
|
516
523
|
|
|
517
524
|
def __init__(self, patch, pointer_cls=JsonPointer):
|
|
518
|
-
self.patch = patch
|
|
519
525
|
self.pointer_cls = pointer_cls
|
|
520
526
|
|
|
521
527
|
if isinstance(patch, (str, bytes, Mapping)):
|
|
522
528
|
raise InvalidJsonPatch("Document is expected to be sequence of operations")
|
|
523
529
|
try:
|
|
524
|
-
|
|
530
|
+
self.patch = patch if isinstance(patch, Sequence) else list(patch)
|
|
525
531
|
except TypeError:
|
|
526
532
|
raise InvalidJsonPatch("Document is expected to be sequence of operations")
|
|
527
533
|
|
|
@@ -529,7 +535,7 @@ class JsonPatch(object):
|
|
|
529
535
|
# is correct by retrieving each patch element.
|
|
530
536
|
# Much of the validation is done in the initializer
|
|
531
537
|
# though some is delayed until the patch is applied.
|
|
532
|
-
for op in
|
|
538
|
+
for op in self.patch:
|
|
533
539
|
# We're only checking for strings in the following check
|
|
534
540
|
# for two reasons:
|
|
535
541
|
#
|
|
@@ -598,11 +604,11 @@ class JsonPatch(object):
|
|
|
598
604
|
one. The resulting patch transforms `src` into `dst`, so it has to be
|
|
599
605
|
applied to `src` (or to a document equal to it).
|
|
600
606
|
|
|
601
|
-
:param src:
|
|
602
|
-
:type src:
|
|
607
|
+
:param src: Source JSON document, including arrays and scalar values.
|
|
608
|
+
:type src: object
|
|
603
609
|
|
|
604
|
-
:param dst:
|
|
605
|
-
:type dst:
|
|
610
|
+
:param dst: Target JSON document, including arrays and scalar values.
|
|
611
|
+
:type dst: object
|
|
606
612
|
|
|
607
613
|
:param optimization: Generate move operations for matching values.
|
|
608
614
|
Set to False to use only add, remove and replace.
|
|
@@ -643,14 +649,16 @@ class JsonPatch(object):
|
|
|
643
649
|
def apply(self, obj, in_place=False):
|
|
644
650
|
"""Applies the patch to a given object.
|
|
645
651
|
|
|
646
|
-
:param obj:
|
|
647
|
-
:type obj:
|
|
652
|
+
:param obj: JSON document, including arrays and scalar values.
|
|
653
|
+
:type obj: object
|
|
648
654
|
|
|
649
655
|
:param in_place: Tweaks the way how patch would be applied - directly to
|
|
650
656
|
specified `obj` or to its copy.
|
|
651
657
|
:type in_place: bool
|
|
652
658
|
|
|
653
|
-
:return:
|
|
659
|
+
:return: Resulting document. Use this return value even with
|
|
660
|
+
``in_place=True``, because a root replacement returns a new
|
|
661
|
+
value rather than modifying the original container.
|
|
654
662
|
"""
|
|
655
663
|
|
|
656
664
|
if not in_place:
|
jsonpatch_cli.py
CHANGED
|
@@ -78,6 +78,7 @@ def patch_files():
|
|
|
78
78
|
args.ORIGINAL.close()
|
|
79
79
|
dirname = os.path.abspath(os.path.dirname(args.ORIGINAL.name))
|
|
80
80
|
|
|
81
|
+
fd = None
|
|
81
82
|
try:
|
|
82
83
|
# Attempt to replace the file atomically. We do this by
|
|
83
84
|
# creating a temporary file in the same directory as the
|
|
@@ -90,6 +91,17 @@ def patch_files():
|
|
|
90
91
|
atomic = True
|
|
91
92
|
|
|
92
93
|
except OSError:
|
|
94
|
+
# mkstemp may have succeeded before fdopen failed. Neither the
|
|
95
|
+
# descriptor nor the temporary file belongs to the fallback.
|
|
96
|
+
if fd is not None:
|
|
97
|
+
try:
|
|
98
|
+
os.close(fd)
|
|
99
|
+
except OSError:
|
|
100
|
+
pass
|
|
101
|
+
try:
|
|
102
|
+
os.unlink(pathname)
|
|
103
|
+
except OSError:
|
|
104
|
+
pass
|
|
93
105
|
# We failed to create the temporary file for an atomic
|
|
94
106
|
# replace, so fall back to non-atomic mode by backing up
|
|
95
107
|
# the original (if desired) and writing a new file.
|
jsonpatch-1.37.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
jsonpatch.py,sha256=6fX9MEBkMv4cIyw_iVt5b2VkDXMSG73MjDTgp4FMhRg,43496
|
|
2
|
-
jsonpatch_cli.py,sha256=Gi1DOHBOYcny9Fedd7893r1XdLn6Sq-Rycgncn1hObo,5617
|
|
3
|
-
jsonpatch-1.37.dist-info/licenses/AUTHORS,sha256=hOtEnBGbfDegKjzMDEl5vuVJyczbI2PlYE2ho4LjGNQ,140
|
|
4
|
-
jsonpatch-1.37.dist-info/licenses/LICENSE,sha256=Q5PrZzP6HjZ_QXabOC9PG-e_Da6x4kPtkrP12Lr9I28,1481
|
|
5
|
-
jsonpatch-1.37.dist-info/METADATA,sha256=oaKNZAeNG-Z59oQ07lI2ne1vvUJ8uo8iZEj4XDyeT9Q,3672
|
|
6
|
-
jsonpatch-1.37.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
-
jsonpatch-1.37.dist-info/entry_points.txt,sha256=aY9ormBVRZHHDaAeMcdqTBwZ-ax7GvBTSQ33I75xtZM,98
|
|
8
|
-
jsonpatch-1.37.dist-info/top_level.txt,sha256=efUF341HUk8WcQKnFt8ZLKEKNrm1kFT76Flr38Fjno0,24
|
|
9
|
-
jsonpatch-1.37.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|