diff options
Diffstat (limited to 'jsonschema/validators.py')
-rw-r--r-- | jsonschema/validators.py | 78 |
1 files changed, 1 insertions, 77 deletions
diff --git a/jsonschema/validators.py b/jsonschema/validators.py index 7044428..fab8201 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -1,6 +1,5 @@ from __future__ import division, unicode_literals -import collections import contextlib import json import numbers @@ -15,6 +14,7 @@ from jsonschema.compat import ( PY3, Sequence, urljoin, urlsplit, urldefrag, unquote, urlopen, str_types, int_types, iteritems, ) +from jsonschema.exceptions import ErrorTree # For backwards compatibility from jsonschema.exceptions import RefResolutionError, SchemaError, UnknownType @@ -379,82 +379,6 @@ class RefResolver(object): return result -class ErrorTree(object): - """ - ErrorTrees make it easier to check which validations failed. - - """ - - _instance = _unset - - def __init__(self, errors=()): - self.errors = {} - self._contents = collections.defaultdict(self.__class__) - - for error in errors: - container = self - for element in error.path: - container = container[element] - container.errors[error.validator] = error - - self._instance = error.instance - - def __contains__(self, index): - """ - Check whether ``instance[index]`` has any errors. - - """ - - return index in self._contents - - def __getitem__(self, index): - """ - Retrieve the child tree one level down at the given ``index``. - - If the index is not in the instance that this tree corresponds to and - is not known by this tree, whatever error would be raised by - ``instance.__getitem__`` will be propagated (usually this is some - subclass of :class:`LookupError`. - - """ - - if self._instance is not _unset and index not in self: - self._instance[index] - return self._contents[index] - - def __setitem__(self, index, value): - self._contents[index] = value - - def __iter__(self): - """ - Iterate (non-recursively) over the indices in the instance with errors. - - """ - - return iter(self._contents) - - def __len__(self): - """ - Same as :attr:`total_errors`. - - """ - - return self.total_errors - - def __repr__(self): - return "<%s (%s total errors)>" % (self.__class__.__name__, len(self)) - - @property - def total_errors(self): - """ - The total number of errors in the entire tree, including children. - - """ - - child_errors = sum(len(tree) for _, tree in iteritems(self._contents)) - return len(self.errors) + child_errors - - def validator_for(schema, default=_unset): if default is _unset: default = Draft4Validator |