
    K]neG                       U d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 ddl
mZmZmZmZmZ ddlmZ ddlmZmZ ddlmZmZmZ eeef   Ze	eef   Zee   Ze G d	 d
e              Z!d<dZ"d<dZ#d=dZ$	 	 	 	 	 	 d>dZ%	 	 	 	 	 	 d?dZ&	 	 	 	 	 	 d?dZ'	 	 	 	 	 	 d@dZ( e)        e)        e)       f	 	 	 	 	 dAdZ* e)        e)        e)       f	 	 	 	 	 dAdZ+ e)        e)        e)       f	 	 	 	 	 dAdZ, e)        e)        e)       f	 	 	 	 	 dAdZ- e)        e)        e)       f	 	 	 	 	 dAdZ. e)        e)        e)       f	 	 	 	 	 dAdZ/ e)        e)        e)       f	 	 	 	 	 dAdZ0 ede" e*h dh dh d      e% e.h dh dh d            Z1 ede" e+h d h d!h d      e& e/h d h d!h d            Z2 ed"e# e,h d#h d!h d$      e' e0h d#h d!h d$            Z3 ed%e# e,h d&h d!h d$      e' e0h d&h d!h d$            Z4 ed'e$ e-d(hh d!h d$      e( e0h d)h d!h d$            Z5 ed*e$ e-d+hh d$,      e( e0d-d.hd+hh d$            Z6 ed/e1fd0e2fd1e3fd2e4fd3e5fd4e6ffD  ci c]  \  } }|  ejn                  |       c}}       Z8d5e9d6<   	 dB	 	 	 	 	 dCd8Z:e G d9 d:             Z;dDd;Z<y7c c}} w )EzI
Referencing implementations for JSON Schema specs (historic & current).
    )annotations)SequenceSet)AnyIterableUnion)AnchorRegistryResourceSpecification
exceptions)frozen)ResolvedResolver)URIr	   Mappingc                      e Zd ZU dZded<   y)UnknownDialectz
    A dialect identifier was found for a dialect unknown by this library.

    If it's a custom ("unofficial") dialect, be sure you've registered it.
    r   uriN)__name__
__module____qualname____doc____annotations__     6lib/python3.12/site-packages/referencing/jsonschema.pyr   r      s     
Hr   r   c                F    t        | t              ry | j                  d      S )N$id)
isinstanceboolget)contentss    r   
_dollar_idr$   $   s    (D!<<r   c                |    t        | t              sd| v ry | j                  d      }||j                  d      s|S y y )N$refr   #)r    r!   r"   
startswithr#   ids     r   _legacy_dollar_idr+   *   s@    (D!Vx%7	e	B	~bmmC0	 1~r   c                \    d| v ry | j                  d      }||j                  d      s|S y y )Nr&   r*   r'   )r"   r(   r)   s     r   
_legacy_idr-   2   s7    	d	B	~bmmC0	 1~r   c              #     K   t        |t              ry |j                  d      }|t        || j	                  |             |j                  d      }|t        || j	                  |             y y w)N$anchornameresourcez$dynamicAnchor)r    r!   r"   r	   create_resourceDynamicAnchor)specificationr#   anchordynamic_anchors       r   _anchorr8   :   s      (D!\\)$F"228<
 	

 \\"23N!"228<
 	
 "s   A6A8c                    t        |t              rg S |j                  d      }|g S t        || j	                  |            gS )Nr/   r0   )r    r!   r"   r	   r3   )r5   r#   r6   s      r   _anchor_2019r:   O   sN     (D!	\\)$F~	"228<	
 r   c                    t        |t              rg S |j                  dd      }|j                  d      sg S t	        |dd  | j                  |            gS )Nr    r'      r0   )r    r!   r"   r(   r	   r3   r5   r#   r*   s      r   _legacy_anchor_in_dollar_idr?   `   s]     (D!		eR	 B==	AB"228<	
 r   c                    |j                  dd      }|j                  d      sg S t        |dd  | j                  |            gS )Nr*   r<   r'   r=   r0   )r"   r(   r	   r3   r>   s      r   _legacy_anchor_in_idrA   q   sN     
dB	B==	AB"228<	
 r   c                     d fd}|S )z
    Create a callable returning JSON Schema specification-style subschemas.

    Relies on specifying the set of keywords containing subschemas in their
    values, in a subobject's values, or in a subarray.
    c              3     K   t        | t              ry D ]  }|| v s| |     D ]  }|| v s| |   E d {     D ]"  }|| v s| |   j                         E d {    $ y 7 .7 	wN)r    r!   values)r#   eachin_subarrayin_subvaluesin_values     r   subresources_ofz)_subresources_of.<locals>.subresources_of   s     h% 	%Dxtn$	%   	*Dx#D>))	* ! 	3Dx#D>00222	3 * 3s1   A-A-A-A)A-A-!A+"A-+A-r#   SchemareturnIterable[ObjectSchema]r   rI   rH   rG   rJ   s   ``` r   _subresources_ofrP      s    3 r   c                     d fd}|S )O
    Specifically handle older drafts where there are some funky keywords.
    c              3  H  K   t        | t              ry D ]  }|| v s| |     D ]  }|| v s| |   E d {     D ]"  }|| v s| |   j                         E d {    $ | j                  d      }| t        |t              r|E d {    y | y y 7 a7 <7 wNitems)r    r!   rE   r"   r   )r#   rF   rU   rG   rH   rI   s      r   rJ   z:_subresources_of_with_crazy_items.<locals>.subresources_of   s     h% 	%Dxtn$	%   	*Dx#D>))	* ! 	3Dx#D>00222	3 W%%*   	  * 3
 !sC   B"B"B"BB"B"!B".B"B B"B" B"rK   r   rO   s   ``` r   !_subresources_of_with_crazy_itemsrV      s    ( r   c                     d fd}|S )rR   c              3    K   t        | t              ry D ]  }|| v s| |     D ]  }|| v s| |   E d {     D ]"  }|| v s| |   j                         E d {    $ | j                  d      }|t        |t              r|E d {    n| | j                  d      }|Et        |j                               }t        |d       }t        |t              r| |E d {    y y y 7 7 7 f7 wNrU   dependencies)r    r!   rE   r"   r   iternextr   	r#   rF   rU   rZ   rE   valuerG   rH   rI   s	         r   rJ   zG_subresources_of_with_crazy_items_dependencies.<locals>.subresources_of   s$    h% 	%Dxtn$	%   	*Dx#D>))	* ! 	3Dx#D>00222	3 W%%*   ||N3#,--/0F&E%)!!! * $ * 3
 ! "sV   C;C;C;C3C;C;!C5".C;C7AC;+C9,C;5C;7C;9C;rK   r   rO   s   ``` r   ._subresources_of_with_crazy_items_dependenciesr_      s    "6 r   c                     d fd}|S )zT
    Specifically handle even older drafts where there are some funky keywords.
    c              3  .  K   D ]  }|| v s| |     D ]  }|| v s| |   E d {     D ]"  }|| v s| |   j                         E d {    $ | j                  d      }|t        |t              r|E d {    n| | j                  d      }|Ct	        |j                               }t        |d       }t        |t              r| |E d {    dD ](  }| j                  |      }t        |t              s%| * y 7 7 7 7 8w)NrU   rZ   )additionalItemsadditionalProperties)rE   r"   r    r   r[   r\   r   r]   s	         r   rJ   zJ_subresources_of_with_crazy_aP_items_dependencies.<locals>.subresources_of   s9     	%Dxtn$	%   	*Dx#D>))	* ! 	3Dx#D>00222	3 W%%*   ||N3#,--/0F&E%)!!!= 	DLL&E%)	' * 3
 ! "s[   
DDDDDDD.D?D ADD*DDDDD)r#   ObjectSchemarM   rN   r   rO   s   ``` r   1_subresources_of_with_crazy_aP_items_dependenciesre      s    < r   c                2     ||z  	 	 	 	 	 	 	 	 d fd}|S )Nc                |    t        |       }|D ]  }|vs|vst        |d       |c S  |j                  |      S rD   )r[   r\   in_subresourcesegmentsresolversubresource	_segmentssegmentin_childrI   s        r   maybe_in_subresourcez3_maybe_in_subresource.<locals>.maybe_in_subresource  sQ    
 N	  	 Gh&x'4	4+@+H		 
 &&{33r   rj   zSequence[int | str]rk   _Resolver[Any]rl   zResource[Any]rM   rr   r   rI   rH   rG   rp   ro   s   `   @r   _maybe_in_subresourcert     s@    
 k)H4%4 4 #4 
	4  r   c                2     ||z  	 	 	 	 	 	 	 	 d fd}|S )Nc                    t        |       }|D ]M  }|dk(  r-t        |j                  t              r|j	                  |      c S |vs:|vst        |d       K|c S  |j	                  |      S rT   r[   r    r#   r   rh   r\   ri   s        r   rp   z?_maybe_in_subresource_crazy_items.<locals>.maybe_in_subresource+  s    
 N	  		 G'!j$$'  ..{;;h&x'4	4+@+H		  &&{33r   rq   r   rs   s   `   @r   !_maybe_in_subresource_crazy_itemsrx   $  s@    
 k)H4%4 4 #4 
	4$  r   c                2     ||z  	 	 	 	 	 	 	 	 d fd}|S )Nc                    t        |       }|D ]R  }|dk(  s|dk(  r-t        |j                  t              r|j	                  |      c S |vs?|vst        |d       P|c S  |j	                  |      S rY   rw   ri   s        r   rp   zL_maybe_in_subresource_crazy_items_dependencies.<locals>.maybe_in_subresourceG  s    
 N	  	 G7"g&?[117;..{;;h&x'4	4+@+H	  &&{33r   rq   r   rs   s   `   @r   ._maybe_in_subresource_crazy_items_dependenciesr{   @  s@    
 k)H4%4 4 #4 
	4"  r   zdraft2020-12>   ifnotelsethenrU   containscontentSchemapropertyNamesunevaluatedItemsrc   unevaluatedProperties>   allOfanyOfoneOfprefixItems>   $defs
propertiesdependentSchemaspatternProperties)rI   rG   rH   )r1   id_ofrJ   
anchors_inrp   zdraft2019-09>   r|   r}   r~   r   r   r   r   rb   r   rc   r   >   r   r   r   zdraft-07>   r|   r}   r~   r   r   r   rb   rc   >   r   definitionsr   zdraft-06>   r}   r   r   rb   rc   zdraft-04r}   >   r}   rb   rc   zdraft-03extends)rG   rH   rb   rc   z,https://json-schema.org/draft/2020-12/schemaz,https://json-schema.org/draft/2019-09/schemaz&http://json-schema.org/draft-07/schemaz&http://json-schema.org/draft-06/schemaz&http://json-schema.org/draft-04/schemaz&http://json-schema.org/draft-03/schemazRegistry[Specification[Schema]]_SPECIFICATIONSNc                    t         j                  | j                  d            }||j                  S |t	        |       |S )z
    Retrieve the `Specification` with the given dialect identifier.

    Raises:

        `UnknownDialect`

            if the given ``dialect_id`` isn't known
    r'   )r   r"   rstripr#   r   )
dialect_iddefaultr2   s      r   specification_withr   -  sF     "":#4#4S#9:H   Z((Nr   c                  .    e Zd ZU dZded<   ded<   ddZy)	r4   z4
    Dynamic anchors, introduced in draft 2020.
    strr1   zResource[Schema]r2   c                P   | j                   }|j                         D ]I  \  }}	 |j                  || j                        j                  }t        |t              s>|j                   }K t        |j                  |j                  |            S # t
        j                  $ r Y w xY w)z2
        Resolve this anchor dynamically.
        )r#   rk   )r2   dynamic_scoper6   r1   r^   r   NoSuchAnchorr    r4   	_Resolvedr#   rh   )selfrk   lastr   registryr6   s         r   resolvezDynamicAnchor.resolveK  s     }}%335 	'MC!dii8>> &-0	' ]],,T2
 	
	 ** s   &BB%$B%Nrk   z_Resolver[Schema]rM   z_Resolved[Schema])r   r   r   r   r   r   r   r   r   r4   r4   B  s     I
r   r4   c                X   | j                  d      }t        |j                  t              r~|j                  j	                  d      rc| j                         D ]P  \  }}| j                  |      }t        |j                  t              r|j                  j	                  d      s |S |}R |S )u   
    Recursive references (via recursive anchors), present only in draft 2019.

    As per the 2019 specification (§ 8.2.4.2.1), only the ``#`` recursive
    reference is supported (and is therefore assumed to be the relevant
    reference).
    r'   z$recursiveAnchor)lookupr    r#   r   r"   r   )rk   resolvedr   _next_resolveds        r   lookup_recursive_refr   ]  s     s#H(##W-(2C2C2G2G3 ,,. 	%FC$OOC0M&& #++//0BCO %H	% Or   )r#   rL   rM   
URI | None)r#   rd   rM   r   )r5   Specification[Schema]r#   rL   rM   zIterable[AnchorType[Schema]])r5   r   r#   rL   rM   zIterable[Anchor[Schema]])r5   zSpecification[ObjectSchema]r#   rd   rM   zIterable[Anchor[ObjectSchema]])rI   Set[str]rH   r   rG   r   rD   )r   r   r   Specification[Any]rM   r   r   )=r   
__future__r   collections.abcr   r   typingr   r   r   referencingr	   r
   r   r   r   referencing._attrsr   referencing._corer   r   r   	_Resolverreferencing.typingr   
AnchorTyper   r   rd   r!   rL   SchemaRegistry	Exceptionr   r$   r+   r-   r8   r:   r?   rA   	frozensetrP   rV   r_   re   rt   rx   r{   DRAFT202012DRAFT201909DRAFT7DRAFT6DRAFT4DRAFT3opaquer   r   r   r4   r   )r   r5   s   00r   <module>r      s   # ) ' ' M M % J A A sCx  
t\!	" &! Y  
(

 "
*( "( ". $  #&[%K : #&[%K B #&[%K$$$ $P #&[%K''' 'V #&[%K     0 #&[%K     : #&[%K     8 	
$
 ?
, .
 ?
50d 	
5
 0
, :
 0
50d 
	
B	
 0G +G	
 0G% 
D 
	
B
 0G
 +G
 0G

8 
	
E/G
 $GC/G
  
	
EKG $G#%;<KG
  4< <[I;[I5v>5v>5v>5v>*

%J 	OHOOM22
40 " #' * 
 
 
4}
s   2J;
