Skip to content

Optimize: Allow rules to break error-loop (x2 faster) #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jsonschema/_validators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re

from jsonschema import _utils
from jsonschema.exceptions import FormatError, ValidationError
from jsonschema.exceptions import FormatError, ValidationError, _BreakLoopException
from jsonschema.compat import iteritems


Expand Down Expand Up @@ -196,6 +196,7 @@ def ref(validator, ref, instance, schema):
with validator.resolver.resolving(ref) as resolved:
for error in validator.descend(instance, resolved):
yield error
raise _BreakLoopException()


def type_draft3(validator, types, instance, schema):
Expand Down
12 changes: 8 additions & 4 deletions jsonschema/compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import unicode_literals
import sys

from collections import namedtuple
import operator
import sys


try:
from collections import MutableMapping, Sequence # noqa
Expand All @@ -13,7 +16,7 @@
zip = zip
from io import StringIO
from urllib.parse import (
unquote, urljoin, urlunsplit, SplitResult, urlsplit as _urlsplit
unquote, urljoin, urlunsplit, SplitResult, urlsplit as _urlsplit,
)
from urllib.request import urlopen
str_types = str,
Expand All @@ -23,7 +26,7 @@
from itertools import izip as zip # noqa
from StringIO import StringIO
from urlparse import (
urljoin, urlunsplit, SplitResult, urlsplit as _urlsplit # noqa
urljoin, urlunsplit, SplitResult, urlsplit as _urlsplit, # noqa
)
from urllib import unquote # noqa
from urllib2 import urlopen # noqa
Expand All @@ -40,14 +43,15 @@ def urlsplit(url):
return SplitResult(scheme, netloc, path, query, fragment)


DefragResult = namedtuple('DefragResult', 'url fragment')
def urldefrag(url):
if "#" in url:
s, n, p, q, frag = urlsplit(url)
defrag = urlunsplit((s, n, p, q, ''))
else:
defrag = url
frag = ''
return defrag, frag
return DefragResult(defrag, frag)


# flake8: noqa
2 changes: 2 additions & 0 deletions jsonschema/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def __unicode__(self):
if PY3:
__str__ = __unicode__

class _BreakLoopException(Exception):
pass

class ErrorTree(object):
"""
Expand Down
Loading