Share code.

This commit is contained in:
Julian Berman 2013-02-16 23:55:07 -05:00
parent c13afc120c
commit 701b2ecfcd
3 changed files with 22 additions and 25 deletions

View File

@ -7,3 +7,7 @@ Resolving JSON References
.. autoclass:: RefResolver
:members:
.. autoexception:: RefResolutionError
A JSON reference failed to resolve.

View File

@ -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.

View File

@ -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