本文整理汇总了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()`"
)
示例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)
示例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
示例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)
示例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
示例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)
示例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()`",
)
示例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