当前位置: 首页>>代码示例>>Python>>正文


Python JsonPointer.from_parts方法代码示例

本文整理汇总了Python中jsonpointer.JsonPointer.from_parts方法的典型用法代码示例。如果您正苦于以下问题:Python JsonPointer.from_parts方法的具体用法?Python JsonPointer.from_parts怎么用?Python JsonPointer.from_parts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsonpointer.JsonPointer的用法示例。


在下文中一共展示了JsonPointer.from_parts方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compare_dicts

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
 def compare_dicts(path, src, dst):
     for key in src:
         if key not in dst:
             ptr = JsonPointer.from_parts(path + [key])
             yield {"op": "remove", "path": ptr.path}
             continue
         current = path + [key]
         for operation in compare_values(current, src[key], dst[key]):
             yield operation
     for key in dst:
         if key not in src:
             ptr = JsonPointer.from_parts(path + [key])
             yield {"op": "add", "path": ptr.path, "value": dst[key]}
开发者ID:stefankoegl,项目名称:python-json-patch,代码行数:15,代码来源:jsonpatch.py

示例2: compare_dicts

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
 def compare_dicts(path, src, dst):
     for key in src:
         if key not in dst:
             ptr = JsonPointer.from_parts(path + [key])
             yield {'op': 'remove', 'path': ptr.path}
             continue
         current = path + [key]
         for operation in compare_values(current, src[key], dst[key]):
             yield operation
     for key in dst:
         if key not in src:
             ptr = JsonPointer.from_parts(path + [key])
             yield {'op': 'add',
                    'path': ptr.path,
                    'value': dst[key]}
开发者ID:602p,项目名称:spacegame,代码行数:17,代码来源:jsonpatch.py

示例3: _compare_right

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
def _compare_right(path, dst, right, shift):
    """Yields JSON patch ``add`` operations for elements that are only
    exists in the `dst` list"""
    start, end = right
    if end == -1:
        end = len(dst)
    for idx in range(start, end):
        ptr = JsonPointer.from_parts(path + [str(idx)])
        yield ({"op": "add", "path": ptr.path, "value": dst[idx]}, shift + 1)
        shift += 1
开发者ID:stefankoegl,项目名称:python-json-patch,代码行数:12,代码来源:jsonpatch.py

示例4: compare_values

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
 def compare_values(path, value, other):
     if value == other:
         return
     if isinstance(value, dict) and isinstance(other, dict):
         for operation in compare_dicts(path, value, other):
             yield operation
     elif isinstance(value, list) and isinstance(other, list):
         for operation in compare_lists(path, value, other):
             yield operation
     else:
         ptr = JsonPointer.from_parts(path)
         yield {'op': 'replace', 'path': ptr.path, 'value': other}
开发者ID:vishwakarma,项目名称:python-json-patch,代码行数:14,代码来源:jsonpatch.py

示例5: _makeoffset

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
    def _makeoffset(self, offset):
        '''
        prepare a full offset based on this views' offset and a relative offset

        :param offset: the relative offset
        '''
        thisoffset = JsonPointer(offset)
        if self.offset:
            fulloffset = JsonPointer.from_parts(JsonPointer(self.offset).parts + thisoffset.parts).path
        else:
            fulloffset = thisoffset.path
        return fulloffset
开发者ID:lukasheinrich,项目名称:yadage,代码行数:14,代码来源:wflowview.py

示例6: compare_values

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
 def compare_values(path, value, other):
     if value == other:
         return
     if isinstance(value, MutableMapping) and isinstance(other, MutableMapping):
         for operation in compare_dicts(path, value, other):
             yield operation
     elif isinstance(value, MutableSequence) and isinstance(other, MutableSequence):
         for operation in compare_lists(path, value, other):
             yield operation
     else:
         ptr = JsonPointer.from_parts(path)
         yield {"op": "replace", "path": ptr.path, "value": other}
开发者ID:stefankoegl,项目名称:python-json-patch,代码行数:14,代码来源:jsonpatch.py

示例7: compare_values

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
 def compare_values(path, value, other):
     if value == other:
         return
     if isinstance(value, MutableMapping) and \
             isinstance(other, MutableMapping):
         for operation in compare_dicts(path, value, other):
             yield operation
     elif isinstance(value, MutableSequence) and \
             isinstance(other, MutableSequence):
         for operation in compare_lists(path, value, other):
             yield operation
     else:
         ptr = JsonPointer.from_parts(path)
         yield {'op': 'replace', 'path': ptr.path, 'value': other}
开发者ID:602p,项目名称:spacegame,代码行数:16,代码来源:jsonpatch.py

示例8: addWorkflow

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
    def addWorkflow(self, rules, stage=None):
        '''
        add a (sub-)workflow (i.e. list of stages) to the overall workflow
        '''
        offset = ''
        if stage is not None:
            #make sure storage for the 'authoring' stage is present and
            #register the workflow as part of that 'author'
            #needed e.g. for predicate handlers trying to determing if
            #the author stage is done
            nextindex = len(self.steps.get(stage,[]))
            offset = JsonPointer.from_parts([stage, nextindex]).path

            self.steps.setdefault(stage,[]).append({})
            self.values.setdefault(stage,[]).append({})

        for rule in rules:
            self.addRule(rule, offset)
开发者ID:lukasheinrich,项目名称:yadage,代码行数:20,代码来源:wflowview.py

示例9: _compare_left

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
def _compare_left(path, src, left, shift):
    """Yields JSON patch ``remove`` operations for elements that are only
    exists in the `src` list."""
    start, end = left
    if end == -1:
        end = len(src)
    # we need to `remove` elements from list tail to not deal with index shift
    for idx in reversed(range(start + shift, end + shift)):
        ptr = JsonPointer.from_parts(path + [str(idx)])
        yield (
            {'op': 'remove',
             # yes, there should be any value field, but we'll use it
             # to apply `move` optimization a bit later and will remove
             # it in _optimize function.
             'value': src[idx - shift],
             'path': ptr.path,
            },
            shift - 1
        )
        shift -= 1
开发者ID:602p,项目名称:spacegame,代码行数:22,代码来源:jsonpatch.py

示例10: test_round_trip

# 需要导入模块: from jsonpointer import JsonPointer [as 别名]
# 或者: from jsonpointer.JsonPointer import from_parts [as 别名]
    def test_round_trip(self):
        paths = [
            "",
            "/foo",
            "/foo/0",
            "/",
            "/a~1b",
            "/c%d",
            "/e^f",
            "/g|h",
            "/i\\j",
            "/k\"l",
            "/ ",
            "/m~0n",
        ]
        for path in paths:
            ptr = JsonPointer(path)
            self.assertEqual(path, ptr.path)

            parts = ptr.parts
            new_ptr = JsonPointer.from_parts(parts)
            self.assertEqual(ptr, new_ptr)
开发者ID:dsuch,项目名称:python-json-pointer,代码行数:24,代码来源:tests.py


注:本文中的jsonpointer.JsonPointer.from_parts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。