summaryrefslogtreecommitdiff
path: root/jsonpointer.py
diff options
context:
space:
mode:
Diffstat (limited to 'jsonpointer.py')
-rw-r--r--jsonpointer.py30
1 files changed, 13 insertions, 17 deletions
diff --git a/jsonpointer.py b/jsonpointer.py
index 4f2bfc7..9a6a613 100644
--- a/jsonpointer.py
+++ b/jsonpointer.py
@@ -228,26 +228,18 @@ class JsonPointer(object):
return part
else:
- raise JsonPointerException("document '%s' does not support indexing, "
+ raise JsonPointerException("Document '%s' does not support indexing, "
"must be mapping/sequence or support __getitem__" % type(doc))
+
def walk(self, doc, part):
- """Walks one step in doc and returns the referenced part"""
+ """ Walks one step in doc and returns the referenced part """
part = self.get_part(doc, part)
- assert 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):
+ assert hasattr(doc, '__getitem__'), "invalid document type %s" % (type(doc),)
+ if isinstance(doc, Sequence):
if part == '-':
return EndOfList(doc)
@@ -257,16 +249,20 @@ 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"""
+ """ Returns True if self contains the given ptr """
return self.parts[:len(ptr.parts)] == ptr.parts
def __contains__(self, item):
- """Returns True if self contains the given ptr"""
+ """ Returns True if self contains the given ptr """
return self.contains(item)
@property