Share code.
This commit is contained in:
parent
c13afc120c
commit
701b2ecfcd
|
@ -7,3 +7,7 @@ Resolving JSON References
|
|||
|
||||
.. autoclass:: RefResolver
|
||||
:members:
|
||||
|
||||
.. autoexception:: RefResolutionError
|
||||
|
||||
A JSON reference failed to resolve.
|
||||
|
|
|
@ -94,6 +94,7 @@ adhere to.
|
|||
|
||||
:type type: str
|
||||
:rtype: bool
|
||||
:raises: :exc:`UnknownType` if ``type`` is not a known type.
|
||||
|
||||
The special type ``"any"`` is valid for any given instance.
|
||||
|
||||
|
|
|
@ -54,6 +54,23 @@ FLOAT_TOLERANCE = 10 ** -15
|
|||
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):
|
||||
"""
|
||||
Register the decorated validator for a ``version`` of the specification.
|
||||
|
@ -72,31 +89,6 @@ def validates(version):
|
|||
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):
|
||||
def __init__(self, message, validator=None, path=()):
|
||||
# Any validator that recurses (e.g. properties and items) must append
|
||||
|
|
Loading…
Reference in New Issue