jsonpointer.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:deb-python-json-pointer 作者: openstack 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号