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


Python jsonpointer.JsonPointer类代码示例

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


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

示例1: ComparisonTests

class ComparisonTests(unittest.TestCase):

    def setUp(self):
        self.ptr1 = JsonPointer("/a/b/c")
        self.ptr2 = JsonPointer("/a/b")
        self.ptr3 = JsonPointer("/b/c")

    def test_eq_hash(self):
        p1 = JsonPointer("/something/1/b")
        p2 = JsonPointer("/something/1/b")
        p3 = JsonPointer("/something/1.0/b")

        self.assertEqual(p1, p2)
        self.assertNotEqual(p1, p3)
        self.assertNotEqual(p2, p3)

        self.assertEqual(hash(p1), hash(p2))
        self.assertNotEqual(hash(p1), hash(p3))
        self.assertNotEqual(hash(p2), hash(p3))

        # a pointer compares not-equal to objects of other types
        self.assertFalse(p1 == "/something/1/b")

    def test_contains(self):

        self.assertTrue(self.ptr1.contains(self.ptr2))
        self.assertTrue(self.ptr1.contains(self.ptr1))
        self.assertFalse(self.ptr1.contains(self.ptr3))

    def test_contains_magic(self):

        self.assertTrue(self.ptr2 in self.ptr1)
        self.assertTrue(self.ptr1 in self.ptr1)
        self.assertFalse(self.ptr3 in self.ptr1)
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:34,代码来源:tests.py

示例2: test_contains

    def test_contains(self):
        p1 = JsonPointer("/a/b/c")
        p2 = JsonPointer("/a/b")
        p3 = JsonPointer("/b/c")

        self.assertTrue(p1.contains(p2))
        self.assertFalse(p1.contains(p3))
开发者ID:dsuch,项目名称:python-json-pointer,代码行数:7,代码来源:tests.py

示例3: apply

    def apply(self, obj):
        try:
            from_ptr = JsonPointer(self.operation['from'])
        except KeyError as ex:
            raise InvalidJsonPatch(
                "The operation does not contain a 'from' member")

        subobj, part = from_ptr.to_last(obj)
        try:
            value = subobj[part]
        except (KeyError, IndexError) as ex:
            raise JsonPatchConflict(str(ex))

        if isinstance(subobj, MutableMapping) and \
                self.pointer.contains(from_ptr):
            raise JsonPatchConflict('Cannot move values into its own children')

        obj = RemoveOperation({
            'op': 'remove',
            'path': self.operation['from']
        }).apply(obj)

        obj = AddOperation({
            'op': 'add',
            'path': self.location,
            'value': value
        }).apply(obj)

        return obj
开发者ID:602p,项目名称:spacegame,代码行数:29,代码来源:jsonpatch.py

示例4: __init__

 def __init__(self, workflowobj, offset=''):
     self.wflow = workflowobj
     self.dag = workflowobj.dag
     self.rules = workflowobj.rules
     self.applied_rules = workflowobj.applied_rules
     self.offset = offset
     self.steps = JsonPointer(self.offset).resolve(workflowobj.stepsbystage)
     self.bookkeeper = JsonPointer(self.offset).resolve(workflowobj.bookkeeping)
     self.values = JsonPointer(self.offset).resolve(workflowobj.values)
开发者ID:lukasheinrich,项目名称:yadage,代码行数:9,代码来源:wflowview.py

示例5: createOffsetMeta

def createOffsetMeta(offset, bookkeeping):
    '''
    sets up a location to track rule and step ids for a given scope offset
    '''
    pointer = JsonPointer(offset)
    view = bookkeeping
    for x in pointer.parts:
        view = view.setdefault(x,{})
    pointer.resolve(bookkeeping).setdefault('_meta',{'stages': [], 'steps': []})
开发者ID:lukasheinrich,项目名称:yadage,代码行数:9,代码来源:wflowview.py

示例6: add

    def add(self, name, value, *ignored_args, **ignored_kwargs):
        """ Adds a new JSON Pointer expression to the store.
        """
        # Make sure it's valid, no exception in 'resolve' means the expression was valid.
        pointer = JsonPointer(value)
        pointer.resolve({}, None)

        with self.update_lock:
            self.data[name] = pointer
开发者ID:remcoboerma,项目名称:zato,代码行数:9,代码来源:message.py

示例7: apply

    def apply(self, obj):
        from_ptr = JsonPointer(self.operation['from'])
        subobj, part = from_ptr.to_last(obj)
        value = copy.deepcopy(subobj[part])

        obj = AddOperation({
            'op': 'add',
            'path': self.location,
            'value': value
        }).apply(obj)

        return obj
开发者ID:graingert,项目名称:python-json-patch,代码行数:12,代码来源:jsonpatch.py

示例8: compare_dicts

 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,代码行数:13,代码来源:jsonpatch.py

示例9: addRule

    def addRule(self, rule, offset='', identifier = None):
        '''
        add a DAG extension rule, possibly with a scope offset
        '''
        thisoffset = JsonPointer(offset)
        if offset != '':
            createIndexData(thisoffset.path, self.steps, self.values)
        createOffsetMeta(thisoffset.path, self.bookkeeper)

        offsetstage = OffsetStage(rule, self._makeoffset(offset), identifier = identifier)
        self.rules += [offsetstage]
        thisoffset.resolve(self.bookkeeper)['_meta']['stages'] += [offsetstage.identifier]
        return offsetstage.identifier
开发者ID:lukasheinrich,项目名称:yadage,代码行数:13,代码来源:wflowview.py

示例10: resolve

 def resolve(self, doc, default=jsonpointer._nothing):
     if self.isHash:
         if len(self.parts) == 1:
             refdata = doc
         else:
             p = JsonPointer('/' + '/'.join(self.parts[:-1]))
             refdata = p.resolve(doc)
         if isinstance(refdata, list):
             return int(self.parts[-1])
         else:
             return self.parts[-1]
     else:
         return super(RelJsonPointer, self).resolve(doc, default)
开发者ID:riverbed,项目名称:reschema,代码行数:13,代码来源:reljsonpointer.py

示例11: apply

    def apply(self, obj):
        from_ptr = JsonPointer(self.operation['from'])
        subobj, part = from_ptr.to_last(obj)
        try:
            value = copy.deepcopy(subobj[part])
        except (KeyError, IndexError) as ex:
            raise JsonPatchConflict(str(ex))

        obj = AddOperation({
            'op': 'add',
            'path': self.location,
            'value': value
        }).apply(obj)

        return obj
开发者ID:zbyte64,项目名称:python-json-patch,代码行数:15,代码来源:jsonpatch.py

示例12: compare_dicts

 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,代码行数:15,代码来源:jsonpatch.py

示例13: apply

    def apply(self, obj):
        try:
            from_ptr = JsonPointer(self.operation["from"])
        except KeyError as ex:
            raise InvalidJsonPatch("The operation does not contain a 'from' member")

        subobj, part = from_ptr.to_last(obj)
        try:
            value = copy.deepcopy(subobj[part])
        except (KeyError, IndexError) as ex:
            raise JsonPatchConflict(str(ex))

        obj = AddOperation({"op": "add", "path": self.location, "value": value}).apply(obj)

        return obj
开发者ID:stefankoegl,项目名称:python-json-patch,代码行数:15,代码来源:jsonpatch.py

示例14: _compare_right

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,代码行数:10,代码来源:jsonpatch.py

示例15: _makeoffset

    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,代码行数:12,代码来源:wflowview.py


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