Share code.
This commit is contained in:
@@ -7,3 +7,7 @@ Resolving JSON References
|
|||||||
|
|
||||||
.. autoclass:: RefResolver
|
.. autoclass:: RefResolver
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
.. autoexception:: RefResolutionError
|
||||||
|
|
||||||
|
A JSON reference failed to resolve.
|
||||||
|
@@ -94,6 +94,7 @@ adhere to.
|
|||||||
|
|
||||||
:type type: str
|
:type type: str
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
|
:raises: :exc:`UnknownType` if ``type`` is not a known type.
|
||||||
|
|
||||||
The special type ``"any"`` is valid for any given instance.
|
The special type ``"any"`` is valid for any given instance.
|
||||||
|
|
||||||
|
@@ -54,6 +54,23 @@ FLOAT_TOLERANCE = 10 ** -15
|
|||||||
validators = {}
|
validators = {}
|
||||||
|
|
||||||
|
|
||||||
|
class _Error(Exception):
|
||||||
|
def __init__(self, message, validator=None, path=()):
|
||||||
|
super(_Error, self).__init__(message, validator, path)
|
||||||
|
self.message = message
|
||||||
|
self.path = list(path)
|
||||||
|
self.validator = validator
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.message
|
||||||
|
|
||||||
|
|
||||||
|
class SchemaError(_Error): pass
|
||||||
|
class ValidationError(_Error): pass
|
||||||
|
class RefResolutionError(Exception): pass
|
||||||
|
class UnknownType(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
def validates(version):
|
def validates(version):
|
||||||
"""
|
"""
|
||||||
Register the decorated validator for a ``version`` of the specification.
|
Register the decorated validator for a ``version`` of the specification.
|
||||||
@@ -72,31 +89,6 @@ def validates(version):
|
|||||||
return _validates
|
return _validates
|
||||||
|
|
||||||
|
|
||||||
class UnknownType(Exception):
|
|
||||||
"""
|
|
||||||
An attempt was made to check if an instance was of an unknown type.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class RefResolutionError(Exception):
|
|
||||||
"""
|
|
||||||
A JSON reference failed to resolve.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class SchemaError(Exception):
|
|
||||||
def __init__(self, message, validator=None, path=()):
|
|
||||||
super(SchemaError, self).__init__(message, validator, path)
|
|
||||||
self.message = message
|
|
||||||
self.path = list(path)
|
|
||||||
self.validator = validator
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.message
|
|
||||||
|
|
||||||
|
|
||||||
class ValidationError(Exception):
|
class ValidationError(Exception):
|
||||||
def __init__(self, message, validator=None, path=()):
|
def __init__(self, message, validator=None, path=()):
|
||||||
# Any validator that recurses (e.g. properties and items) must append
|
# Any validator that recurses (e.g. properties and items) must append
|
||||||
|
Reference in New Issue
Block a user