o
    tfI                  
   @  s  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 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)SequenceSet)AnyIterable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   _/var/www/html/software/conda/envs/catlas/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   anchorZ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   


r@   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   

rC   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rG   rF   rD   r   r   subresources_of   s    

z)_subresources_of.<locals>.subresources_ofNr   r    r!   rI   r   rD   rF   rG   rN   r   rM   r   _subresources_of   s   rQ   c                   rH   )	O
    Specifically handle older drafts where there are some funky keywords.
    r   r    r!   rI   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%   rK   r&   r   )r   rL   rT   rM   r   r   rN      s*   




z:_subresources_of_with_crazy_items.<locals>.subresources_ofNrO   r   rP   r   rM   r   !_subresources_of_with_crazy_items   s   	rU   c                   rH   )	rR   r   r    r!   rI   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 )NrT   dependencies)r$   r%   rK   r&   r   iternextr   r   rL   rT   rV   rK   valuerM   r   r   rN      s:   






zG_subresources_of_with_crazy_items_dependencies.<locals>.subresources_ofNrO   r   rP   r   rM   r   ._subresources_of_with_crazy_items_dependencies   s   	r[   c                   rH   )	zT
    Specifically handle even older drafts where there are some funky keywords.
    r   r.   r!   rI   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 )NrT   rV   )additionalItemsadditionalProperties)rK   r&   r$   r   rW   rX   r   rY   rM   r   r   rN      s>   








zJ_subresources_of_with_crazy_aP_items_dependencies.<locals>.subresources_ofN)r   r.   r!   rI   r   rP   r   rM   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 rJ   )rW   rX   in_subresourcer`   rb   rd   Z	_segmentssegmentZin_childrD   r   r   maybe_in_subresource  s   
z3_maybe_in_subresource.<locals>.maybe_in_subresourcer`   ra   rb   rc   rd   re   r!   rc   r   rD   rF   rG   rj   r   ri   r   _maybe_in_subresource  s   rm   c                   r_   )Nr`   ra   rb   rc   rd   re   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 rS   rW   r$   r   r   rf   rX   rg   ri   r   r   rj   6     

z?_maybe_in_subresource_crazy_items.<locals>.maybe_in_subresourcerk   r   rl   r   ri   r   !_maybe_in_subresource_crazy_items/     rp   c                   r_   )Nr`   ra   rb   rc   rd   re   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>   rV   rT   rn   rg   ri   r   r   rj   R  ro   zL_maybe_in_subresource_crazy_items_dependencies.<locals>.maybe_in_subresourcerk   r   rl   r   ri   r   ._maybe_in_subresource_crazy_items_dependenciesK  rq   rr   zdraft2020-12>   thencontainspropertyNamesunevaluatedItemsrT   ifelsecontentSchemar]   notunevaluatedProperties>   anyOfallOfoneOfZprefixItems>   
propertiespatternPropertiesz$defsZdependentSchemasdefinitions)rD   rG   rF   )r5   Zid_ofrN   Z
anchors_inrj   zdraft2019-09>   r\   rs   rt   ru   rv   rx   rw   ry   r]   rz   r{   >   r|   r}   r~   zdraft-07>   r\   rs   rt   ru   rw   rx   r]   rz   >   r   r   r   zdraft-06>   r\   rt   ru   r]   rz   zdraft-04rz   >   r\   r]   rz   zdraft-03Zextends)rG   rF   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   rb   _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   rb   )r6   dynamic_scoper9   r5   rZ   r   ZNoSuchAnchorr$   r8   	_Resolvedr   rf   )selfrb   lastr   registryr9   r   r   r   resolve\  s   
zDynamicAnchor.resolveNrb   r   r!   r   )r   r   r   r   r   r   r   r   r   r   r8   S  s
   
 r8   rb   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   )rb   resolvedr   _Z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   rA   r   r.   r!   rB   )rD   rE   rF   rE   rG   rE   )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   r   Z	_Resolverr   Zreferencing.typingr   Z
AnchorTyper   r   r.   r%   r    r   r   r   r   	Exceptionr   r'   r-   r/   r:   r<   r@   rC   	frozensetrQ   rU   r[   r^   rm   rp   rr   ZDRAFT202012ZDRAFT201909ZDRAFT7ZDRAFT6ZDRAFT4ZDRAFT3r   r   r8   r   r   r   r   r   <module>   s6   


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