summaryrefslogtreecommitdiff
path: root/jsonschema/_utils.py
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2022-05-05 16:54:57 -0400
committerJulian Berman <Julian@GrayVines.com>2022-05-05 16:55:32 -0400
commitfb85c6620ff26823362ebd27b8577995c0841028 (patch)
treee6c6ed824a02cf725079f22965610da57bdfeacd /jsonschema/_utils.py
parent3b2f0f36c73b61fd72a87ab468e46b24119ae9e0 (diff)
downloadjsonschema-fb85c6620ff26823362ebd27b8577995c0841028.tar.gz
Revert "Extend dynamicRef keyword"v4.5.1
It needs performance optimization. See python-jsonschema/jsonschema#941. This reverts commit 12c791ee81baf27e54d18baf95b975bd48387dc6.
Diffstat (limited to 'jsonschema/_utils.py')
-rw-r--r--jsonschema/_utils.py83
1 files changed, 0 insertions, 83 deletions
diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py
index a4ab2ad..a2ad5a9 100644
--- a/jsonschema/_utils.py
+++ b/jsonschema/_utils.py
@@ -1,4 +1,3 @@
-from collections import deque
from collections.abc import Mapping, MutableMapping, Sequence
from urllib.parse import urlsplit
import itertools
@@ -347,85 +346,3 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
)
return evaluated_keys
-
-
-def _schema_is_referenced(schema, parent_schema):
- """
- Checks if a schema is referenced by another schema
- """
- return (
- "$id" in schema
- and "$ref" in parent_schema
- and parent_schema["$ref"] == schema["$id"]
- )
-
-
-def _find_dynamic_anchor_extender(validator, scopes, fragment, schema):
- """
- Find a schema that extends the dynamic anchor
- """
- for url in scopes:
- with validator.resolver.resolving(url) as parent_schema:
- if _schema_is_referenced(schema, parent_schema):
- return validator.resolver.resolve_fragment(
- parent_schema,
- fragment,
- )
-
-
-def _find_dynamic_anchor_intermediate(validator, scopes, fragment):
- """
- Find a schema that extends the dynamic anchor by an intermediate schema
- """
- for url in scopes:
- with validator.resolver.resolving(url) as schema:
- if "$id" in schema:
- for intermediate_url in scopes:
- with validator.resolver.resolving(
- intermediate_url) as intermediate_schema:
- for subschema in search_schema(
- intermediate_schema, match_keyword("$ref")):
- if _schema_is_referenced(subschema, schema):
- return _find_dynamic_anchor_extender(
- validator,
- scopes,
- fragment,
- subschema,
- )
-
-
-def dynamic_anchor_extender(validator, scopes, fragment, schema, subschema):
- extender_schema = _find_dynamic_anchor_extender(
- validator, scopes, fragment, schema,
- )
- if not extender_schema:
- extender_schema = _find_dynamic_anchor_extender(
- validator, scopes, fragment, subschema,
- )
- if not extender_schema:
- extender_schema = _find_dynamic_anchor_intermediate(
- validator, scopes, fragment,
- )
-
- return extender_schema
-
-
-def match_keyword(keyword):
- def matcher(value):
- if keyword in value:
- yield value
- return matcher
-
-
-def search_schema(schema, matcher):
- """Breadth-first search routine."""
- values = deque([schema])
- while values:
- value = values.pop()
- if isinstance(value, list):
- values.extendleft(value)
- continue
- if not isinstance(value, dict):
- continue
- yield from matcher(value)
- values.extendleft(value.values())