@@ -757,6 +757,10 @@ def resolving(self, ref):
757757 finally :
758758 self .pop_scope ()
759759
760+ @lru_cache ()
761+ def _find_in_referrer (self , key ):
762+ return list (self ._finditem (self .referrer , key ))
763+
760764 def _finditem (self , schema , key ):
761765 values = deque ([schema ])
762766 while values :
@@ -773,8 +777,11 @@ def _find_subschemas(self):
773777
774778 @lru_cache ()
775779 def _find_in_subschemas (self , url ):
780+ subschemas = self ._find_subschemas ()
781+ if not subschemas :
782+ return None
776783 uri , fragment = urldefrag (url )
777- for subschema in self . _find_subschemas () :
784+ for subschema in subschemas :
778785 target_uri = self ._urljoin_cache (
779786 self .resolution_scope , subschema ["$id" ],
780787 )
@@ -831,12 +838,19 @@ def resolve_fragment(self, document, fragment):
831838 if not fragment :
832839 return document
833840
841+ if document is self .referrer :
842+ find = self ._find_in_referrer
843+ else :
844+
845+ def find (key ):
846+ return self ._finditem (document , key )
847+
834848 for keyword in ["$anchor" , "$dynamicAnchor" ]:
835- for subschema in self . _finditem ( document , keyword ):
849+ for subschema in find ( keyword ):
836850 if fragment == subschema [keyword ]:
837851 return subschema
838852 for keyword in ["id" , "$id" ]:
839- for subschema in self . _finditem ( document , keyword ):
853+ for subschema in find ( keyword ):
840854 if "#" + fragment == subschema [keyword ]:
841855 return subschema
842856
0 commit comments