o
    eG                  
   @  sx  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
 d
e Z!ddddZ"ddddZ#deddZ$dfddZ%dgddZ&dgddZ'dhd"d#Z(e) e) e) fdid(d)Z*e) e) e) fdid*d+Z+e) e) e) fdid,d-Z,e) e) e) fdid.d/Z-e) e) e) fdid0d1Z.e) e) e) fdid2d3Z/e) e) e) fdid4d5Z0ed6e"e*h d7h d8h d9d:e%e.h d7h d8h d9d:d;Z1ed<e"e+h d=h d>h d9d:e&e/h d=h d>h d9d:d;Z2ed?e#e,h d@h d>h dAd:e'e0h d@h d>h dAd:d;Z3edBe#e,h dCh d>h dAd:e'e0h dCh d>h dAd:d;Z4edDe$e-dEhh d>h dAd:e(e0h dFh d>h dAd:d;Z5edGe$e-dHhh dAdIe(e0dJdKhdHhh dAd:d;Z6edLdM dNe1fdOe2fdPe3fdQe4fdRe5fdSe6ffD Z7dTe8dU< 	Vdjdkd[d\Z9eG d]d^ d^Z:dldbdcZ;dVS )mzI
Referencing implementations for JSON Schema specs (historic & current).
    )annotations)SequenceSet)AnyIterableUnion)AnchorRegistryResourceSpecification
exceptions)frozen)ResolvedResolver)URIr   Mappingc                   @  s   e Zd ZU dZded< dS )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__ r   r   FD:\Projects\ConvertPro\env\Lib\site-packages\referencing/jsonschema.pyr      s   
 r   contentsSchemareturn
URI | Nonec                 C  s   t | trd S | dS )N$id)
isinstanceboolget)r   r   r   r   
_dollar_id$   s   

r#   c                 C  s>   t | ts	d| v rd S | d}|d ur|ds|S d S d S )N$refr   #)r    r!   r"   
startswithr   idr   r   r   _legacy_dollar_id*   s   
r)   ObjectSchemac                 C  s4   d| v rd S |  d}|d ur|ds|S d S d S )Nr$   r(   r%   )r"   r&   r'   r   r   r   
_legacy_id2   s   
r+   specificationSpecification[Schema]Iterable[AnchorType[Schema]]c                 c  sd    t |trd S |d}|d urt|| |dV  |d}|d ur0t|| |dV  d S d S )N$anchornameresourcez$dynamicAnchor)r    r!   r"   r   create_resourceDynamicAnchor)r,   r   anchorZdynamic_anchorr   r   r   _anchor:   s    


r6   Iterable[Anchor[Schema]]c                 C  s8   t |trg S |d}|d u rg S t|| |dgS )Nr/   r0   )r    r!   r"   r   r3   )r,   r   r5   r   r   r   _anchor_2019O   s   

r8   c                 C  sD   t |trg S |dd}|dsg S t|dd  | |dgS )Nr    r%      r0   )r    r!   r"   r&   r   r3   r,   r   r(   r   r   r   _legacy_anchor_in_dollar_id`   s   


r<   Specification[ObjectSchema]Iterable[Anchor[ObjectSchema]]c                 C  s6   | dd}|dsg S t|dd  | |dgS )Nr(   r9   r%   r:   r0   )r"   r&   r   r3   r;   r   r   r   _legacy_anchor_in_idq   s   

r?   in_valueSet[str]in_subvaluesin_subarrayc                      d fd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.
    r   r   r   Iterable[ObjectSchema]c                 3  st    t | trd S D ]}|| v r| | V  q
 D ]}|| v r%| | E d H  qD ]}|| v r7| |  E d H  q(d S N)r    r!   values)r   eachrC   rB   r@   r   r   subresources_of   s    

z)_subresources_of.<locals>.subresources_ofNr   r   r   rE   r   r@   rB   rC   rJ   r   rI   r   _subresources_of   s   rM   c                   rD   )	O
    Specifically handle older drafts where there are some funky keywords.
    r   r   r   rE   c                 3  s    t | trd S D ]}|| v r| | V  q
 D ]}|| v r%| | E d H  qD ]}|| v r7| |  E d H  q(| d}|d urRt |trM|E d H  d S |V  d S d S Nitems)r    r!   rG   r"   r   )r   rH   rP   rI   r   r   rJ      s*   




z:_subresources_of_with_crazy_items.<locals>.subresources_ofNrK   r   rL   r   rI   r   !_subresources_of_with_crazy_items   s   	rQ   c                   rD   )	rN   r   r   r   rE   c                 3  s    t | trd S D ]}|| v r| | V  q
 D ]}|| v r%| | E d H  qD ]}|| v r7| |  E d H  q(| d}|d urOt |trL|E d H  n|V  | d}|d urrt| }t|d }t |trt|V  |E d H  d S d S d S NrP   dependencies)r    r!   rG   r"   r   iternextr   r   rH   rP   rS   rG   valuerI   r   r   rJ      s:   






zG_subresources_of_with_crazy_items_dependencies.<locals>.subresources_ofNrK   r   rL   r   rI   r   ._subresources_of_with_crazy_items_dependencies   s   	rX   c                   rD   )	zT
    Specifically handle even older drafts where there are some funky keywords.
    r   r*   r   rE   c                 3  s    D ]}|| v r| | V  q D ]}|| v r| | E d H  qD ]}|| v r0| |   E d H  q!| d}|d urHt|trE|E d H  n|V  | d}|d urit|  }t|d }t|tri|V  |E d H  dD ]}| |}t|trz|V  qkd S )NrP   rS   )additionalItemsadditionalProperties)rG   r"   r    r   rT   rU   r   rV   rI   r   r   rJ      s>   








zJ_subresources_of_with_crazy_aP_items_dependencies.<locals>.subresources_ofN)r   r*   r   rE   r   rL   r   rI   r   1_subresources_of_with_crazy_aP_items_dependencies   s   	r[   c                      ||B  d
 fdd	}|S )NsegmentsSequence[int | str]resolver_Resolver[Any]subresourceResource[Any]r   c                   sB   t | }|D ]}|vr| vst|d d u r|  S q||S rF   )rT   rU   in_subresourcer]   r_   ra   Z	_segmentssegmentZin_childr@   r   r   maybe_in_subresource  s   
z3_maybe_in_subresource.<locals>.maybe_in_subresourcer]   r^   r_   r`   ra   rb   r   r`   r   r@   rB   rC   rg   r   rf   r   _maybe_in_subresource  s   rj   c                   r\   )Nr]   r^   r_   r`   ra   rb   r   c                   sd   t | }|D ]&}|dkrt|jtr||  S |vr,| vs(t|d d u r,|  S q||S rO   rT   r    r   r   rc   rU   rd   rf   r   r   rg   +  s   

z?_maybe_in_subresource_crazy_items.<locals>.maybe_in_subresourcerh   r   ri   r   rf   r   !_maybe_in_subresource_crazy_items$  s   rl   c                   r\   )Nr]   r^   r_   r`   ra   rb   r   c                   sl   t | }|D ]*}|dks|dkrt|jtr||  S |vr0| vs,t|d d u r0|  S q||S rR   rk   rd   rf   r   r   rg   G  s   

zL_maybe_in_subresource_crazy_items_dependencies.<locals>.maybe_in_subresourcerh   r   ri   r   rf   r   ._maybe_in_subresource_crazy_items_dependencies@  s   rm   zdraft2020-12>   unevaluatedPropertiespropertyNamescontentSchemaunevaluatedItemsifcontainsthenelserP   notrZ   >   ZprefixItemsanyOfoneOfallOf>   z$defspatternProperties
propertiesZdependentSchemas)r@   rC   rB   )r1   Zid_ofrJ   Z
anchors_inrg   zdraft2019-09>   rn   ro   rp   rq   rr   rs   rt   ru   rY   rv   rZ   >   rw   rx   ry   zdraft-07>   ro   rr   rs   rt   ru   rY   rv   rZ   >   r{   rz   Zdefinitionszdraft-06>   ro   rs   rY   rv   rZ   zdraft-04rv   >   rY   rv   rZ   zdraft-03Zextends)rC   rB   rY   rZ   c                 C  s   i | ]
\}}|t |qS r   )r
   opaque).0
dialect_idr,   r   r   r   
<dictcomp>  s    
r   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]]_SPECIFICATIONSNr~   r   defaultSpecification[Any]c                 C  s2   t | d}|dur|jS |du rt| |S )z
    Retrieve the `Specification` with the given dialect identifier.

    Raises:

        `UnknownDialect`

            if the given ``dialect_id`` isn't known
    r%   N)r   r"   rstripr   r   )r~   r   r2   r   r   r   specification_with-  s   r   c                   @  s,   e Zd ZU dZded< ded< dd
dZdS )r4   z4
    Dynamic anchors, introduced in draft 2020.
    strr1   zResource[Schema]r2   r_   _Resolver[Schema]r   _Resolved[Schema]c              	   C  sf   | j }| D ]!\}}z
||| jj}W n
 tjy   Y qw t|tr(|j }qt	|j
||dS )z2
        Resolve this anchor dynamically.
        )r   r_   )r2   dynamic_scoper5   r1   rW   r   ZNoSuchAnchorr    r4   	_Resolvedr   rc   )selfr_   lastr   registryr5   r   r   r   resolveK  s   
zDynamicAnchor.resolveNr_   r   r   r   )r   r   r   r   r   r   r   r   r   r   r4   B  s
   
 r4   r_   r   r   c                 C  sd   |  d}t|jtr0|jdr0|  D ]\}}|  |}t|jtr*|jds- |S |}q|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   )r_   resolvedr   _Znext_resolvedr   r   r   lookup_recursive_ref]  s    


r   )r   r   r   r   )r   r*   r   r   )r,   r-   r   r   r   r.   )r,   r-   r   r   r   r7   )r,   r=   r   r*   r   r>   )r@   rA   rB   rA   rC   rA   rF   )r~   r   r   r   r   r   r   )<r   
__future__r   collections.abcr   r   typingr   r   r   Zreferencingr   r	   r
   r   r   Zreferencing._attrsr   Zreferencing._corer   r   r   Z	_ResolverZreferencing.typingr   Z
AnchorTyper   r   r*   r!   r   ZSchemaRegistry	Exceptionr   r#   r)   r+   r6   r8   r<   r?   	frozensetrM   rQ   rX   r[   rj   rl   rm   ZDRAFT202012ZDRAFT201909ZDRAFT7ZDRAFT6ZDRAFT4ZDRAFT3r   r   r   r4   r   r   r   r   r   <module>   s2   







!(+22

"