def walk(self, doc, 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, Sequence):
if part == '-':
return EndOfList(doc)
try:
return doc[part]
except IndexError:
raise JsonPointerException("index '%s' is out of bounds" % (part, ))
# 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))
评论列表
文章目录