o
    i(                     @   s   d dl mZmZmZ d dlmZ d dlZd dlZd dlZd dl	Z	e	j
dkr,d dlmZ nd dlZG dd deZG dd	 d	Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Ze e fddZdd Zdd Zd d! ZdS )"    )MappingMutableMappingSequence)urlsplitN)   	   )	resourcesc                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )URIDictz8
    Dictionary which uses normalized URIs as keys.
    c                 C   s   t | S N)r   geturlselfuri r   L/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jsonschema/_utils.py	normalize   s   zURIDict.normalizec                 O   s   t  | _| jj|i | d S r
   )dictstoreupdate)r   argskwargsr   r   r   __init__   s   zURIDict.__init__c                 C   s   | j | | S r
   r   r   r   r   r   r   __getitem__   s   zURIDict.__getitem__c                 C   s   || j | |< d S r
   r   )r   r   valuer   r   r   __setitem__   s   zURIDict.__setitem__c                 C   s   | j | |= d S r
   r   r   r   r   r   __delitem__!   s   zURIDict.__delitem__c                 C   
   t | jS r
   )iterr   r   r   r   r   __iter__$      
zURIDict.__iter__c                 C   r   r
   )lenr   r   r   r   r   __len__'   r!   zURIDict.__len__c                 C   r   r
   )reprr   r   r   r   r   __repr__*   r!   zURIDict.__repr__N)__name__
__module____qualname____doc__r   r   r   r   r   r    r#   r%   r   r   r   r   r	      s    r	   c                   @   s   e Zd ZdZdd ZdS )UnsetzG
    An as-of-yet unset attribute or unprovided default parameter.
    c                 C   s   dS )Nz<unset>r   r   r   r   r   r%   3   s   zUnset.__repr__N)r&   r'   r(   r)   r%   r   r   r   r   r*   .   s    r*   c                 C   s.   t td|  d}|jdd}t|S )zC
    Load a schema from ./schemas/``name``.json and return it.
    zschemas/z.jsonzutf-8)encoding)r   files__package__joinpath	read_textjsonloads)namepathdatar   r   r   load_schema7   s   
r5   c                 C   s(   |s| S |  dd dd |D  dS )aA  
    Construct a single string containing indexing operations for the indices.

    For example for a container ``bar``, [1, 2, "foo"] -> bar[1][2]["foo"]

    Arguments:

        container (str):

            A word to use for the thing being indexed

        indices (sequence):

            The indices to format.
    [z][c                 s       | ]}t |V  qd S r
   r$   ).0indexr   r   r   	<genexpr>T       z"format_as_index.<locals>.<genexpr>])join)	containerindicesr   r   r   format_as_indexA   s    rA   c                 c   sN    | di }d| di }| D ]}||vr$|r!t||r!q|V  qdS )z
    Return the set of additional properties for the given ``instance``.

    Weeds out properties that should have been validated by ``properties`` and
    / or ``patternProperties``.

    Assumes ``instance`` is dict-like already.
    
properties|patternPropertiesN)getr>   research)instanceschemarB   patternspropertyr   r   r   find_additional_propertiesW   s   
rL   c                 C   s2   t | dkr	d}nd}ddd t| D |fS )z@
    Create an error message for extra items or properties.
       waswerez, c                 s   r7   r
   r8   )r9   extrar   r   r   r;   s   r<   zextras_msg.<locals>.<genexpr>)r"   r>   sorted)extrasverbr   r   r   
extras_msgj   s   rT   c                 C   s   t | tr| gS | S )z]
    Wrap ``thing`` in a list if it's a single str.

    Otherwise, return it unchanged.
    )
isinstancestr)thingr   r   r   ensure_listv   s   
rX   c                    s.   t | t  kr
dS t fdd|  D S )zI
    Check if two mappings are equal using the semantics of `equal`.
    Fc                 3   s*    | ]\}}| v ot | | V  qd S r
   equal)r9   keyr   twor   r   r;      s
    
z!_mapping_equal.<locals>.<genexpr>)r"   allitemsoner]   r   r\   r   _mapping_equal   s
   rb   c                 C   s,   t | t |kr
dS tdd t| |D S )zJ
    Check if two sequences are equal using the semantics of `equal`.
    Fc                 s   s    | ]
\}}t ||V  qd S r
   rY   )r9   ijr   r   r   r;      s    z"_sequence_equal.<locals>.<genexpr>)r"   r^   zipr`   r   r   r   _sequence_equal   s   rf   c                 C   sh   t | ts
t |tr| |kS t | trt |trt| |S t | tr,t |tr,t| |S t| t|kS )z
    Check if two things are equal evading some Python type hierarchy semantics.

    Specifically in JSON Schema, evade `bool` inheriting from `int`,
    recursing into sequences to do the same.
    )rU   rV   r   rf   r   rb   unboolr`   r   r   r   rZ      s   

rZ   c                 C   s   | du r|S | du r|S | S )zH
    A hack to make True and 1 and False and 0 unique for ``uniq``.
    TFr   )elementtruefalser   r   r   rg      s
   rg   c              	   C   s   z&t dd | D }t|dd}t||D ]\}}t||r# W dS qW dS  ttfyQ   g }| D ]}t|}|D ]}t||rG  Y dS q;|| q3Y dS w )z
    Check if all of a container's elements are unique.

    Tries to rely on the container being recursively sortable, or otherwise
    falls back on (slow) brute force.
    c                 s   r7   r
   )rg   )r9   rc   r   r   r   r;      r<   zuniq.<locals>.<genexpr>rM   NFT)	rQ   	itertoolsislicere   rZ   NotImplementedError	TypeErrorrg   append)r?   sortslicedrc   rd   seener   r   r   uniq   s*   


rt   c                 C   s  |  |drg S g }d|v rttdt|S d|v rA| j|d \}}| j| z|t| ||7 }W | j  n| j  w d|v rR|ttdt|d 7 }d|v r| j	|d d
|rz|t| ||d 7 }d|v ry|t| ||d 7 }nd	|v r|t| ||d	 7 }d
D ]}||v rt|D ]\}}| j	|| d
|r|| qqdD ]}||v r|| D ]}	t| ||	}
|
s|t| ||	7 }qq|S )z
    Get all indexes of items that get evaluated under the current schema

    Covers all keywords related to unevaluatedItems: items, prefixItems, if,
    then, else, contains, unevaluatedItems, allOf, oneOf, anyOf
    booleanr_   r   $refprefixItemsifrI   thenelse)containsunevaluatedItemsallOfoneOfanyOf)is_typelistranger"   resolverresolve
push_scope%find_evaluated_item_indexes_by_schema	pop_scopeevolveis_valid	enumeratero   descend)	validatorrH   rI   evaluated_indexesscoperesolvedkeywordkv	subschemaerrsr   r   r   r      sZ   



r   c                 C   sd  |  |drg S g }d|v r4| j|d \}}| j| z|t| ||7 }W | j  n| j  w dD ]P}||v r|  || dr_| D ]\}}| j|| d||ir^|	| qH|  || dr||  D ]\}}	||v r| j|	d|| r|	| qmq6d|v r| D ]'\}}|d  D ]\}
}t
|
|r| j|d d||ir|	| qqd|v r|d  D ]\}}	||vrq|t| ||	7 }qdD ]}||v r|| D ]}	t| ||	}|s|t| ||	7 }qqd	|v r0| j|d	 d|r!|t| ||d	 7 }d
|v r|t| ||d
 7 }|S d|v r0|t| ||d 7 }|S )a  
    Get all keys of items that get evaluated under the current schema

    Covers all keywords related to unevaluatedProperties: properties,
    additionalProperties, unevaluatedProperties, patternProperties,
    dependentSchemas, allOf, oneOf, anyOf, if, then, else
    ru   rv   )rB   additionalPropertiesunevaluatedPropertiesry   objectrD   dependentSchemasr~   rx   rz   r{   )r   r   r   r   &find_evaluated_property_keys_by_schemar   r_   r   r   ro   rF   rG   r   r   )r   rH   rI   evaluated_keysr   r   r   rK   r   r   pattern_r   r   r   r   r     s   








	

r   )collections.abcr   r   r   urllib.parser   rk   r0   rF   sysversion_info	importlibr   importlib_resourcesr	   r*   r5   rA   rL   rT   rX   rb   rf   rZ   r   rg   rt   r   r   r   r   r   r   <module>   s.    
	
	=