jsonpointer 3.4__tar.gz → 3.5__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.
- {jsonpointer-3.4/jsonpointer.egg-info → jsonpointer-3.5}/PKG-INFO +1 -1
- {jsonpointer-3.4 → jsonpointer-3.5}/bin/jsonpointer +5 -2
- {jsonpointer-3.4 → jsonpointer-3.5/jsonpointer.egg-info}/PKG-INFO +1 -1
- {jsonpointer-3.4 → jsonpointer-3.5}/jsonpointer.py +1 -1
- {jsonpointer-3.4 → jsonpointer-3.5}/tests.py +53 -3
- {jsonpointer-3.4 → jsonpointer-3.5}/AUTHORS +0 -0
- {jsonpointer-3.4 → jsonpointer-3.5}/LICENSE.txt +0 -0
- {jsonpointer-3.4 → jsonpointer-3.5}/MANIFEST.in +0 -0
- {jsonpointer-3.4 → jsonpointer-3.5}/README.md +0 -0
- {jsonpointer-3.4 → jsonpointer-3.5}/jsonpointer.egg-info/SOURCES.txt +0 -0
- {jsonpointer-3.4 → jsonpointer-3.5}/jsonpointer.egg-info/dependency_links.txt +0 -0
- {jsonpointer-3.4 → jsonpointer-3.5}/jsonpointer.egg-info/top_level.txt +0 -0
- {jsonpointer-3.4 → jsonpointer-3.5}/setup.cfg +0 -0
- {jsonpointer-3.4 → jsonpointer-3.5}/setup.py +0 -0
|
@@ -13,7 +13,7 @@ parser = argparse.ArgumentParser(
|
|
|
13
13
|
# Accept pointer as option, as file or as first positional argument
|
|
14
14
|
ptr_group = parser.add_mutually_exclusive_group()
|
|
15
15
|
|
|
16
|
-
ptr_group.add_argument('-f', '--pointer-file', type=argparse.FileType('r'),
|
|
16
|
+
ptr_group.add_argument('-f', '--pointer-file', type=argparse.FileType('r', encoding='utf-8'),
|
|
17
17
|
help='File containing a JSON pointer expression')
|
|
18
18
|
|
|
19
19
|
ptr_group.add_argument('-p', '--pointer', type=str,
|
|
@@ -88,7 +88,7 @@ def resolve_files():
|
|
|
88
88
|
|
|
89
89
|
for name in files:
|
|
90
90
|
try:
|
|
91
|
-
f = argparse.FileType('r')(name)
|
|
91
|
+
f = argparse.FileType('r', encoding='utf-8')(name)
|
|
92
92
|
except argparse.ArgumentTypeError as e:
|
|
93
93
|
parser.error(str(e))
|
|
94
94
|
|
|
@@ -104,6 +104,9 @@ def resolve_files():
|
|
|
104
104
|
|
|
105
105
|
try:
|
|
106
106
|
result = jsonpointer.resolve_pointer(doc, ptr)
|
|
107
|
+
if isinstance(result, jsonpointer.EndOfList):
|
|
108
|
+
raise jsonpointer.JsonPointerException(
|
|
109
|
+
"'-' does not reference an existing array element")
|
|
107
110
|
print(json.dumps(result, indent=args.indent))
|
|
108
111
|
except jsonpointer.JsonPointerException as e:
|
|
109
112
|
print('Could not resolve pointer: %s' % str(e), file=sys.stderr)
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
# Will be parsed by setup.py to determine package metadata
|
|
34
34
|
__author__ = 'Stefan Kögl <stefan@skoegl.net>'
|
|
35
|
-
__version__ = '3.
|
|
35
|
+
__version__ = '3.5'
|
|
36
36
|
__website__ = 'https://github.com/stefankoegl/python-json-pointer'
|
|
37
37
|
__license__ = 'Modified BSD License'
|
|
38
38
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import copy
|
|
4
4
|
import doctest
|
|
5
|
+
import json
|
|
5
6
|
import os
|
|
6
7
|
import subprocess
|
|
7
8
|
import sys
|
|
@@ -566,14 +567,33 @@ class CommandLineTests(unittest.TestCase):
|
|
|
566
567
|
self._write('ptr.txt', '/a\n')
|
|
567
568
|
|
|
568
569
|
def _write(self, name, content):
|
|
569
|
-
with open(os.path.join(self.dir, name), 'w') as f:
|
|
570
|
+
with open(os.path.join(self.dir, name), 'w', encoding='utf-8') as f:
|
|
570
571
|
f.write(content)
|
|
571
572
|
|
|
572
|
-
def _run(self, *args):
|
|
573
|
+
def _run(self, *args, utf8=True):
|
|
573
574
|
env = dict(os.environ, PYTHONPATH=self.ROOT, PYTHONUTF8='1')
|
|
575
|
+
if not utf8:
|
|
576
|
+
# Keep pipes in UTF-8 while exercising locale-dependent file I/O.
|
|
577
|
+
env.update(PYTHONUTF8='0', PYTHONIOENCODING='utf-8',
|
|
578
|
+
LC_ALL='C', PYTHONCOERCECLOCALE='0')
|
|
574
579
|
return subprocess.run([sys.executable, self.SCRIPT] + list(args),
|
|
575
580
|
cwd=self.dir, env=env, capture_output=True,
|
|
576
|
-
|
|
581
|
+
encoding='utf-8')
|
|
582
|
+
|
|
583
|
+
def test_utf8_json_file_without_utf8_mode(self):
|
|
584
|
+
self._write('unicode.json', '{"value": "🚀"}')
|
|
585
|
+
proc = self._run('/value', 'unicode.json', utf8=False)
|
|
586
|
+
self.assertEqual(proc.returncode, 0, proc.stderr)
|
|
587
|
+
self.assertEqual(json.loads(proc.stdout), '🚀')
|
|
588
|
+
self.assertEqual(proc.stderr, '')
|
|
589
|
+
|
|
590
|
+
def test_utf8_pointer_file_without_utf8_mode(self):
|
|
591
|
+
self._write('unicode.json', json.dumps({'ä': 'expected'}))
|
|
592
|
+
self._write('unicode.txt', '/ä\n')
|
|
593
|
+
proc = self._run('-f', 'unicode.txt', 'unicode.json', utf8=False)
|
|
594
|
+
self.assertEqual(proc.returncode, 0, proc.stderr)
|
|
595
|
+
self.assertEqual(json.loads(proc.stdout), 'expected')
|
|
596
|
+
self.assertEqual(proc.stderr, '')
|
|
577
597
|
|
|
578
598
|
def test_positional_pointer(self):
|
|
579
599
|
proc = self._run('/a', 'a.json', 'b.json')
|
|
@@ -639,6 +659,36 @@ class CommandLineTests(unittest.TestCase):
|
|
|
639
659
|
self.assertIn('Could not resolve pointer', proc.stderr)
|
|
640
660
|
self.assertEqual(proc.stdout, '')
|
|
641
661
|
|
|
662
|
+
def test_end_of_list_pointer(self):
|
|
663
|
+
for content, pointer in (('[]', '/-'), ('[1, 2]', '/-'),
|
|
664
|
+
('{"a": []}', '/a/-')):
|
|
665
|
+
with self.subTest(content=content, pointer=pointer):
|
|
666
|
+
self._write('array.json', content)
|
|
667
|
+
proc = self._run(pointer, 'array.json')
|
|
668
|
+
self.assertEqual(proc.returncode, 1)
|
|
669
|
+
self.assertEqual(proc.stdout, '')
|
|
670
|
+
self.assertIn('Could not resolve pointer:', proc.stderr)
|
|
671
|
+
self.assertNotIn('Traceback', proc.stderr)
|
|
672
|
+
|
|
673
|
+
def test_end_of_list_pointer_in_one_file(self):
|
|
674
|
+
self._write('array.json', '{"a": []}')
|
|
675
|
+
self._write('member.json', '{"a": {"-": "value"}}')
|
|
676
|
+
for files in (('array.json', 'member.json'),
|
|
677
|
+
('member.json', 'array.json')):
|
|
678
|
+
with self.subTest(files=files):
|
|
679
|
+
proc = self._run('/a/-', *files)
|
|
680
|
+
self.assertEqual(proc.returncode, 1)
|
|
681
|
+
self.assertEqual(proc.stdout, '"value"\n')
|
|
682
|
+
self.assertIn('Could not resolve pointer:', proc.stderr)
|
|
683
|
+
self.assertNotIn('Traceback', proc.stderr)
|
|
684
|
+
|
|
685
|
+
def test_hyphen_object_member(self):
|
|
686
|
+
self._write('member.json', '{"-": [1, 2]}')
|
|
687
|
+
proc = self._run('/-', 'member.json')
|
|
688
|
+
self.assertEqual(proc.returncode, 0, proc.stderr)
|
|
689
|
+
self.assertEqual(proc.stdout, '[1, 2]\n')
|
|
690
|
+
self.assertEqual(proc.stderr, '')
|
|
691
|
+
|
|
642
692
|
def test_unresolvable_pointer_in_one_file(self):
|
|
643
693
|
# /b resolves in b.json only; a.json is still reported but b.json
|
|
644
694
|
# is processed
|
|
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
|