o
    RhH                  
   @  s  U d Z ddlmZ ddlmZmZmZ ddl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 de%Z&dgddZ'dgddZ(dhddZ)diddZ*djddZ+djd d!Z,dkd$d%Z-e. e. e. fdld*d+Z/e. e. e. fdld,d-Z0e. e. e. fdld.d/Z1e. e. e. fdld0d1Z2e. e. e. fdld2d3Z3e. e. e. fdld4d5Z4e. e. e. fdld6d7Z5ed8e'e/h d9h d:h d;d<e*e3h d9h d:h d;d<d=Z6ed>e'e0h d?h d@h d;d<e+e4h d?h d@h d;d<d=Z7edAe(e1h dBh d@h dCd<e,e5h dBh d@h dCd<d=Z8edDe(e1h dEh d@h dCd<e,e5h dEh d@h dCd<d=Z9edFe)e2dGhh d@h dCd<e-e5h dHh d@h dCd<d=Z:edIe)e2dJhh dCdKe-e5dLdMhdJhh dCd<d=Z;edNdO dPe6fdQe7fdRe8fdSe9fdTe:fdUe;ffD Z<dVe$dW< efdmd]d^Z=eG d_d` d`Z>dndddeZ?dfS )ozI
Referencing implementations for JSON Schema specs (historic & current).
    )annotations)IterableSequenceSet)AnyUnion)AnchorRegistryResourceSpecification
exceptions)frozen)_UNSETResolvedResolver_Unset)URIr   MappingSchemaRegistryEMPTY_REGISTRYc                   @  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   X/home/air/sanwanet/backup_V2/venv/lib/python3.10/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_id5   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_id=   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)r0   r   anchordynamic_anchorr   r   r   _anchorE   s    


r;   Iterable[Anchor[Schema]]c                 C  s8   t |trg S |d}|d u rg S t|| |dgS )Nr3   r4   )r$   r%   r&   r   r7   )r0   r   r9   r   r   r   _anchor_2019Z   s   

r=   c                 C  sD   t |trg S |dd}|dsg S t|dd  | |dgS )Nr#    r)      r4   )r$   r%   r&   r*   r   r7   r0   r   r,   r   r   r   _legacy_anchor_in_dollar_idk   s   


rA   Specification[ObjectSchema]Iterable[Anchor[ObjectSchema]]c                 C  s6   | dd}|dsg S t|dd  | |dgS )Nr,   r>   r)   r?   r4   )r&   r*   r   r7   r@   r   r   r   _legacy_anchor_in_id|   s   

rD   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rH   rG   rE   r   r   subresources_of   s    

z)_subresources_of.<locals>.subresources_ofNr   r    r!   rJ   r   rE   rG   rH   rO   r   rN   r   _subresources_of   s   rR   c                   rI   )	O
    Specifically handle older drafts where there are some funky keywords.
    r   r    r!   rJ   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%   rL   r&   r   )r   rM   rU   rN   r   r   rO      s*   




z:_subresources_of_with_crazy_items.<locals>.subresources_ofNrP   r   rQ   r   rN   r   !_subresources_of_with_crazy_items   s   	rV   c                   rI   )	rS   r   r    r!   rJ   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 )NrU   dependencies)r$   r%   rL   r&   r   iternextr   r   rM   rU   rW   rL   valuerN   r   r   rO      s:   






zG_subresources_of_with_crazy_items_dependencies.<locals>.subresources_ofNrP   r   rQ   r   rN   r   ._subresources_of_with_crazy_items_dependencies   s   	r\   c                   rI   )	zT
    Specifically handle even older drafts where there are some funky keywords.
    r   r.   r!   rJ   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 )NrU   rW   )additionalItemsadditionalProperties)rL   r&   r$   r   rX   rY   r   rZ   rN   r   r   rO      s>   








zJ_subresources_of_with_crazy_aP_items_dependencies.<locals>.subresources_ofN)r   r.   r!   rJ   r   rQ   r   rN   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 rK   )rX   rY   in_subresourcera   rc   re   	_segmentssegmentin_childrE   r   r   maybe_in_subresource  s   
z3_maybe_in_subresource.<locals>.maybe_in_subresourcera   rb   rc   rd   re   rf   r!   rd   r   rE   rG   rH   rm   r   rk   r   _maybe_in_subresource  s   rp   c                   r`   )Nra   rb   rc   rd   re   rf   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 rT   rX   r$   r   r   rg   rY   rh   rk   r   r   rm   6     

z?_maybe_in_subresource_crazy_items.<locals>.maybe_in_subresourcern   r   ro   r   rk   r   !_maybe_in_subresource_crazy_items/     rs   c                   r`   )Nra   rb   rc   rd   re   rf   r!   c                   sd   t | }|D ]&}|dv rt|jtr||  S |vr,| vs(t|d d u r,|  S q||S )N>   rU   rW   rq   rh   rk   r   r   rm   R  rr   zL_maybe_in_subresource_crazy_items_dependencies.<locals>.maybe_in_subresourcern   r   ro   r   rk   r   ._maybe_in_subresource_crazy_items_dependenciesK  rt   ru   zdraft2020-12>   ifnotelsethenrU   containscontentSchemapropertyNamesunevaluatedItemsr^   unevaluatedProperties>   allOfanyOfoneOfprefixItems>   $defs
propertiesdefinitionsdependentSchemaspatternProperties)rE   rH   rG   )r5   id_ofrO   
anchors_inrm   zdraft2019-09>   rv   rw   rx   ry   rz   r{   r|   r]   r}   r^   r~   >   r   r   r   zdraft-07>   rv   rw   rx   ry   rz   r|   r]   r^   >   r   r   r   zdraft-06>   rw   rz   r|   r]   r^   zdraft-04rw   >   rw   r]   r^   zdraft-03extends)rH   rG   r]   r^   c                 C  s   i | ]
\}}|t |qS r   )r
   opaque).0
dialect_idr0   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]]_SPECIFICATIONSr   r   defaultSpecification[Any] | _UnsetSpecification[Any]c                 C  s2   t | d}|dur|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)   N)r   r&   rstripr   r   r   )r   r   r6   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 )r8   z4
    Dynamic anchors, introduced in draft 2020.
    strr5   SchemaResourcer6   rc   _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   rc   )r6   dynamic_scoper9   r5   r[   r   NoSuchAnchorr$   r8   	_Resolvedr   rg   )selfrc   lastr   registryr9   r   r   r   resolve\  s   
zDynamicAnchor.resolveNrc   r   r!   r   )r   r   r   r   r   r   r   r   r   r   r8   S  s
   
 r8   rc   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   )rc   resolvedr   _next_resolvedr   r   r   lookup_recursive_refn  s    


r   N)r   r    r!   r"   )r   r.   r!   r"   )r0   r1   r   r    r!   r2   )r0   r1   r   r    r!   r<   )r0   rB   r   r.   r!   rC   )rE   rF   rG   rF   rH   rF   )r   r   r   r   r!   r   r   )@r   
__future__r   collections.abcr   r   r   typingr   r   referencingr   r	   r
   r   r   referencing._attrsr   referencing._corer   r   r   r   	_Resolverr   referencing.typingr   
AnchorTyper   r   r.   r%   r    r   r   r   r   	Exceptionr   r'   r-   r/   r;   r=   rA   rD   	frozensetrR   rV   r\   r_   rp   rs   ru   DRAFT202012DRAFT201909DRAFT7DRAFT6DRAFT4DRAFT3r   r   r8   r   r   r   r   r   <module>   s6   


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