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


Python exceptions.RefResolutionError方法代码示例

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


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

示例1: pop_scope

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import RefResolutionError [as 别名]
def pop_scope(self):
        try:
            self._scopes_stack.pop()
        except IndexError:
            raise RefResolutionError(
                "Failed to pop the scope from an empty stack. "
                "`pop_scope()` should only be called once for every "
                "`push_scope()`"
            ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:11,代码来源:validators.py

示例2: resolve_from_url

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import RefResolutionError [as 别名]
def resolve_from_url(self, url):
        url, fragment = urldefrag(url)
        try:
            document = self.store[url]
        except KeyError:
            try:
                document = self.resolve_remote(url)
            except Exception as exc:
                raise RefResolutionError(exc)

        return self.resolve_fragment(document, fragment) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:13,代码来源:validators.py

示例3: resolve_fragment

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import RefResolutionError [as 别名]
def resolve_fragment(self, document, fragment):
        """
        Resolve a ``fragment`` within the referenced ``document``.

        Arguments:

            document:

                The referrant document

            fragment (str):

                a URI fragment to resolve within it

        """

        fragment = fragment.lstrip(u"/")
        parts = unquote(fragment).split(u"/") if fragment else []

        for part in parts:
            part = part.replace(u"~1", u"/").replace(u"~0", u"~")

            if isinstance(document, Sequence):
                # Array indexes should be turned into integers
                try:
                    part = int(part)
                except ValueError:
                    pass
            try:
                document = document[part]
            except (TypeError, LookupError):
                raise RefResolutionError(
                    "Unresolvable JSON pointer: %r" % fragment
                )

        return document 
开发者ID:remg427,项目名称:misp42splunk,代码行数:38,代码来源:validators.py

示例4: test_resolvingRaisesError

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import RefResolutionError [as 别名]
def test_resolvingRaisesError(self):
        """
        The L{LocalRefResolver.resolving} context manager raises an exception
        when entered.
        """
        resolver = LocalRefResolver(base_uri=b'', referrer={})
        context = resolver.resolving(b'http://json-schema.org/schema')
        e = self.assertRaises(RefResolutionError, context.__enter__)

        self.assertIsInstance(e.args[0], SchemaNotProvided) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:12,代码来源:test_schema.py

示例5: load_resource_spec

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import RefResolutionError [as 别名]
def load_resource_spec(resource_spec_file):  # noqa: C901
    """Load a resource provider definition from a file, and validate it."""
    try:
        resource_spec = json.load(resource_spec_file)
    except ValueError as e:
        LOG.debug("Resource spec decode failed", exc_info=True)
        raise SpecValidationError(str(e)) from e

    validator = make_resource_validator()
    try:
        validator.validate(resource_spec)
    except ValidationError as e:
        LOG.debug("Resource spec validation failed", exc_info=True)
        raise SpecValidationError(str(e)) from e

    # TODO: more general validation framework
    if "remote" in resource_spec:
        raise SpecValidationError(
            "Property 'remote' is reserved for CloudFormation use"
        )

    try:
        base_uri = resource_spec["$id"]
    except KeyError:
        base_uri = get_file_base_uri(resource_spec_file)

    inliner = RefInliner(base_uri, resource_spec)
    try:
        inlined = inliner.inline()
    except RefResolutionError as e:
        LOG.debug("Resource spec validation failed", exc_info=True)
        raise SpecValidationError(str(e)) from e

    try:
        validator.validate(inlined)
    except ValidationError as e:
        LOG.debug("Inlined schema is no longer valid", exc_info=True)
        raise InternalError() from e

    return inlined 
开发者ID:aws-cloudformation,项目名称:cloudformation-cli,代码行数:42,代码来源:data_loaders.py

示例6: test_load_resource_spec_invalid_ref

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import RefResolutionError [as 别名]
def test_load_resource_spec_invalid_ref():
    copy = json.loads(json.dumps(BASIC_SCHEMA))
    copy["properties"]["foo"] = {"$ref": "#/bar"}
    with pytest.raises(SpecValidationError) as excinfo:
        load_resource_spec(json_s(copy))

    cause = excinfo.value.__cause__
    assert cause
    assert isinstance(cause, RefResolutionError)
    assert "bar" in str(cause) 
开发者ID:aws-cloudformation,项目名称:cloudformation-cli,代码行数:12,代码来源:test_data_loaders.py

示例7: pop_scope

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import RefResolutionError [as 别名]
def pop_scope(self):
        try:
            self._scopes_stack.pop()
        except IndexError:
            raise RefResolutionError(
                "Failed to pop the scope from an empty stack. "
                "`pop_scope()` should only be called once for every "
                "`push_scope()`",
            ) 
开发者ID:splunk,项目名称:SA-ctf_scoreboard,代码行数:11,代码来源:validators.py

示例8: resolve_fragment

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import RefResolutionError [as 别名]
def resolve_fragment(self, document, fragment):
        """
        Resolve a ``fragment`` within the referenced ``document``.

        :argument document: the referrant document
        :argument str fragment: a URI fragment to resolve within it

        """

        fragment = fragment.lstrip(u"/")
        parts = unquote(fragment).split(u"/") if fragment else []

        for part in parts:
            part = part.replace(u"~1", u"/").replace(u"~0", u"~")

            if isinstance(document, Sequence):
                # Array indexes should be turned into integers
                try:
                    part = int(part)
                except ValueError:
                    pass
            try:
                document = document[part]
            except (TypeError, LookupError):
                raise RefResolutionError(
                    "Unresolvable JSON pointer: %r" % fragment
                )

        return document 
开发者ID:splunk,项目名称:SA-ctf_scoreboard,代码行数:31,代码来源:validators.py


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