o
    miH                  
   @  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   P/home/kim/smarthome/.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   anchorZdynamic_anchorr   r   r   _anchorE   s    


r9   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   

rB   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rF   rE   rC   r   r   subresources_of   s    

z)_subresources_of.<locals>.subresources_ofNr   r   r    rH   r   rC   rE   rF   rM   r   rL   r   _subresources_of   s   rP   c                   rG   )	O
    Specifically handle older drafts where there are some funky keywords.
    r   r   r    rH   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$   rJ   r%   r   )r   rK   rS   rL   r   r   rM      s*   




z:_subresources_of_with_crazy_items.<locals>.subresources_ofNrN   r   rO   r   rL   r   !_subresources_of_with_crazy_items   s   	rT   c                   rG   )	rQ   r   r   r    rH   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 )NrS   dependencies)r#   r$   rJ   r%   r   iternextr   r   rK   rS   rU   rJ   valuerL   r   r   rM      s:   






zG_subresources_of_with_crazy_items_dependencies.<locals>.subresources_ofNrN   r   rO   r   rL   r   ._subresources_of_with_crazy_items_dependencies   s   	rZ   c                   rG   )	zT
    Specifically handle even older drafts where there are some funky keywords.
    r   r-   r    rH   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 )NrS   rU   )additionalItemsadditionalProperties)rJ   r%   r#   r   rV   rW   r   rX   rL   r   r   rM      s>   








zJ_subresources_of_with_crazy_aP_items_dependencies.<locals>.subresources_ofN)r   r-   r    rH   r   rO   r   rL   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 rI   )rV   rW   in_subresourcer_   ra   rc   Z	_segmentssegmentZin_childrC   r   r   maybe_in_subresource  s   
z3_maybe_in_subresource.<locals>.maybe_in_subresourcer_   r`   ra   rb   rc   rd   r    rb   r   rC   rE   rF   ri   r   rh   r   _maybe_in_subresource  s   rl   c                   r^   )Nr_   r`   ra   rb   rc   rd   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 rR   rV   r#   r   r   re   rW   rf   rh   r   r   ri   6     

z?_maybe_in_subresource_crazy_items.<locals>.maybe_in_subresourcerj   r   rk   r   rh   r   !_maybe_in_subresource_crazy_items/     ro   c                   r^   )Nr_   r`   ra   rb   rc   rd   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>   rS   rU   rm   rf   rh   r   r   ri   R  rn   zL_maybe_in_subresource_crazy_items_dependencies.<locals>.maybe_in_subresourcerj   r   rk   r   rh   r   ._maybe_in_subresource_crazy_items_dependenciesK  rp   rq   zdraft2020-12>   containselser\   rS   unevaluatedItemsunevaluatedPropertiesnotpropertyNamescontentSchemathenif>   anyOfZprefixItemsoneOfallOf>   patternPropertiesZdependentSchemas
propertiesdefinitionsz$defs)rC   rF   rE   )r4   Zid_ofrM   Z
anchors_inri   zdraft2019-09>   rr   rs   r\   r[   rt   ru   rv   rw   rx   ry   rz   >   r{   r|   r}   zdraft-07>   rr   rs   r\   r[   rv   rw   ry   rz   >   r~   r   r   zdraft-06>   rr   r\   r[   rw   rv   zdraft-04rv   >   r\   r[   rv   zdraft-03Zextends)rF   rE   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   ra   _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   ra   )r5   dynamic_scoper8   r4   rY   r   ZNoSuchAnchorr#   r7   	_Resolvedr   re   )selfra   lastr   registryr8   r   r   r   resolve\  s   
zDynamicAnchor.resolveNra   r   r    r   )r   r   r   r   r   r   r   r   r   r   r7   S  s
   
 r7   ra   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   )ra   resolvedr   _Z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/   r@   r   r-   r    rA   )rC   rD   rE   rD   rF   rD   )r   r   r   r   r    r   r   )?r   
__future__r   collections.abcr   r   r   typingr   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.   r9   r;   r?   rB   	frozensetrP   rT   rZ   r]   rl   ro   rq   ZDRAFT202012ZDRAFT201909ZDRAFT7ZDRAFT6ZDRAFT4ZDRAFT3r   r   r7   r   r   r   r   r   <module>   s6   


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