Skip to content

Commit 701b2ec

Browse files
committed
Share code.
1 parent c13afc1 commit 701b2ec

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

docs/references.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ Resolving JSON References
77

88
.. autoclass:: RefResolver
99
:members:
10+
11+
.. autoexception:: RefResolutionError
12+
13+
A JSON reference failed to resolve.

docs/validate.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ adhere to.
9494

9595
:type type: str
9696
:rtype: bool
97+
:raises: :exc:`UnknownType` if ``type`` is not a known type.
9798

9899
The special type ``"any"`` is valid for any given instance.
99100

jsonschema.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@
5454
validators = {}
5555

5656

57+
class _Error(Exception):
58+
def __init__(self, message, validator=None, path=()):
59+
super(_Error, self).__init__(message, validator, path)
60+
self.message = message
61+
self.path = list(path)
62+
self.validator = validator
63+
64+
def __str__(self):
65+
return self.message
66+
67+
68+
class SchemaError(_Error): pass
69+
class ValidationError(_Error): pass
70+
class RefResolutionError(Exception): pass
71+
class UnknownType(Exception): pass
72+
73+
5774
def validates(version):
5875
"""
5976
Register the decorated validator for a ``version`` of the specification.
@@ -72,31 +89,6 @@ def _validates(cls):
7289
return _validates
7390

7491

75-
class UnknownType(Exception):
76-
"""
77-
An attempt was made to check if an instance was of an unknown type.
78-
79-
"""
80-
81-
82-
class RefResolutionError(Exception):
83-
"""
84-
A JSON reference failed to resolve.
85-
86-
"""
87-
88-
89-
class SchemaError(Exception):
90-
def __init__(self, message, validator=None, path=()):
91-
super(SchemaError, self).__init__(message, validator, path)
92-
self.message = message
93-
self.path = list(path)
94-
self.validator = validator
95-
96-
def __str__(self):
97-
return self.message
98-
99-
10092
class ValidationError(Exception):
10193
def __init__(self, message, validator=None, path=()):
10294
# Any validator that recurses (e.g. properties and items) must append

0 commit comments

Comments
 (0)