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


Python jsonpointer.resolve_pointer方法代码示例

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


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

示例1: validate_deferred_references

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def validate_deferred_references(schema, context, **kwargs):
    try:
        deferred_references = context['deferred_references']
    except KeyError:
        raise KeyError("`deferred_references` not found in context")

    with ErrorDict() as errors:
        for reference in deferred_references:
            parts = urlparse.urlparse(reference)
            if any((parts.scheme, parts.netloc, parts.path, parts.params, parts.query)):
                errors.add_error(
                    reference,
                    MESSAGES['reference']['unsupported'].format(reference),
                )
                continue
            try:
                jsonpointer.resolve_pointer(schema, parts.fragment)
            except jsonpointer.JsonPointerException:
                errors.add_error(
                    reference,
                    MESSAGES['reference']['undefined'].format(reference),
                ) 
开发者ID:pipermerriam,项目名称:flex,代码行数:24,代码来源:__init__.py

示例2: __init__

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def __init__(self, directive, arguments, options, content, lineno, content_offset, block_text, state, state_machine):
        assert directive == 'jsonschema'

        #breakpoint()

        self.options = options
        self.state = state
        self.lineno = lineno
        self.statemachine = state_machine

        if len(arguments) == 1:
            filename, pointer = self._splitpointer(arguments[0])
            if filename != '':
                self._load_external(filename)
            else:
                self._load_internal(content)
            if pointer:
                self.schema = resolve_pointer(self.schema, pointer)
        else:
            self._load_internal(content) 
开发者ID:lnoor,项目名称:sphinx-jsonschema,代码行数:22,代码来源:__init__.py

示例3: get_identifiers

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def get_identifiers(self):

        if self.xml:
            doc = lxml.etree.fromstring(self.xml)
            for number_type, xpath in self.XML_IDENTIFIER_XPATH_MAP.items():
                node = doc.xpath(xpath, namespaces=self.XML_NAMESPACES)
                if node:
                    identifier = self.sanitize_value(node[0].text)
                    if identifier:
                        self.identifiers.setdefault(number_type, identifier)

        if self.json:
            data = json.loads(self.json)
            for number_type, jpointer in self.JSON_IDENTIFIER_JSONPOINTER_MAP.items():
                try:
                    identifier = self.sanitize_value(jsonpointer.resolve_pointer(data, jpointer))
                    if identifier:
                        self.identifiers.setdefault(number_type, identifier)
                except jsonpointer.JsonPointerException:
                    pass

        return self.identifiers 
开发者ID:ip-tools,项目名称:uspto-opendata-python,代码行数:24,代码来源:document.py

示例4: getConfigValue

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def getConfigValue(self, conf_key):
        self._ensureConfig()
        # jsonpointer, pip install jsonpointer, BSD 3 Clause
        import jsonpointer
        try:
            return jsonpointer.resolve_pointer(self.config, conf_key)
        except jsonpointer.JsonPointerException as e:
            # fall back to legacy dot-separated pointers
            key_path = conf_key.split('.');
            c = self.config
            for part in key_path:
                if part in c:
                    c = c[part]
                else:
                    return None
            return c 
开发者ID:ARMmbed,项目名称:yotta,代码行数:18,代码来源:target.py

示例5: __init__

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def __init__(self, reference, context):
        if self.validators_constructor is None:
            raise NotImplementedError(
                "Subclasses of LazyReferenceValidator must specify a "
                "`validators_constructor` function"
            )

        self.reference_fragment = urlparse.urlparse(reference).fragment
        # TODO: something better than this which potentiall raises a
        # JsonPointerException
        jsonpointer.resolve_pointer(context, self.reference_fragment)
        self.reference = reference
        self.context = context 
开发者ID:pipermerriam,项目名称:flex,代码行数:15,代码来源:reference.py

示例6: schema

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def schema(self):
        return jsonpointer.resolve_pointer(self.context, self.reference_fragment) 
开发者ID:pipermerriam,项目名称:flex,代码行数:4,代码来源:reference.py

示例7: dereference_reference

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def dereference_reference(reference, context):
    parts = urlparse.urlparse(reference)
    if any((parts.scheme, parts.netloc, parts.path, parts.params, parts.query)):
        raise ValueError(
            MESSAGES['reference']['unsupported'].format(reference),
        )
    return jsonpointer.resolve_pointer(context, parts.fragment) 
开发者ID:pipermerriam,项目名称:flex,代码行数:9,代码来源:utils.py

示例8: validate_reference_pointer

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def validate_reference_pointer(reference, context, **kwargs):
    parts = urlparse.urlparse(reference)
    if any((parts.scheme, parts.netloc, parts.path, parts.params, parts.query)):
        raise ValidationError(
            MESSAGES['reference']['unsupported'].format(reference),
        )

    try:
        jsonpointer.resolve_pointer(context, parts.fragment)
    except jsonpointer.JsonPointerException:
        raise ValidationError(
            MESSAGES['reference']['undefined'].format(reference),
        ) 
开发者ID:pipermerriam,项目名称:flex,代码行数:15,代码来源:reference.py

示例9: find

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def find(self, path, default=None):
        """
         Retrieves a single value using JSON-Pointer syntax
        """
        result = resolve_pointer(self.__d, path, default)
        if isinstance(result, dict):
            result = TDict(result)
        return result 
开发者ID:vandersonmota,项目名称:t_dict,代码行数:10,代码来源:t_dict.py

示例10: _without

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def _without(obj, attrs, path=None):
    """Returns patched object with attributes deleted."""
    if path:
        ptrval = copy.deepcopy(jsonpointer.resolve_pointer(obj, path))
        return _patch(obj, path, _without(ptrval, attrs))
    else:
        updated = copy.deepcopy(obj)
        for attr in attrs:
            if attr in updated:
                del updated[attr]
        return updated 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:13,代码来源:schema_test.py

示例11: get

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def get(self, selector=None):
        """Main function for get command

        :param selector: the type selection for the get operation.
        :type selector: str.
        :returns: returns a list from get operation

        """
        results = list()

        instances = self.get_selection()
        if not instances or len(instances) == 0:
            raise NothingSelectedError()

        for instance in instances:
            currdict = instance.resp.dict

            # apply patches to represent current edits
            for patch in instance.patches:
                currdict = jsonpatch.apply_patch(currdict, patch)

            if selector:
                jsonpath_expr = jsonpath_rw.parse(u'%s' % selector)
                matches = jsonpath_expr.find(currdict)
                temp_dict = OrderedDict()

                for match in matches:
                    json_pstr = u'/%s' % match.full_path
                    json_node = jsonpointer.resolve_pointer(currdict, json_pstr)
                    temp_dict[str(match.full_path)] = json_node
                    results.append(temp_dict)
            else:
                results.append(currdict)

        return results 
开发者ID:HewlettPackard,项目名称:python-ilorest-library-old,代码行数:37,代码来源:rmc.py

示例12: get_version_diff

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def get_version_diff(from_data, to_data):
    """Calculate the diff (a mangled JSON patch) between from_data and to_data"""

    basic_patch = jsonpatch.make_patch(from_data, to_data)
    result = []
    for operation in sorted(basic_patch, key=lambda o: (o['op'], o['path'])):
        op = operation['op']
        ignore = False
        # We deal with standing_in and party_memberships slightly
        # differently so they can be presented in human-readable form,
        # so match those cases first:
        m = re.search(
            r'(standing_in|party_memberships)(?:/([^/]+))?(?:/(\w+))?',
            operation['path'],
        )
        if op in ('replace', 'remove'):
            operation['previous_value'] = \
                jsonpointer.resolve_pointer(
                    from_data,
                    operation['path'],
                    default=None
                )

        attribute, election, leaf = m.groups() if m else (None, None, None)
        if attribute:
            explain_standing_in_and_party_memberships(operation, attribute, election, leaf)
        if op in ('replace', 'remove'):
            if op == 'replace' and not operation['previous_value']:
                if operation['value']:
                    operation['op'] = 'add'
                else:
                    # Ignore replacing no data with no data:
                    ignore = True
        elif op == 'add':
            # It's important that we don't skip the case where a
            # standing_in value is being set to None, because that's
            # saying 'we *know* they're not standing then'
            if (not operation['value']) and (attribute != 'standing_in'):
                ignore = True
        operation['path'] = re.sub(r'^/', '', operation['path'])
        if not ignore:
            result.append(operation)
        # The operations generated by jsonpatch are incremental, so we
        # need to apply each before going on to parse the next:
        operation['path'] = '/' + operation['path']
        from_data = jsonpatch.apply_patch(from_data, [operation])
    for operation in result:
        operation['path'] = operation['path'].lstrip('/')
    return result 
开发者ID:mysociety,项目名称:yournextrepresentative,代码行数:51,代码来源:diffs.py

示例13: get_save

# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def get_save(self, selector=None, currentoverride=False, pluspath=False, \
                                                                onlypath=None):
        """Special main function for get in save command

        :param selector: the type selection for the get operation.
        :type selector: str.
        :param currentoverride: flag to override current selection.
        :type currentoverride: boolean.
        :param pluspath: flag to add path to the results.
        :type pluspath: boolean.
        :param onlypath: flag to enable only that path selection.
        :type onlypath: boolean.
        :returns: returns a list from the get command

        """
        results = list()

        instances = self.get_selection()
        if not instances or len(instances) == 0:
            raise NothingSelectedError()

        for instance in instances:
            if self.get_save_helper(instance.resp.request.path, instances)\
                                                     and not currentoverride:
                continue
            elif onlypath:
                if not onlypath == instance.resp.request.path:
                    continue

            currdict = instance.resp.dict

            # apply patches to represent current edits
            for patch in instance.patches:
                currdict = jsonpatch.apply_patch(currdict, patch)

            if selector:
                for item in currdict.iterkeys():
                    if selector.lower() == item.lower():
                        selector = item
                        break

                try:
                    jsonpath_expr = jsonpath_rw.parse(u'"%s"' % selector)
                except Exception, excp:
                    raise InvalidCommandLineError(excp)

                matches = jsonpath_expr.find(currdict)
                temp_dict = OrderedDict()

                for match in matches:
                    json_pstr = u'/%s' % match.full_path
                    json_node = jsonpointer.resolve_pointer(currdict, json_pstr)
                    temp_dict[str(match.full_path)] = json_node

                results.append(temp_dict)
            else:
                if pluspath:
                    results.append({instance.resp.request.path: currdict})
                else:
                    results.append(currdict) 
开发者ID:HewlettPackard,项目名称:python-ilorest-library-old,代码行数:62,代码来源:rmc.py


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