o
    viH                  
   @  s  U d Z ddlmZ ddlmZmZmZ ddl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B 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-Z/e- e- e- fdld.d/Z0e- e- e- fdld0d1Z1e- e- e- fdld2d3Z2e- e- e- fdld4d5Z3e- e- e- fdld6d7Z4ed8e&e.h d9h d:h d;d<e)e2h d9h d:h d;d<d=Z5ed>e&e/h d?h d@h d;d<e*e3h d?h d@h d;d<d=Z6edAe'e0h dBh d@h dCd<e+e4h dBh d@h dCd<d=Z7edDe'e0h dEh d@h dCd<e+e4h dEh d@h dCd<d=Z8edFe(e1dGhh d@h dCd<e,e4h dHh d@h dCd<d=Z9edIe(e1dJhh dCdKe,e4dLdMhdJhh dCd<d=Z:edNdO dPe5fdQe6fdRe7fdSe8fdTe9f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)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   U/home/air/biblejyuku/back/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)r/   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 )Nr2   r3   )r#   r$   r%   r   r6   )r/   r   r8   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(      r3   )r#   r$   r%   r)   r   r6   r/   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>   r3   )r%   r)   r   r6   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   	_segmentssegment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   rl   r   rj   r   _maybe_in_subresource  s   ro   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   rj   r   r   rl   6     

z?_maybe_in_subresource_crazy_items.<locals>.maybe_in_subresourcerm   r   rn   r   rj   r   !_maybe_in_subresource_crazy_items/     rr   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>   rT   rV   rp   rg   rj   r   r   rl   R  rq   zL_maybe_in_subresource_crazy_items_dependencies.<locals>.maybe_in_subresourcerm   r   rn   r   rj   r   ._maybe_in_subresource_crazy_items_dependenciesK  rs   rt   zdraft2020-12>   ifnotelsethenrT   containscontentSchemapropertyNamesunevaluatedItemsr]   unevaluatedProperties>   allOfanyOfoneOfprefixItems>   $defs
propertiesdefinitionsdependentSchemaspatternProperties)rD   rG   rF   )r4   id_ofrN   
anchors_inrl   zdraft2019-09>   ru   rv   rw   rx   ry   rz   r{   r\   r|   r]   r}   >   r~   r   r   zdraft-07>   ru   rv   rw   rx   ry   r{   r\   r]   >   r   r   r   zdraft-06>   rv   ry   r{   r\   r]   zdraft-04rv   >   rv   r\   r]   zdraft-03extends)rG   rF   r\   r]   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]]_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   r5   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 )r7   z4
    Dynamic anchors, introduced in draft 2020.
    strr4   SchemaResourcer5   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   )r5   dynamic_scoper8   r4   rZ   r   NoSuchAnchorr#   r7   	_Resolvedr   rf   )selfrb   lastr   registryr8   r   r   r   resolve\  s   
zDynamicAnchor.resolveNrb   r   r    r   )r   r   r   r   r   r   r   r   r   r   r7   S  s
   
 r7   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   _next_resolvedr   r   r   lookup_recursive_refn  s    


r   N)r   r   r    r!   )r   r-   r    r!   )r/   r0   r   r   r    r1   )r/   r0   r   r   r    r;   )r/   rA   r   r-   r    rB   )rD   rE   rF   rE   rG   rE   )r   r   r   r   r    r   r   )?r   
__future__r   collections.abcr   r   r   typingr   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<   r@   rC   	frozensetrQ   rU   r[   r^   ro   rr   rt   DRAFT202012DRAFT201909DRAFT7DRAFT6DRAFT4DRAFT3r   r   r7   r   r   r   r   r   <module>   s6   


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