jsonpointer 3.9__tar.gz → 3.10__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.9/jsonpointer.egg-info → jsonpointer-3.10}/PKG-INFO +1 -1
- {jsonpointer-3.9 → jsonpointer-3.10/jsonpointer.egg-info}/PKG-INFO +1 -1
- {jsonpointer-3.9 → jsonpointer-3.10}/jsonpointer.py +7 -1
- {jsonpointer-3.9 → jsonpointer-3.10}/tests.py +30 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/AUTHORS +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/LICENSE.txt +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/MANIFEST.in +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/README.md +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/bin/jsonpointer +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/doc/commandline.rst +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/doc/index.rst +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/doc/mod-jsonpointer.rst +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/doc/tutorial.rst +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/jsonpointer-stubs/__init__.pyi +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/jsonpointer.egg-info/SOURCES.txt +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/jsonpointer.egg-info/dependency_links.txt +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/jsonpointer.egg-info/top_level.txt +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/setup.cfg +0 -0
- {jsonpointer-3.9 → jsonpointer-3.10}/setup.py +0 -0
|
@@ -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.10'
|
|
36
36
|
__website__ = 'https://github.com/stefankoegl/python-json-pointer'
|
|
37
37
|
__license__ = 'Modified BSD License'
|
|
38
38
|
|
|
@@ -341,6 +341,12 @@ class JsonPointer:
|
|
|
341
341
|
|
|
342
342
|
# Else the object is a mapping or supports __getitem__(so assume custom indexing)
|
|
343
343
|
try:
|
|
344
|
+
# Check membership first so that mappings with a fallback for
|
|
345
|
+
# missing keys (e.g. defaultdict.__missing__) are not mutated and
|
|
346
|
+
# absent members are reported as missing.
|
|
347
|
+
if isinstance(doc, Mapping) and part not in doc:
|
|
348
|
+
raise KeyError(part)
|
|
349
|
+
|
|
344
350
|
return doc[part]
|
|
345
351
|
|
|
346
352
|
except KeyError:
|
|
@@ -12,6 +12,7 @@ import sys
|
|
|
12
12
|
import tempfile
|
|
13
13
|
import textwrap
|
|
14
14
|
import unittest
|
|
15
|
+
from collections import defaultdict
|
|
15
16
|
from contextlib import redirect_stderr, redirect_stdout
|
|
16
17
|
from unittest import mock
|
|
17
18
|
|
|
@@ -593,6 +594,35 @@ class AltTypesTests(unittest.TestCase):
|
|
|
593
594
|
self.assertRaises(JsonPointerException, resolve_pointer, doc, '/root/1/2/3/4')
|
|
594
595
|
|
|
595
596
|
|
|
597
|
+
class DefaultDictTests(unittest.TestCase):
|
|
598
|
+
"""Missing members of mappings with __missing__ must stay missing (#101)"""
|
|
599
|
+
|
|
600
|
+
def test_resolve_missing_returns_default(self):
|
|
601
|
+
doc = defaultdict(dict)
|
|
602
|
+
self.assertEqual(resolve_pointer(doc, '/missing', 'SENTINEL'), 'SENTINEL')
|
|
603
|
+
self.assertEqual(dict(doc), {})
|
|
604
|
+
|
|
605
|
+
def test_resolve_missing_raises(self):
|
|
606
|
+
doc = defaultdict(dict)
|
|
607
|
+
self.assertRaises(JsonPointerException, resolve_pointer, doc, '/missing')
|
|
608
|
+
self.assertEqual(dict(doc), {})
|
|
609
|
+
|
|
610
|
+
def test_resolve_existing_member(self):
|
|
611
|
+
doc = defaultdict(dict, {'foo': {'bar': 1}})
|
|
612
|
+
self.assertEqual(resolve_pointer(doc, '/foo/bar'), 1)
|
|
613
|
+
|
|
614
|
+
def test_set_without_create_raises(self):
|
|
615
|
+
doc = defaultdict(dict)
|
|
616
|
+
self.assertRaises(JsonPointerException, set_pointer, doc,
|
|
617
|
+
'/missing/child', 1)
|
|
618
|
+
self.assertEqual(dict(doc), {})
|
|
619
|
+
|
|
620
|
+
def test_set_with_create(self):
|
|
621
|
+
doc = defaultdict(dict)
|
|
622
|
+
set_pointer(doc, '/missing/child', 1, create=True)
|
|
623
|
+
self.assertEqual(dict(doc), {'missing': {'child': 1}})
|
|
624
|
+
|
|
625
|
+
|
|
596
626
|
class CommandLineTests(unittest.TestCase):
|
|
597
627
|
""" Tests the jsonpointer command line utility """
|
|
598
628
|
|
|
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
|