def get_part(self, doc, part):
""" Returns the next step in the correct type """
if isinstance(doc, Mapping):
return part
elif isinstance(doc, Sequence):
if part == '-':
return part
if not RE_ARRAY_INDEX.match(str(part)):
raise JsonPointerException("'%s' is not a valid list index" % (part, ))
return int(part)
elif hasattr(doc, '__getitem__'):
# Allow indexing via ducktyping if the target has defined __getitem__
return part
else:
raise JsonPointerException("Document '%s' does not support indexing, "
"must be dict/list or support __getitem__" % type(doc))
评论列表
文章目录