jsonpatch 1.45__py3-none-any.whl → 1.47__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.45.dist-info → jsonpatch-1.47.dist-info}/METADATA +17 -12
- jsonpatch-1.47.dist-info/RECORD +9 -0
- jsonpatch-stubs/__init__.pyi +0 -3
- jsonpatch.py +38 -46
- jsonpatch_cli.py +26 -19
- jsonpatch-1.45.dist-info/RECORD +0 -10
- jsonpatch-1.45.dist-info/licenses/AUTHORS +0 -4
- {jsonpatch-1.45.dist-info → jsonpatch-1.47.dist-info}/WHEEL +0 -0
- {jsonpatch-1.45.dist-info → jsonpatch-1.47.dist-info}/entry_points.txt +0 -0
- {jsonpatch-1.45.dist-info → jsonpatch-1.47.dist-info}/licenses/LICENSE +0 -0
- {jsonpatch-1.45.dist-info → jsonpatch-1.47.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jsonpatch
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.47
|
|
4
4
|
Summary: Apply JSON-Patches (RFC 6902)
|
|
5
5
|
Home-page: https://github.com/stefankoegl/python-json-patch
|
|
6
6
|
Author: Stefan Kögl
|
|
@@ -8,7 +8,7 @@ Author-email: stefan@skoegl.net
|
|
|
8
8
|
License-Expression: BSD-3-Clause
|
|
9
9
|
Project-URL: Website, https://github.com/stefankoegl/python-json-patch
|
|
10
10
|
Project-URL: Repository, https://github.com/stefankoegl/python-json-patch.git
|
|
11
|
-
Project-URL: Documentation, https://python-json-patch.readthedocs.
|
|
11
|
+
Project-URL: Documentation, https://python-json-patch.readthedocs.io/
|
|
12
12
|
Project-URL: PyPI, https://pypi.org/pypi/jsonpatch
|
|
13
13
|
Project-URL: Tests, https://github.com/stefankoegl/python-json-patch/actions
|
|
14
14
|
Project-URL: Test Coverage, https://coveralls.io/github/stefankoegl/python-json-patch
|
|
@@ -19,20 +19,19 @@ Classifier: Operating System :: OS Independent
|
|
|
19
19
|
Classifier: Programming Language :: Python
|
|
20
20
|
Classifier: Programming Language :: Python :: 3
|
|
21
21
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
24
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
25
24
|
Classifier: Programming Language :: Python :: 3.13
|
|
26
25
|
Classifier: Programming Language :: Python :: 3.14
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
27
27
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
28
28
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
29
29
|
Classifier: Topic :: Software Development :: Libraries
|
|
30
30
|
Classifier: Topic :: Utilities
|
|
31
31
|
Classifier: Typing :: Typed
|
|
32
|
-
Requires-Python: >=3.
|
|
32
|
+
Requires-Python: >=3.11
|
|
33
33
|
Description-Content-Type: text/markdown
|
|
34
34
|
License-File: LICENSE
|
|
35
|
-
License-File: AUTHORS
|
|
36
35
|
Requires-Dist: jsonpointer>=3.8
|
|
37
36
|
Dynamic: author
|
|
38
37
|
Dynamic: author-email
|
|
@@ -50,8 +49,8 @@ Dynamic: summary
|
|
|
50
49
|
python-json-patch
|
|
51
50
|
=================
|
|
52
51
|
|
|
53
|
-
[](https://pypi.org/project/jsonpatch
|
|
54
|
-
[](https://pypi.org/project/jsonpatch
|
|
52
|
+
[](https://pypi.org/project/jsonpatch/)
|
|
53
|
+
[](https://pypi.org/project/jsonpatch/)
|
|
55
54
|
[](https://github.com/stefankoegl/python-json-patch/actions/workflows/test.yaml)
|
|
56
55
|
[](https://coveralls.io/github/stefankoegl/python-json-patch?branch=master)
|
|
57
56
|
|
|
@@ -61,11 +60,12 @@ Applying JSON Patches in Python
|
|
|
61
60
|
Library to apply JSON Patches according to
|
|
62
61
|
[RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902)
|
|
63
62
|
|
|
64
|
-
See
|
|
63
|
+
See the [tutorial](https://python-json-patch.readthedocs.io/en/latest/tutorial.html)
|
|
64
|
+
for examples.
|
|
65
65
|
|
|
66
66
|
* Website: https://github.com/stefankoegl/python-json-patch
|
|
67
67
|
* Repository: https://github.com/stefankoegl/python-json-patch.git
|
|
68
|
-
* Documentation: https://python-json-patch.readthedocs.
|
|
68
|
+
* Documentation: https://python-json-patch.readthedocs.io/
|
|
69
69
|
* PyPI: https://pypi.org/project/jsonpatch/
|
|
70
70
|
* CI: https://github.com/stefankoegl/python-json-patch/actions
|
|
71
71
|
* Coveralls: https://coveralls.io/github/stefankoegl/python-json-patch
|
|
@@ -77,7 +77,8 @@ non-RFC string `append` operation. Its `from_diff()` method sends only the
|
|
|
77
77
|
new suffix when an object member's string grows. `JsonPatch`, `make_patch()`
|
|
78
78
|
and `apply_patch()` retain their standard RFC 6902 behavior.
|
|
79
79
|
|
|
80
|
-
See the [tutorial](
|
|
80
|
+
See the [tutorial](https://python-json-patch.readthedocs.io/en/latest/tutorial.html#string-append-extension)
|
|
81
|
+
for examples.
|
|
81
82
|
Both sender and receiver must support the extension.
|
|
82
83
|
|
|
83
84
|
Type hints
|
|
@@ -94,6 +95,11 @@ typical usage in `typetests/usage.py` type-checks:
|
|
|
94
95
|
python -m mypy.stubtest --mypy-config-file pyproject.toml jsonpatch
|
|
95
96
|
cd typetests && mypy --config-file ../pyproject.toml usage.py
|
|
96
97
|
|
|
98
|
+
Running tests
|
|
99
|
+
-------------
|
|
100
|
+
pip install -r requirements.txt -r requirements-dev.txt
|
|
101
|
+
python tests.py
|
|
102
|
+
|
|
97
103
|
Running external tests
|
|
98
104
|
----------------------
|
|
99
105
|
To run external tests (such as those from https://github.com/json-patch/json-patch-tests) use ext_tests.py
|
|
@@ -103,8 +109,7 @@ To run external tests (such as those from https://github.com/json-patch/json-pat
|
|
|
103
109
|
Running property-based tests
|
|
104
110
|
----------------------------
|
|
105
111
|
Property-based tests using [Hypothesis](https://hypothesis.readthedocs.io/)
|
|
106
|
-
are in property_tests.py.
|
|
107
|
-
yet are marked as expected failures.
|
|
112
|
+
are in property_tests.py.
|
|
108
113
|
|
|
109
114
|
pip install hypothesis
|
|
110
115
|
python property_tests.py
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
jsonpatch.py,sha256=gRxBHP7TRKWjgTY8AMM3wqjFoTkFP7ef8aYx4OEX3yY,67287
|
|
2
|
+
jsonpatch_cli.py,sha256=q_72_UMrOxKptom2038w0FM3zSMeA1ikY9vqFhVavdU,6707
|
|
3
|
+
jsonpatch-1.47.dist-info/licenses/LICENSE,sha256=Q5PrZzP6HjZ_QXabOC9PG-e_Da6x4kPtkrP12Lr9I28,1481
|
|
4
|
+
jsonpatch-stubs/__init__.pyi,sha256=Bg2Z-QYkBV2nFsw410s5GcQxI-GV4Jb00eYHBP7ciFw,5498
|
|
5
|
+
jsonpatch-1.47.dist-info/METADATA,sha256=71D2bBUEJgpkqUkk74oPf4R5q191GaGsqq0dXkHs1P0,4860
|
|
6
|
+
jsonpatch-1.47.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
jsonpatch-1.47.dist-info/entry_points.txt,sha256=aY9ormBVRZHHDaAeMcdqTBwZ-ax7GvBTSQ33I75xtZM,98
|
|
8
|
+
jsonpatch-1.47.dist-info/top_level.txt,sha256=AGmziZtf5TSFAtbhYlhDGjQg1POmwzF9HwLdbzPkoio,40
|
|
9
|
+
jsonpatch-1.47.dist-info/RECORD,,
|
jsonpatch-stubs/__init__.pyi
CHANGED
|
@@ -65,7 +65,6 @@ class PatchOperation:
|
|
|
65
65
|
def apply(self, obj: Any) -> Any: ...
|
|
66
66
|
def __hash__(self) -> int: ...
|
|
67
67
|
def __eq__(self, other: object) -> bool: ...
|
|
68
|
-
def __ne__(self, other: object) -> bool: ...
|
|
69
68
|
@property
|
|
70
69
|
def path(self) -> str: ...
|
|
71
70
|
@property
|
|
@@ -104,8 +103,6 @@ class JsonPatch:
|
|
|
104
103
|
def __iter__(self) -> Iterator[dict[str, Any]]: ...
|
|
105
104
|
def __hash__(self) -> int: ...
|
|
106
105
|
def __eq__(self, other: object) -> bool: ...
|
|
107
|
-
def __ne__(self, other: object) -> bool: ...
|
|
108
|
-
__nonzero__ = __bool__
|
|
109
106
|
@classmethod
|
|
110
107
|
def from_string(
|
|
111
108
|
cls,
|
jsonpatch.py
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
#
|
|
3
1
|
# python-json-patch - An implementation of the JSON Patch format
|
|
4
2
|
# https://github.com/stefankoegl/python-json-patch
|
|
5
3
|
#
|
|
6
4
|
# Copyright (c) 2011 Stefan Kögl <stefan@skoegl.net>
|
|
7
|
-
# All rights reserved.
|
|
8
5
|
#
|
|
9
6
|
# Redistribution and use in source and binary forms, with or without
|
|
10
|
-
# modification, are permitted provided that the following conditions
|
|
11
|
-
#
|
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
|
8
|
+
#
|
|
9
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
10
|
+
# this list of conditions and the following disclaimer.
|
|
11
|
+
#
|
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
# and/or other materials provided with the distribution.
|
|
12
15
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
# notice, this list of conditions and the following disclaimer in the
|
|
17
|
-
# documentation and/or other materials provided with the distribution.
|
|
18
|
-
# 3. The name of the author may not be used to endorse or promote products
|
|
19
|
-
# derived from this software without specific prior written permission.
|
|
16
|
+
# 3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
# contributors may be used to endorse or promote products derived from this
|
|
18
|
+
# software without specific prior written permission.
|
|
20
19
|
#
|
|
21
|
-
# THIS SOFTWARE IS PROVIDED BY THE
|
|
22
|
-
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
-
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
24
|
-
# IN NO EVENT SHALL THE
|
|
25
|
-
# INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
26
|
-
# NOT LIMITED TO, PROCUREMENT OF
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
# (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
30
|
-
# THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
31
31
|
#
|
|
32
32
|
|
|
33
33
|
""" Apply JSON-Patches (RFC 6902) """
|
|
@@ -59,7 +59,7 @@ _JSONPOINTER_FROM_PARTS = JsonPointer.from_parts.__func__
|
|
|
59
59
|
|
|
60
60
|
# Will be parsed by setup.py to determine package metadata
|
|
61
61
|
__author__ = 'Stefan Kögl <stefan@skoegl.net>'
|
|
62
|
-
__version__ = '1.
|
|
62
|
+
__version__ = '1.47'
|
|
63
63
|
__website__ = 'https://github.com/stefankoegl/python-json-patch'
|
|
64
64
|
__license__ = 'BSD-3-Clause'
|
|
65
65
|
|
|
@@ -78,7 +78,7 @@ class JsonPatchException(Exception):
|
|
|
78
78
|
:type op: PatchOperation or dict or None
|
|
79
79
|
"""
|
|
80
80
|
self.op = kwargs.pop('op', None)
|
|
81
|
-
super(
|
|
81
|
+
super().__init__(*args, **kwargs)
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
class InvalidJsonPatch(JsonPatchException):
|
|
@@ -294,7 +294,7 @@ def path_join(parts, pointer_cls=JsonPointer):
|
|
|
294
294
|
return from_parts(parts).path
|
|
295
295
|
|
|
296
296
|
|
|
297
|
-
class _NullJournal
|
|
297
|
+
class _NullJournal:
|
|
298
298
|
"""Performs the changes of patch operations without recording them."""
|
|
299
299
|
|
|
300
300
|
@staticmethod
|
|
@@ -317,7 +317,7 @@ class _NullJournal(object):
|
|
|
317
317
|
_NO_JOURNAL = _NullJournal()
|
|
318
318
|
|
|
319
319
|
|
|
320
|
-
class _Journal
|
|
320
|
+
class _Journal:
|
|
321
321
|
"""Performs the changes of patch operations and records how to undo them.
|
|
322
322
|
|
|
323
323
|
Each undo step refers to the changed container itself rather than to a
|
|
@@ -437,7 +437,7 @@ def _reorder(mapping, keys):
|
|
|
437
437
|
mapping[key] = mapping.pop(key)
|
|
438
438
|
|
|
439
439
|
|
|
440
|
-
class PatchOperation
|
|
440
|
+
class PatchOperation:
|
|
441
441
|
"""A single operation inside a JSON Patch."""
|
|
442
442
|
|
|
443
443
|
def __init__(self, operation, pointer_cls=JsonPointer):
|
|
@@ -499,9 +499,6 @@ class PatchOperation(object):
|
|
|
499
499
|
# e.g. tests for 1 and for true behave differently
|
|
500
500
|
return _json_equal(self.operation, other.operation)
|
|
501
501
|
|
|
502
|
-
def __ne__(self, other):
|
|
503
|
-
return not(self == other)
|
|
504
|
-
|
|
505
502
|
@property
|
|
506
503
|
def path(self):
|
|
507
504
|
"""The location of the object or array that contains the target of
|
|
@@ -625,7 +622,7 @@ class ReplaceOperation(PatchOperation):
|
|
|
625
622
|
raise InvalidJsonPatch(
|
|
626
623
|
"The operation does not contain a 'value' member", op=self)
|
|
627
624
|
|
|
628
|
-
# copied for the same reason as in AddOperation.
|
|
625
|
+
# copied for the same reason as in AddOperation._apply
|
|
629
626
|
value = copy.deepcopy(value)
|
|
630
627
|
|
|
631
628
|
subobj, part = self.pointer.to_last(obj)
|
|
@@ -871,7 +868,7 @@ def _supports_journal(operation):
|
|
|
871
868
|
return True
|
|
872
869
|
|
|
873
870
|
|
|
874
|
-
class JsonPatch
|
|
871
|
+
class JsonPatch:
|
|
875
872
|
"""A JSON Patch is an iterable of Patch Operations.
|
|
876
873
|
|
|
877
874
|
Accepts sequences, iterators, generators, and other iterables of operation
|
|
@@ -975,8 +972,6 @@ class JsonPatch(object):
|
|
|
975
972
|
def __bool__(self):
|
|
976
973
|
return bool(self.patch)
|
|
977
974
|
|
|
978
|
-
__nonzero__ = __bool__
|
|
979
|
-
|
|
980
975
|
def __iter__(self):
|
|
981
976
|
return iter(self.patch)
|
|
982
977
|
|
|
@@ -988,9 +983,6 @@ class JsonPatch(object):
|
|
|
988
983
|
return False
|
|
989
984
|
return self._ops == other._ops
|
|
990
985
|
|
|
991
|
-
def __ne__(self, other):
|
|
992
|
-
return not(self == other)
|
|
993
|
-
|
|
994
986
|
@classmethod
|
|
995
987
|
def from_string(cls, patch_str, loads=None, pointer_cls=JsonPointer):
|
|
996
988
|
"""Creates JsonPatch instance from string source.
|
|
@@ -1187,7 +1179,7 @@ class JsonPatchWithAppend(JsonPatch):
|
|
|
1187
1179
|
return cls(ops, pointer_cls=pointer_cls)
|
|
1188
1180
|
|
|
1189
1181
|
|
|
1190
|
-
class DiffBuilder
|
|
1182
|
+
class DiffBuilder:
|
|
1191
1183
|
|
|
1192
1184
|
def __init__(self, src_doc, dst_doc, dumps=json.dumps, pointer_cls=JsonPointer,
|
|
1193
1185
|
optimization=True, generate_test_ops=False):
|
|
@@ -1395,9 +1387,9 @@ class DiffBuilder(object):
|
|
|
1395
1387
|
""" Inserts a test operation that checks the value at location, if
|
|
1396
1388
|
test operations are generated """
|
|
1397
1389
|
if self.generate_test_ops:
|
|
1398
|
-
#
|
|
1390
|
+
# like all values, it is copied when the patch is created
|
|
1399
1391
|
return self.insert({'op': 'test', 'path': location,
|
|
1400
|
-
'value':
|
|
1392
|
+
'value': value})
|
|
1401
1393
|
|
|
1402
1394
|
def _item_replaced(self, path, key, item, old_item):
|
|
1403
1395
|
location = self._location(_path_join(path, key))
|
|
@@ -1577,13 +1569,13 @@ def _json_equal(first, second):
|
|
|
1577
1569
|
if isinstance(first, bool) or isinstance(second, bool):
|
|
1578
1570
|
return isinstance(first, bool) and isinstance(second, bool) and \
|
|
1579
1571
|
first == second
|
|
1580
|
-
if isinstance(first,
|
|
1581
|
-
isinstance(second, MutableMapping):
|
|
1572
|
+
if isinstance(first, Mapping) and isinstance(second, Mapping):
|
|
1582
1573
|
return len(first) == len(second) and all(
|
|
1583
1574
|
key in second and _json_equal(first[key], second[key])
|
|
1584
1575
|
for key in first)
|
|
1585
|
-
if isinstance(first,
|
|
1586
|
-
isinstance(
|
|
1576
|
+
if isinstance(first, Sequence) and isinstance(second, Sequence) and \
|
|
1577
|
+
not isinstance(first, (str, bytes)) and \
|
|
1578
|
+
not isinstance(second, (str, bytes)):
|
|
1587
1579
|
return len(first) == len(second) and all(
|
|
1588
1580
|
_json_equal(*items) for items in zip(first, second))
|
|
1589
1581
|
return first == second
|
|
@@ -1609,7 +1601,7 @@ def _sorted_members(value):
|
|
|
1609
1601
|
# change, but their locations do not.
|
|
1610
1602
|
|
|
1611
1603
|
|
|
1612
|
-
class _ArrayItem
|
|
1604
|
+
class _ArrayItem:
|
|
1613
1605
|
""" An item that an array has at some point of the diff """
|
|
1614
1606
|
|
|
1615
1607
|
__slots__ = ('array', 'label', 'initial')
|
|
@@ -1626,7 +1618,7 @@ class _ArrayItem(object):
|
|
|
1626
1618
|
return bisect.bisect_left(self.array.present_labels, self.label)
|
|
1627
1619
|
|
|
1628
1620
|
|
|
1629
|
-
class _ArrayItems
|
|
1621
|
+
class _ArrayItems:
|
|
1630
1622
|
""" All items that an array has at some point of the diff, and the items
|
|
1631
1623
|
that it has at the moment, both ordered by their labels.
|
|
1632
1624
|
|
jsonpatch_cli.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
1
|
""" The jsondiff and jsonpatch command line programs """
|
|
4
2
|
|
|
5
3
|
import sys
|
|
@@ -13,8 +11,8 @@ from contextlib import ExitStack
|
|
|
13
11
|
|
|
14
12
|
jsondiff_parser = argparse.ArgumentParser(
|
|
15
13
|
prog='jsondiff', description='Diff two JSON files')
|
|
16
|
-
jsondiff_parser.add_argument('FILE1', type=argparse.FileType('r', encoding='utf-8'))
|
|
17
|
-
jsondiff_parser.add_argument('FILE2', type=argparse.FileType('r', encoding='utf-8'))
|
|
14
|
+
jsondiff_parser.add_argument('FILE1', type=argparse.FileType('r', encoding='utf-8-sig'))
|
|
15
|
+
jsondiff_parser.add_argument('FILE2', type=argparse.FileType('r', encoding='utf-8-sig'))
|
|
18
16
|
jsondiff_parser.add_argument('--indent', type=int, default=None,
|
|
19
17
|
help='Indent output by n spaces')
|
|
20
18
|
jsondiff_parser.add_argument('-u', '--preserve-unicode', action='store_true',
|
|
@@ -26,6 +24,16 @@ jsondiff_parser.add_argument('-v', '--version', action='version',
|
|
|
26
24
|
version='%(prog)s ' + jsonpatch.__version__)
|
|
27
25
|
|
|
28
26
|
|
|
27
|
+
def _input_files(*streams):
|
|
28
|
+
""" Closes the input files when the returned context is left; stdin is
|
|
29
|
+
left open, as it is not ours """
|
|
30
|
+
inputs = ExitStack()
|
|
31
|
+
for stream in streams:
|
|
32
|
+
if stream is not sys.stdin:
|
|
33
|
+
inputs.enter_context(stream)
|
|
34
|
+
return inputs
|
|
35
|
+
|
|
36
|
+
|
|
29
37
|
def jsondiff_main():
|
|
30
38
|
try:
|
|
31
39
|
diff_files()
|
|
@@ -36,24 +44,21 @@ def jsondiff_main():
|
|
|
36
44
|
def diff_files():
|
|
37
45
|
""" Diffs two JSON files and prints a patch """
|
|
38
46
|
args = jsondiff_parser.parse_args()
|
|
39
|
-
with
|
|
40
|
-
for stream in (args.FILE1, args.FILE2):
|
|
41
|
-
if stream is not sys.stdin:
|
|
42
|
-
inputs.enter_context(stream)
|
|
47
|
+
with _input_files(args.FILE1, args.FILE2):
|
|
43
48
|
doc1 = json.load(args.FILE1)
|
|
44
49
|
doc2 = json.load(args.FILE2)
|
|
45
50
|
patch = jsonpatch.make_patch(doc1, doc2, generate_test_ops=args.test_ops)
|
|
46
51
|
if patch.patch:
|
|
47
|
-
print(json.dumps(patch.patch, indent=args.indent, ensure_ascii=not
|
|
52
|
+
print(json.dumps(patch.patch, indent=args.indent, ensure_ascii=not args.preserve_unicode))
|
|
48
53
|
sys.exit(1)
|
|
49
54
|
|
|
50
55
|
|
|
51
56
|
jsonpatch_parser = argparse.ArgumentParser(
|
|
52
57
|
prog='jsonpatch',
|
|
53
58
|
description='Apply a JSON patch on a JSON file')
|
|
54
|
-
jsonpatch_parser.add_argument('ORIGINAL', type=argparse.FileType('r', encoding='utf-8'),
|
|
59
|
+
jsonpatch_parser.add_argument('ORIGINAL', type=argparse.FileType('r', encoding='utf-8-sig'),
|
|
55
60
|
help='Original file')
|
|
56
|
-
jsonpatch_parser.add_argument('PATCH', type=argparse.FileType('r', encoding='utf-8'),
|
|
61
|
+
jsonpatch_parser.add_argument('PATCH', type=argparse.FileType('r', encoding='utf-8-sig'),
|
|
57
62
|
nargs='?', default=sys.stdin,
|
|
58
63
|
help='Patch file (read from stdin if omitted)')
|
|
59
64
|
jsonpatch_parser.add_argument('--indent', type=int, default=None,
|
|
@@ -67,6 +72,7 @@ jsonpatch_parser.add_argument('-v', '--version', action='version',
|
|
|
67
72
|
jsonpatch_parser.add_argument('-u', '--preserve-unicode', action='store_true',
|
|
68
73
|
help='Output Unicode character as-is without using Code Point')
|
|
69
74
|
|
|
75
|
+
|
|
70
76
|
def jsonpatch_main():
|
|
71
77
|
try:
|
|
72
78
|
patch_files()
|
|
@@ -77,12 +83,13 @@ def jsonpatch_main():
|
|
|
77
83
|
def patch_files():
|
|
78
84
|
""" Applies a JSON patch on a JSON file """
|
|
79
85
|
args = jsonpatch_parser.parse_args()
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
# The inputs are closed before anything is written, as Windows cannot
|
|
87
|
+
# replace ORIGINAL while it is open.
|
|
88
|
+
with _input_files(args.ORIGINAL, args.PATCH):
|
|
89
|
+
doc = json.load(args.ORIGINAL)
|
|
90
|
+
result = jsonpatch.apply_patch(doc, args.PATCH.read())
|
|
82
91
|
|
|
83
92
|
if args.in_place:
|
|
84
|
-
# 2026-10-11: Release the input handle before replacing it on Windows.
|
|
85
|
-
args.ORIGINAL.close()
|
|
86
93
|
dirname = os.path.abspath(os.path.dirname(args.ORIGINAL.name))
|
|
87
94
|
|
|
88
95
|
fd = None
|
|
@@ -91,7 +98,7 @@ def patch_files():
|
|
|
91
98
|
# creating a temporary file in the same directory as the
|
|
92
99
|
# original file so we can atomically move the new file over
|
|
93
100
|
# the original later. (This is done in the same directory
|
|
94
|
-
|
|
101
|
+
# because atomic renames do not work across mount points.)
|
|
95
102
|
|
|
96
103
|
fd, pathname = tempfile.mkstemp(dir=dirname)
|
|
97
104
|
fp = os.fdopen(fd, 'w', encoding='utf-8')
|
|
@@ -124,11 +131,11 @@ def patch_files():
|
|
|
124
131
|
|
|
125
132
|
fp = sys.stdout
|
|
126
133
|
|
|
127
|
-
# By this point we have some sort of file object we can write the
|
|
134
|
+
# By this point we have some sort of file object we can write the
|
|
128
135
|
# modified JSON to.
|
|
129
|
-
|
|
136
|
+
|
|
130
137
|
try:
|
|
131
|
-
json.dump(result, fp, indent=args.indent, ensure_ascii=not
|
|
138
|
+
json.dump(result, fp, indent=args.indent, ensure_ascii=not args.preserve_unicode)
|
|
132
139
|
fp.write('\n')
|
|
133
140
|
if args.in_place:
|
|
134
141
|
fp.close()
|
jsonpatch-1.45.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
jsonpatch.py,sha256=5Vs9OIFV2aioCf4LuMX4CfltVoYwhQAHJGp7u6DtNW0,67433
|
|
2
|
-
jsonpatch_cli.py,sha256=Vavn3OY4KrowXNTRDbgsNPcd9vTGLkIgz0Hr6Uwr5mk,6480
|
|
3
|
-
jsonpatch-1.45.dist-info/licenses/AUTHORS,sha256=hOtEnBGbfDegKjzMDEl5vuVJyczbI2PlYE2ho4LjGNQ,140
|
|
4
|
-
jsonpatch-1.45.dist-info/licenses/LICENSE,sha256=Q5PrZzP6HjZ_QXabOC9PG-e_Da6x4kPtkrP12Lr9I28,1481
|
|
5
|
-
jsonpatch-stubs/__init__.pyi,sha256=ARV0JxPJ3TZbYk1hUbayPO3gJVP0geIQK6fftWM-4KY,5623
|
|
6
|
-
jsonpatch-1.45.dist-info/METADATA,sha256=255V0zWc9-62CxfdBebjRFLt0pal9KGRqBnC5vPnUPY,4748
|
|
7
|
-
jsonpatch-1.45.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
8
|
-
jsonpatch-1.45.dist-info/entry_points.txt,sha256=aY9ormBVRZHHDaAeMcdqTBwZ-ax7GvBTSQ33I75xtZM,98
|
|
9
|
-
jsonpatch-1.45.dist-info/top_level.txt,sha256=AGmziZtf5TSFAtbhYlhDGjQg1POmwzF9HwLdbzPkoio,40
|
|
10
|
-
jsonpatch-1.45.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|