summaryrefslogtreecommitdiff
path: root/jsonpointer.py
diff options
context:
space:
mode:
Diffstat (limited to 'jsonpointer.py')
-rw-r--r--jsonpointer.py18
1 files changed, 7 insertions, 11 deletions
diff --git a/jsonpointer.py b/jsonpointer.py
index b3f0362..06d2cb7 100644
--- a/jsonpointer.py
+++ b/jsonpointer.py
@@ -225,15 +225,7 @@ class JsonPointer(object):
assert (type(doc) in (dict, list) or hasattr(doc, '__getitem__')), "invalid document type %s" % (type(doc),)
- if isinstance(doc, Mapping):
- try:
- return doc[part]
-
- except KeyError:
- raise JsonPointerException("member '%s' not found in %s" % (part, doc))
-
- elif isinstance(doc, Sequence):
-
+ if isinstance(doc, Sequence):
if part == '-':
return EndOfList(doc)
@@ -243,10 +235,14 @@ class JsonPointer(object):
except IndexError:
raise JsonPointerException("index '%s' is out of bounds" % (part, ))
- else:
- # Object supports __getitem__, assume custom indexing
+ # Else the object is a mapping or supports __getitem__(so assume custom indexing)
+ try:
return doc[part]
+ except KeyError:
+ raise JsonPointerException("member '%s' not found in %s" % (part, doc))
+
+
def contains(self, ptr):
""" Returns True if self contains the given ptr """
return len(self.parts) > len(ptr.parts) and \