
    gI                       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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e    Z" e       Z#d	e$d
<   e G d de%             Z&d>dZ'd>dZ(d?dZ)	 	 	 	 	 	 d@dZ*	 	 	 	 	 	 dAdZ+	 	 	 	 	 	 dAdZ,	 	 	 	 	 	 dBdZ- e.        e.        e.       f	 	 	 	 	 dCdZ/ e.        e.        e.       f	 	 	 	 	 dCdZ0 e.        e.        e.       f	 	 	 	 	 dCdZ1 e.        e.        e.       f	 	 	 	 	 dCdZ2 e.        e.        e.       f	 	 	 	 	 dCdZ3 e.        e.        e.       f	 	 	 	 	 dCdZ4 e.        e.        e.       f	 	 	 	 	 dCdZ5 ede' e/h dh dh d      e* e3h dh dh d             Z6 ed!e' e0h d"h d#h d      e+ e4h d"h d#h d             Z7 ed$e( e1h d%h d#h d&      e, e5h d%h d#h d&             Z8 ed'e( e1h d(h d#h d&      e, e5h d(h d#h d&             Z9 ed)e) e2d*hh d#h d&      e- e5h d+h d#h d&             Z: ed,e) e2d-hh d&.      e- e5d/d0hd-hh d&             Z; ed1e6fd2e7fd3e8fd4e9fd5e:fd6e;ffD  ci c]  \  } }| ejy                  |       c}}       Z=d7e$d8<   ef	 	 	 	 	 dDd9Z>e G d: d;             Z?dEd<Z@y=c c}} w )FzI
Referencing implementations for JSON Schema specs (historic & current).
    )annotations)SequenceSet)AnyIterableUnion)AnchorRegistryResourceSpecification
exceptions)frozen)_UNSETResolvedResolver_Unset)URIr	   MappingSchemaRegistryEMPTY_REGISTRYc                      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__     K/var/www/openai/venv/lib/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/   5   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_idr1   =   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!   _anchorr<   E   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 )Nr3   r4   )r$   r%   r&   r	   r7   )r9   r'   r:   s      r!   _anchor_2019r>   Z   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+      r4   )r$   r%   r&   r,   r	   r7   r9   r'   r.   s      r!   _legacy_anchor_in_dollar_idrC   k   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+   rA   r4   )r&   r,   r	   r7   rB   s      r!   _legacy_anchor_in_idrE   |   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>))   !Dx#D>00222 ! * 3s1   A-A-A-A)A-A-!A+"A-+A-r'   SchemareturnIterable[ObjectSchema]r   rM   rL   rK   rN   s   ``` r!   _subresources_ofrT      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%   rI   r&   r   )r'   rJ   rY   rK   rL   rM   s      r!   rN   z:_subresources_of_with_crazy_items.<locals>.subresources_of   s     h%Dxtn$   Dx#D>))   !Dx#D>00222 ! W%%*   	  * 3
 !sC   B"B"B"BB"B"!B".B"B B"B" B"rO   r   rS   s   ``` r!   !_subresources_of_with_crazy_itemsrZ      s    ( r    c                     d fd}|S )rV   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)NrY   dependencies)r$   r%   rI   r&   r   iternextr   	r'   rJ   rY   r]   rI   valuerK   rL   rM   s	         r!   rN   zG_subresources_of_with_crazy_items_dependencies.<locals>.subresources_of   s    h%Dxtn$   Dx#D>))   !Dx#D>00222 ! 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;rO   r   rS   s   ``` r!   ._subresources_of_with_crazy_items_dependenciesrb      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)NrY   r]   )additionalItemsadditionalProperties)rI   r&   r$   r   r^   r_   r   r`   s	         r!   rN   zJ_subresources_of_with_crazy_aP_items_dependencies.<locals>.subresources_of   s%    Dxtn$   Dx#D>))   !Dx#D>00222 ! 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'   ObjectSchemarQ   rR   r   rS   s   ``` r!   1_subresources_of_with_crazy_aP_items_dependenciesrh      s    < r    c                2     ||z  	 	 	 	 	 	 	 	 d fd}|S )Nc                |    t        |       }|D ]  }|vs|vst        |d       |c S  |j                  |      S rH   )r^   r_   in_subresourcesegmentsresolversubresource	_segmentssegmentin_childrM   s        r!   maybe_in_subresourcez3_maybe_in_subresource.<locals>.maybe_in_subresource  sL    
 N	 Gh&x'4	4+@+H	 !
 &&{33r    rm   zSequence[int | str]rn   _Resolver[Any]ro   zResource[Any]rQ   ru   r   rM   rL   rK   rs   rr   s   `   @r!   _maybe_in_subresourcerw     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 rX   r^   r$   r'   r   rk   r_   rl   s        r!   rs   z?_maybe_in_subresource_crazy_items.<locals>.maybe_in_subresource6  sz    
 N	 G'!j$$'  ..{;;h&x'4	4+@+H ! &&{33r    rt   r   rv   s   `   @r!   !_maybe_in_subresource_crazy_itemsr{   /  @    
 k)H4%4 4 #4 
	4$  r    c                2     ||z  	 	 	 	 	 	 	 	 d fd}|S )Nc                    t        |       }|D ]L  }|dv r-t        |j                  t              r|j	                  |      c S |vs9|vst        |d       J|c S  |j	                  |      S )N>   rY   r]   rz   rl   s        r!   rs   zL_maybe_in_subresource_crazy_items_dependencies.<locals>.maybe_in_subresourceR  s{    
 N	 G33
$$9  ..{;;h&x'4	4+@+H ! &&{33r    rt   r   rv   s   `   @r!   ._maybe_in_subresource_crazy_items_dependenciesr   K  r|   r    zdraft2020-12>   ifnotelsethenrY   containscontentSchemapropertyNamesunevaluatedItemsrf   unevaluatedProperties>   allOfanyOfoneOfprefixItems>   $defs
propertiesdefinitionsdependentSchemaspatternProperties)rM   rK   rL   )r5   id_ofrN   
anchors_inrs   zdraft2019-09>   r   r   r   r   r   r   r   re   r   rf   r   >   r   r   r   zdraft-07>   r   r   r   r   r   r   re   rf   >   r   r   r   zdraft-06>   r   r   r   re   rf   zdraft-04r   >   r   re   rf   zdraft-03extends)rK   rL   re   rf   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]]_SPECIFICATIONSc                    t         j                  | j                  d            }||j                  S |t        u r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   r   )
dialect_iddefaultr6   s      r!   specification_withr   =  sI     "":#4#4S#9:H   &Z((Nr    c                  .    e Zd ZU dZded<   ded<   ddZy)	r8   z4
    Dynamic anchors, introduced in draft 2020.
    strr5   SchemaResourcer6   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'   rn   )r6   dynamic_scoper:   r5   ra   r   NoSuchAnchorr$   r8   	_Resolvedr'   rk   )selfrn   lastr   registryr:   s         r!   resolvezDynamicAnchor.resolve\  s     }}%335MC!dii8>> &-0 6 ]],,T2
 	
	 ** s   &BB%$B%Nrn   z_Resolver[Schema]rQ   z_Resolved[Schema])r   r   r   r   r   r   r   r    r!   r8   r8   S  s     I
r    r8   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   )rn   resolvedr   _next_resolveds        r!   lookup_recursive_refr   n  s     s#H(##W-(2C2C2G2G3 ,,.FC$OOC0M&& #++//0BCO %H / Or    N)r'   rP   rQ   
URI | None)r'   rg   rQ   r   )r9   Specification[Schema]r'   rP   rQ   zIterable[AnchorType[Schema]])r9   r   r'   rP   rQ   zIterable[Anchor[Schema]])r9   zSpecification[ObjectSchema]r'   rg   rQ   zIterable[Anchor[ObjectSchema]])rM   Set[str]rL   r   rK   r   )r   r   r   zSpecification[Any] | _UnsetrQ   zSpecification[Any]r   )Ar   
__future__r   collections.abcr   r   typingr   r   r   referencingr	   r
   r   r   r   referencing._attrsr   referencing._corer   r   r   r   	_Resolverr   referencing.typingr   
AnchorTyper   r   rg   r%   rP   r   r   r   r   	Exceptionr   r(   r/   r1   r<   r>   rC   rE   	frozensetrT   rZ   rb   rh   rw   r{   r   DRAFT202012DRAFT201909DRAFT7DRAFT6DRAFT4DRAFT3opaquer   r   r8   r   )r   r9   s   00r!   <module>r      s   # ) ' ' M M %  B A sCx  
t\!	" &! &! "* + Y  
(

 "
*( "( ". $  #&[%K : #&[%K B #&[%K$$$ $P #&[%K''' 'V #&[%K     0 #&[%K     : #&[%K     : 	
$
 ?
. .
 ?
72h 	
5
 0
. :
 0
72h 
	
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 	HOOM22*

40 " ,2( , 
 
 
4
s   K
