refactor type check

This commit is contained in:
Stefan Kögl
2013-07-11 21:50:31 +02:00
parent ef7a41cdce
commit 48dce31314

View File

@@ -175,6 +175,10 @@ class JsonPointer(object):
part = self.get_part(doc, part)
# type is already checked in get_part, so we assert here
# for consistency
assert type(doc) in (dict, list), "invalid document type %s" (type(doc),)
if isinstance(doc, dict):
try:
return doc[part]
@@ -194,11 +198,6 @@ class JsonPointer(object):
raise JsonPointerException("index '%s' is out of bounds" % (part, ))
else:
raise JsonPointerException("can not go beyond '%s' (type '%s')" % (part, doc.__class__))
def contains(self, ptr):
"""" Returns True if self contains the given ptr """
return len(self.parts) > len(ptr.parts) and \