summaryrefslogtreecommitdiff
path: root/jsonschema
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-25 14:17:55 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-25 14:17:55 +0100
commit9a62047b5d1cb21444dbf8fc7b8e03708d6979f8 (patch)
treebb8eaaf07d3ca943d38b74733d6d143b56846b6d /jsonschema
parentbeea67bf274af08cf91064d61f647c3c1e8ae2d5 (diff)
downloadjsonschema-9a62047b5d1cb21444dbf8fc7b8e03708d6979f8.tar.gz
Temporarily simplify _finditem, and unskip some tests.
_finditem will be removed (in favor of more robust finding of scope changes), so this won't matter much, but it's tidier.
Diffstat (limited to 'jsonschema')
-rw-r--r--jsonschema/tests/test_jsonschema_test_suite.py36
-rw-r--r--jsonschema/validators.py23
2 files changed, 13 insertions, 46 deletions
diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py
index 6a367dd..2d72031 100644
--- a/jsonschema/tests/test_jsonschema_test_suite.py
+++ b/jsonschema/tests/test_jsonschema_test_suite.py
@@ -193,18 +193,6 @@ TestDraft4 = DRAFT4.to_unittest_testcase(
or skip(
message=bug(371),
subject="ref",
- case_description="Location-independent identifier",
- )(test)
- or skip(
- message=bug(371),
- subject="ref",
- case_description=(
- "Location-independent identifier with absolute URI"
- ),
- )(test)
- or skip(
- message=bug(371),
- subject="ref",
case_description=(
"Location-independent identifier with "
"base URI change in subschema"
@@ -253,18 +241,6 @@ TestDraft6 = DRAFT6.to_unittest_testcase(
or skip(
message=bug(371),
subject="ref",
- case_description="Location-independent identifier",
- )(test)
- or skip(
- message=bug(371),
- subject="ref",
- case_description=(
- "Location-independent identifier with absolute URI"
- ),
- )(test)
- or skip(
- message=bug(371),
- subject="ref",
case_description=(
"Location-independent identifier with "
"base URI change in subschema"
@@ -298,18 +274,6 @@ TestDraft7 = DRAFT7.to_unittest_testcase(
or skip(
message=bug(371),
subject="ref",
- case_description="Location-independent identifier",
- )(test)
- or skip(
- message=bug(371),
- subject="ref",
- case_description=(
- "Location-independent identifier with absolute URI"
- ),
- )(test)
- or skip(
- message=bug(371),
- subject="ref",
case_description=(
"Location-independent identifier with "
"base URI change in subschema"
diff --git a/jsonschema/validators.py b/jsonschema/validators.py
index 9ad5016..3ecf607 100644
--- a/jsonschema/validators.py
+++ b/jsonschema/validators.py
@@ -1,6 +1,7 @@
"""
Creation and extension of validators, with implementations for existing drafts.
"""
+from collections import deque
from collections.abc import Sequence
from functools import lru_cache
from urllib.parse import unquote, urldefrag, urljoin, urlsplit
@@ -717,16 +718,14 @@ class RefResolver(object):
self.pop_scope()
def _finditem(self, schema, key):
- results = []
- if isinstance(schema, dict):
- if key in schema:
- results.append(schema)
-
- for v in schema.values():
- if isinstance(v, dict):
- results += self._finditem(v, key)
-
- return results
+ values = deque([schema])
+ while values:
+ each = values.pop()
+ if not isinstance(each, dict):
+ continue
+ if key in each:
+ yield each
+ values.extendleft(each.values())
def resolve(self, ref):
"""
@@ -786,6 +785,10 @@ class RefResolver(object):
for subschema in self._finditem(document, keyword):
if fragment == subschema[keyword]:
return subschema
+ for keyword in ["id", "$id"]:
+ for subschema in self._finditem(document, keyword):
+ if "#" + fragment == subschema[keyword]:
+ return subschema
# Resolve via path
parts = unquote(fragment).split("/") if fragment else []