
    sg`              	         % S SK Jr  S SKJrJrJr  S SKJr  S SKJ	r	J
r
JrJrJr  S SKJrJrJr  S SKJrJr  S SKJrJrJr   S SKJr  S S	KJr  S S
KJr  S SK J!r!J"r#J$r$J%r%J&r&  \" 5       r'S\(S'   \" 5       r)S\(S'    " S S\5      r*\*RV                  r, " S S\\$   5      r-S0S jr.    S1S jr/ " S S5      r0\ " S S\\$   5      5       r1\1" SS S S S S9\1l2        \ " S  S!\\$   5      5       r3S2S" jr4\ " S# S$\%\!\3\$   4   5      5       r5\" S%\#\	   \3\	   \3\	   S&9r6\ " S' S(\\$\64   5      5       r7\ " S) S*\\$   5      5       r8\ " S+ S,\\$   5      5       r9\ " S- S.\\$   5      5       r"g/! \ a
    S SKJr   GN5f = f)3    )annotations)IterableIteratorSequence)Enum)AnyCallableClassVarGenericProtocol)unquote	urldefragurljoin)evolvefield)HashTrieMapHashTrieSetList)TypeVar)
exceptions)frozen)URIAnchorDMappingRetrieveHashTrieSet[URI]EMPTY_UNCRAWLED	List[URI]EMPTY_PREVIOUS_RESOLVERSc                      \ rS rSrSrSrSrg)_Unset   z
What sillyness...
    N)__name__
__module____qualname____firstlineno____doc__SENTINEL__static_attributes__r%       3/usr/lib/python3/dist-packages/referencing/_core.pyr"   r"      s     Hr-   r"   c                  .    \ rS rSr        SS jrSrg)_MaybeInSubresource#   c                    g Nr%   )selfsegmentsresolversubresources       r.   __call___MaybeInSubresource.__call__$   s    
 r-   r%   N)r5   zSequence[int | str]r6   Resolver[D]r7   Resource[D]returnr:   )r&   r'   r(   r)   r8   r,   r%   r-   r.   r0   r0   #   s-    %  !	
 
r-   r0   c                    [        U [        5      (       d  [        R                  " U 5      eU R	                  S5      n[        U[
        5      (       d  [        R                  " U 5      eSSKJn  U" U5      $ )N$schemar   specification_with)
isinstancer   r   CannotDetermineSpecificationgetstrreferencing.jsonschemar@   )contentsjsonschema_dialect_idr@   s      r.   _detect_or_errorrH   ,   s]    h((55h??$LL3+S1155h??9344r-   c                   ^  SU 4S jjnU$ )Nc                x   > [        U [        5      (       d  T$ U R                  S5      nUc  T$ SSKJn  U" UTS9$ )Nr>   r   r?   default)rA   r   rC   rE   r@   )rF   rG   r@   rL   s      r.   _detect#_detect_or_default.<locals>._detect<   sE    (G,,N (Y 7 (N=!!
 	
r-   rF   r   r<   Specification[D]r%   )rL   rM   s   ` r.   _detect_or_defaultrQ   9   s    
 Nr-   c                  *    \ rS rSr      SS jrSrg)_SpecificationDetectorN   c                *    Uc  [         $ [        U5      $ r3   )rH   rQ   )r4   instanceclss      r.   __get___SpecificationDetector.__get__O   s    
 ##%h//r-   r%   N)rV   zSpecification[D] | NonerW   ztype[Specification[D]]r<   Callable[[D], Specification[D]])r&   r'   r(   r)   rX   r,   r%   r-   r.   rS   rS   N   s#    0)0 $0 
)	0r-   rS   c                      \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   \" SS9rS\S'   S\S'   \" 5       r	SS jr
SS jrSS jrSrg)SpecificationZ   z
A specification which defines referencing behavior.

The various methods of a `Specification` allow for varying referencing
behavior across JSON Schema specification versions, etc.
rD   namezCallable[[D], URI | None]id_ofzCallable[[D], Iterable[D]]subresources_ofz_MaybeInSubresource[D]maybe_in_subresource
anchors_inaliasz8Callable[[Specification[D], D], Iterable[AnchorType[D]]]_anchors_inzClassVar[Specification[Any]]OPAQUEc                $    SU R                   < S3$ )Nz<Specification name=>)r^   r4   s    r.   __repr__Specification.__repr__   s    %dii]!44r-   c                $    U R                  X5      $ )z7
Retrieve the anchors contained in the given document.
)re   r4   rF   s     r.   rb   Specification.anchors_in   s     //r-   c                    [        XS9$ )zB
Create a resource which is interpreted using this specification.
)rF   specification)Resourcerm   s     r.   create_resourceSpecification.create_resource   s     >>r-   r%   Nr<   rD   )rF   r   rF   r   r<   r;   )r&   r'   r(   r)   r*   __annotations__r   re   rS   detectrj   rb   rr   r,   r%   r-   r.   r\   r\   Z   sa     I %$ 0/ 10 	L!   " )(B $%F50?r-   r\   opaquec                    g r3   r%   rF   s    r.   <lambda>r{      s    4r-   c                    / $ r3   r%   rz   s    r.   r{   r{      s    Rr-   c                    / $ r3   r%   )rp   rF   s     r.   r{   r{      s    rr-   c                    U$ r3   r%   r5   r6   r7   s      r.   r{   r{      s    r-   )r^   r_   r`   rb   ra   c                      \ rS rSr% SrS\S'   \" SS9rS\S'   \\	4     SS	 jj5       r
\SS
 j5       rSS jrSS jrSS jrSS jrSrg)rq      an  
A document (deserialized JSON) with a concrete interpretation under a spec.

In other words, a Python object, along with an instance of `Specification`
which describes how the document interacts with referencing -- both
internally (how it refers to other `Resource`\ s) and externally (how it
should be identified such that it is referenceable by other documents).
r   rF   rp   rc   rP   _specificationc                B    UR                  U5      nUR                  US9$ )a  
Create a resource guessing which specification applies to the contents.

Raises:

    `CannotDetermineSpecification`

        if the given contents don't have any discernible
        information which could be used to guess which
        specification they identify as

rz   )rw   rr   )rW   rF   default_specificationrp   s       r.   from_contentsResource.from_contents   s(    ( .44X>,,h,??r-   c                <    [         R                  R                  US9$ )zm
Create an opaque `Resource` -- i.e. one with opaque specification.

See `Specification.OPAQUE` for details.
rz   )r\   rf   rr   )rW   rF   s     r.   rx   Resource.opaque   s     ##33X3FFr-   c                v    U R                   R                  U R                  5      nUc  gUR                  S5      $ )?
Retrieve this resource's (specification-specific) identifier.
N#)r   r_   rF   rstrip)r4   ids     r.   r   Resource.id   s4       &&t}}5:yy~r-   c                b   ^  U 4S jT R                   R                  T R                  5       5       $ )z(
Retrieve this resource's subresources.
c              3  `   >#    U  H#  n[         R                  UTR                  S 9v   M%     g7f))r   N)rq   r   r   ).0eachr4   s     r.   	<genexpr>(Resource.subresources.<locals>.<genexpr>   s:      

 K	 ""&*&9&9 #  Ks   +.)r   r`   rF   ri   s   `r.   subresourcesResource.subresources   s,    

 ++;;DMMJ
 	
r-   c                L    U R                   R                  U R                  5      $ )r   )r   rb   rF   ri   s    r.   anchorsResource.anchors   s     ""--dmm<<r-   c                ,   U(       d  [        U R                  US9$ U R                  n/ n[        USS 5      R                  S5       H  n[	        U[
        5      (       a  [        U5      nO"UR                  SS5      R                  SS5      n X5   nUR                  U5        UnU R                  R                  UUU R                  R                  U5      S	9nX(Ld  M  / nM     [        X2S9$ ! [         a  n[        R                  " XS9nXveSnAff = f)
z
Resolve the given JSON pointer.

Raises:

    `exceptions.PointerToNowhere`

        if the pointer points to a location not present in the document

rF   r6   r$   N/z~1z~0~)refresourcer   )ResolvedrF   r   splitrA   r   intreplaceLookupErrorr   PointerToNowhereappendr   ra   rr   )	r4   pointerr6   rF   r5   segmentlookup_errorerrorlasts	            r.   r   Resource.pointer   s    T]]XFF==$&wqr{+11#6G(H--g,!//$4<<T3G.#,
 OOG$D**??!! //??I @ H
 #' 7( ==  ."33O-.s   C..
D8DDr%   N)rF   r   r   z)type[Specification[D]] | Specification[D]r<   r;   ru   )r<   z
URI | None)r<   zIterable[Resource[D]])r<   zIterable[AnchorType[D]])r   rD   r6   r:   r<   Resolved[D])r&   r'   r(   r)   r*   rv   r   r   classmethodr\   r   rx   r   r   r   r   r,   r%   r-   r.   rq   rq      s     K',?'CN$C @@ 6	@ 
@ @, G G

=$>r-   rq   c                *    [         R                  " U S9e)Nr   )r   NoSuchResource)uris    r.   _fail_to_retriever   %  s    

#
#
,,r-   c                  P   \ rS rSr% Sr\" \" 5       \R                  SS9rS\	S'   \" 5       r
S\	S'   \rS	\	S
'   \" \SS9rS\	S'   S!S jrS"S jrS#S jr    S$S jrS%S jrS&S jrS'S jrS(S jrS)S jrS*S jrS+S jr    S,S jr      S-S jrS.S jrS/S0S jjrS1S jrSrg )2Registryi)  a  
A registry of `Resource`\ s, each identified by their canonical URIs.

Registries store a collection of in-memory resources, and optionally
enable additional resources which may be stored elsewhere (e.g. in a
database, a separate set of files, over the network, etc.).

They also lazily walk their known resources, looking for subresources
within them. In other words, subresources contained within any added
resources will be retrievable via their own IDs (though this discovery of
subresources will be delayed until necessary).

Registries are immutable, and their methods return new instances of the
registry with the additional resources added to them.

The ``retrieve`` argument can be used to configure retrieval of resources
dynamically, either over the network, from a database, or the like.
Pass it a callable which will be called if any URI not present in the
registry is accessed. It must either return a `Resource` or else raise a
`NoSuchResource` exception indicating that the resource does not exist
even according to the retrieval logic.
	resources)rL   	converterrd   zHashTrieMap[URI, Resource[D]]
_resourcesz+HashTrieMap[tuple[URI, str], AnchorType[D]]_anchorsr   
_uncrawledretrieve)rL   rd   zRetrieve[D]	_retrievec                     U R                   UR                  S5         $ ! [         a    [        R                  " US9Sef = f)zF
Return the (already crawled) `Resource` identified by the given URI.
r   r   N)r   r   KeyErrorr   r   r4   r   s     r.   __getitem__Registry.__getitem__K  s@    	???3::c?33 	?++4$>	?s	      A c                ,    [        U R                  5      $ )z0
Iterate over all crawled URIs in the registry.
)iterr   ri   s    r.   __iter__Registry.__iter__T  s     DOO$$r-   c                ,    [        U R                  5      $ )zE
Count the total number of fully crawled resources in this registry.
)lenr   ri   s    r.   __len__Registry.__len__Z  s     4??##r-   c                   [        U[        5      (       a  U4nU R                  nU R                  nU HL  nUR	                  5       nUc  [
        R                  " US9eUR                  U5      nUR                  XT5      nMN     [        XUS9$ )a  
Create a new registry with resource(s) added using their internal IDs.

Resources must have a internal IDs (e.g. the :kw:`$id` keyword in
modern JSON Schema versions), otherwise an error will be raised.

Both a single resource as well as an iterable of resources works, i.e.:

    * ``resource @ registry`` or

    * ``[iterable, of, multiple, resources] @ registry``

which -- again, assuming the resources have internal IDs -- is
equivalent to calling `Registry.with_resources` as such:

.. code:: python

    registry.with_resources(
        (resource.id(), resource) for resource in new_resources
    )

Raises:

    `NoInternalID`

        if the resource(s) in fact do not have IDs

)r   r   	uncrawled)	rA   rq   r   r   r   r   NoInternalIDinsertr   )r4   newr   r   r   r   s         r.   __rmatmul__Registry.__rmatmul__`  s    @ c8$$&COO	OO	HBz --x@@!((,I!((6I  d9EEr-   c                    [        U 5      nUS:X  a  SOSnU R                  (       a)  [        U R                  5      nX1:X  a  SU 3nOU SU S3nOU nSU SU S	3$ )
Nr$   r   r   z
uncrawled z, z
 uncrawledz<Registry ( z)>)r   r   )r4   size
pluralizedr   summarys        r.   rj   Registry.__repr__  sm    4y#'19Z+
??DOO,I &zl3'L9+Z@#GTF!G9B//r-   c                   U R                   R                  U5      nUb	  [        XS9$ U R                  5       nUR                   R                  U5      nUb	  [        X2S9$  UR	                  U5      nUR                  X5      n[        X2S9$ ! [        R                  [        R                  4 a    e [         a  n[        R                  " US9UeSnAff = f)a  
Get a resource from the registry, crawling or retrieving if necessary.

May involve crawling to find the given URI if it is not already known,
so the returned object is a `Retrieved` object which contains both the
resource value as well as the registry which ultimately contained it.
N)registryvaluer   )r   rC   	Retrievedcrawlr   with_resourcer   rB   r   	ExceptionUnretrievable)r4   r   r   r   r   s        r.   get_or_retrieveRegistry.get_or_retrieve  s     ??&&s+d;;::<&&**3/h??	@))#.H  --c<Hh?? 33%%
 	  	?**s3>	?s    B .C9CCc           
       ^ TU R                   ;  a  [        R                  " TS9e[        U U R                   R	                  T5      U R
                  R                  T5      [        U4S jU R                  R                  5        5       5      S9$ )zH
Return a registry with the resource identified by a given URI removed.
r   c              3  D   >#    U  H  u  pUS    T:w  d  M  X4v   M     g7f)r   Nr%   )r   kvr   s      r.   r   "Registry.remove.<locals>.<genexpr>  s%       #841AaDCK#8s    
 )r   r   r   )
r   r   r   r   remover   discardr   r   itemsr   s    `r.   r   Registry.remove  sx     doo%++44oo,,S1oo--c2  #'==#6#6#8  	
 	
r-   c                   U R                   R                  X45      nUb	  [        X0S9$ U R                  5       nUR                   R                  X45      nUb	  [        X4S9$ X   nUR	                  5       nUb(  UR                   R                  Xb45      nUb	  [        X4S9$ SU;   a  [
        R                  " UUUS9e[
        R                  " XUS9e)zH
Retrieve a given anchor from a resource which must already be crawled.
)r   r   r   )r   r   anchor)r   rC   r   r   r   r   InvalidAnchorNoSuchAnchor)r4   r   r^   r   r   r   canonical_uris          r.   r   Registry.anchor  s     !!3+.588::<!!%%sk25<<9 $%%))=*?@E  u@@$;**! 
 %%#NNr-   c                    X   R                   $ )zF
Retrieve the (already crawled) contents identified by the given URI.
rz   r   s     r.   rF   Registry.contents  s     y!!!r-   c                   ^ U R                   nU R                  nU R                   Vs/ s H  o3X   4PM
     nnU(       a  UR                  5       u  mnUR	                  5       nUb  [        TU5      mUR                  TU5      nUR                  5        H!  nUR                  TUR                  4U5      nM#     UR                  U4S jUR                  5        5       5        U(       a  M  [        U UU[        S9$ s  snf )z6
Crawl all added resources, discovering subresources.
c              3  ,   >#    U  H	  nTU4v   M     g 7fr3   r%   )r   r   r   s     r.   r   !Registry.crawl.<locals>.<genexpr>  s     M5LTc4[5Ls   )r   r   r   )r   r   r   popr   r   r   r   r^   extendr   r   r   )r4   r   r   r   r   r   r   r   s      `    r.   r   Registry.crawl  s     OO	--6:ooFos9>*o	F%MMOMCB~c2&%,,S(;	 ((*!..#tyy)94@ +MX5J5J5LMM i %	
 	
 Gs   C;c                (    U R                  X4/5      $ )z@
Add the given `Resource` to the registry, without crawling it.
with_resources)r4   r   r   s      r.   r   Registry.with_resource  s     ""SO#455r-   c                    U R                   nU R                  nU H8  u  pEUR                  S5      nUR                  U5      nUR                  XE5      nM:     [	        XUS9$ )zE
Add the given `Resource`\ s to the registry, without crawling them.
r   r   )r   r   r   r   r   )r4   pairsr   r   r   r   s         r.   r   Registry.with_resources  s`     OO	OO	"MC **S/C!((-I!((7I # d9EEr-   c                :   ^ U R                  U4S jU 5       5      $ )zG
Add the given contents to the registry, autodetecting when necessary.
c              3  Z   >#    U  H   u  pU[         R                  " U40 TD64v   M"     g 7fr3   )rq   r   )r   r   r   kwargss      r.   r   )Registry.with_contents.<locals>.<genexpr>!  s/      #
"	 (((889"s   (+r   )r4   r   r  s     `r.   with_contentsRegistry.with_contents  s%     "" #
"#
 
 	
r-   c                   X4:X  a  U $ U R                   nU R                  nU R                  nU R                  nU H  nUR	                  UR                   5      nUR	                  UR                  5      nUR	                  UR                  5      nUR                  [
        Ld  Mi  UR                  Us=La	  [
        La  O  O[        S5      eUR                  nM     [        U UUUUS9$ )zI
Combine together one or more other registries, producing a unified one.
z?Cannot combine registries with conflicting retrieval functions.)r   r   r   r   )r   r   r   r   updater   
ValueErrorr   )r4   
registriesr   r   r   r   r   s          r.   combineRegistry.combine&  s      KOO	--OO	>>"H!(()<)<=InnX%6%67G!(()<)<=I!!)::%%XN=NN$%  $-- # 
 	
r-   c                    [        XS9$ )zF
Return a `Resolver` which resolves references against this registry.
base_urir   )Resolver)r4   r  s     r.   r6   Registry.resolverD  s     99r-   c                f    UR                  5       =(       d    Sn[        UU R                  X!5      S9$ )z4
Return a `Resolver` with a specific root resource.
 r  )r   r  r   )r4   r   r   s      r.   resolver_with_rootRegistry.resolver_with_rootJ  s2     kkm!r''6
 	
r-   r%   N)r   r   r<   r;   )r<   zIterator[URI])r<   r   )r   z#Resource[D] | Iterable[Resource[D]]r<   Registry[D]rt   )r   r   r<   zRetrieved[D, Resource[D]]r   r   )r   r   r^   rD   )r   r   r<   r   )r<   r  )r   r   r   r;   )r   z!Iterable[tuple[URI, Resource[D]]]r<   r  )r   zIterable[tuple[URI, D]]r  r   r<   r  )r	  r  r<   r  )r  )r  r   r<   r:   )r   r;   r<   r:   ) r&   r'   r(   r)   r*   r   r   convertr   rv   r   r   r   r   r   r   r   r   r   rj   r   r   r   rF   r   r   r   r  r
  r6   r  r,   r%   r-   r.   r   r   )  s    . 16%%1J- 
 =HMH9I#2J 2"+<JOI{O?%$+F0+F 
+FZ0@<
 O8"
06F0F 
F"
&
 
 
	

<:
r-   r   AnchorOrResourcerK   c                  .    \ rS rSr% SrS\S'   S\S'   Srg)	r   i^  z&
A value retrieved from a `Registry`.
r  r   r  r   r%   Nr&   r'   r(   r)   r*   rv   r,   r%   r-   r.   r   r   ^  s     r-   r   c                  .    \ rS rSr% SrS\S'   S\S'   Srg)	r   ih  z7
A reference resolved to its contents by a `Resolver`.
r   rF   r:   r6   r%   Nr  r%   r-   r.   r   r   h  s     Kr-   r   c                      \ rS rSr% Sr\" SS9rS\S'   \" SS9rS\S	'   \" \	" 5       S
SS9r
S\S'   SS jrSS jrSS jrSS jrSrg)r  ir  a  
A reference resolver.

Resolvers help resolve references (including relative ones) by
pairing a fixed base URI with a `Registry`.

This object, under normal circumstances, is expected to be used by
*implementers of libraries* built on top of `referencing` (e.g. JSON Schema
implementations or other libraries resolving JSON references),
not directly by end-users populating registries or while writing
schemas or other resources.

References are resolved against the base URI, and the combined URI
is then looked up within the registry.

The process of resolving a reference may itself involve calculating
a *new* base URI for future reference resolution (e.g. if an
intermediate resource sets a new base URI), or may involve encountering
additional subresources and adding them to a new registry.
r  rc   r   	_base_urir   r  	_registryFprevious)rL   reprrd   r   	_previousc                (   UR                  S5      (       a  U R                  USS p2O![        [        U R                  U5      5      u  p# U R                  R                  U5      nUR                  S5      (       a3  U R                  UR                  US9nUR                  R                  X6S9$ U(       aN  UR                  R                  X#5      nU R                  UR                  US9nUR                  R                  US9$ U R                  UR                  US9n[!        UR                  R"                  US	9$ ! [        R                   a    [        R                  " US9Se[        R                   a  n[        R                  " US9UeSnAff = f)
a5  
Resolve the given reference to the resource it points to.

Raises:

    `exceptions.Unresolvable`

        or a subclass thereof (see below) if the reference isn't
        resolvable

    `exceptions.NoSuchAnchor`

        if the reference is to a URI where a resource exists but
        contains a plain name fragment which does not exist within
        the resource

    `exceptions.PointerToNowhere`

        if the reference is to a URI where a resource exists but
        contains a JSON pointer to a location within the resource
        that does not exist

r   r$   Nr   r   )r   r  )r   r6   )r6   r   )
startswithr  r   r   r  r   r   r   Unresolvabler   _evolver   r   r   r   resolver   rF   )r4   r   r   fragment	retrievedr   r6   s          r.   lookupResolver.lookup  s[   0 >># NNCG%gdnnc&BCMC	>66s;I s##||Y-?-?#|NH??**8*OO!**11#@I||Y-?-?#|NH??**H*==<<););c<J!9!9HMM (( 	=))c2<'' 	>))c2=	>s   
D; ;<F7FFc                h    UR                  5       nUc  U $ [        U [        U R                  U5      S9$ )zF
Create a resolver for a subresource (which may have a new base URI).
)r  )r   r   r   r  )r4   r7   r   s      r.   in_subresourceResolver.in_subresource  s2     ^^:KdWT^^R%@AAr-   c              #  P   #    U R                    H  nXR                  4v   M     g7f)zD
In specs with such a notion, return the URIs in the dynamic scope.
N)r!  r  r   s     r.   dynamic_scopeResolver.dynamic_scope  s"      >>C~~%% "s   $&c                    U R                   nU R                  (       a1  U(       a  XR                  :w  a  UR                  U R                  5      n[        U 4XS.UD6$ )z)
Evolve, appending to the dynamic scope.
)r  r  )r!  r  
push_frontr   )r4   r  r  r  s       r.   r%  Resolver._evolve  sH     >>>>8x>>/I**4>>:HdKXKFKKr-   r%   N)r   r   r<   r   )r7   r;   r<   r:   )r<   z!Iterable[tuple[URI, Registry[D]]])r  r   r  r   )r&   r'   r(   r)   r*   r   r  rv   r  r   r!  r)  r,  r/  r%  r,   r%   r-   r.   r  r  r  sT    * ,Is,"4I{4 e:NIyN-N^B&Lr-   r  c                  8    \ rS rSr% SrS\S'   S\S'   S
S jrSrg	)r   i  z"
A simple anchor in a `Resource`.
rD   r^   r;   r   c                >    [        U R                  R                  US9$ )z&
Return the resource for this anchor.
r   )r   r   rF   )r4   r6   s     r.   r&  Anchor.resolve  s     !7!7(KKr-   r%   N)r6   r:   )r&   r'   r(   r)   r*   rv   r&  r,   r%   r-   r.   r   r     s     ILr-   r   NrO   )rL   rP   r<   rZ   r  ):
__future__r   collections.abcr   r   r   enumr   typingr   r	   r
   r   r   urllib.parser   r   r   attrsr   r   rpdsr   r   r   typing_extensionsr   ImportErrorreferencingr   referencing._attrsr   referencing.typingr   r   
AnchorTyper   r   r   r   rv   r    r"   r+   _UNSETr0   rH   rQ   rS   r\   rf   rq   r   r   r  r   r   r  r%   r-   r.   <module>rE     s   " 8 8  = = 4 4  / /) # % N N$/M! 1&*f ) ,T  
(1+ 
5$*	0 	0 N?GAJ N? N?b %	
'1I  l>wqz l> l>^- h
wsHQK'( h
 h
X	 sOSMSM	  ++,   wqz   `Lwqz `L `LF LWQZ L LU  s   E/ /E?>E?