
    `d(                        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e      Z G d d	e      Zd
 Zd Zd Zd Zd Zd Zd Zd Z e        e       fdZd Zd Zd Zy)    )MappingMutableMappingSequence)urlsplitN)   	   )	resourcesc                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)URIDictz8
    Dictionary which uses normalized URIs as keys.
    c                 4    t        |      j                         S N)r   geturlselfuris     3/usr/lib/python3/dist-packages/jsonschema/_utils.py	normalizezURIDict.normalize   s    }##%%    c                 Z    t               | _         | j                  j                  |i | y r   )dictstoreupdate)r   argskwargss      r   __init__zURIDict.__init__   s$    V


4*6*r   c                 >    | j                   | j                  |         S r   r   r   r   s     r   __getitem__zURIDict.__getitem__   s    zz$..-..r   c                 @    || j                   | j                  |      <   y r   r   )r   r   values      r   __setitem__zURIDict.__setitem__   s    */

4>>#&'r   c                 <    | j                   | j                  |      = y r   r   r   s     r   __delitem__zURIDict.__delitem__!   s    JJt~~c*+r   c                 ,    t        | j                        S r   )iterr   r   s    r   __iter__zURIDict.__iter__$       DJJr   c                 ,    t        | j                        S r   )lenr   r&   s    r   __len__zURIDict.__len__'   s    4::r   c                 ,    t        | j                        S r   )reprr   r&   s    r   __repr__zURIDict.__repr__*   r(   r   N)__name__
__module____qualname____doc__r   r   r   r!   r#   r'   r+   r.    r   r   r   r      s/    &+/0,  r   r   c                       e Zd ZdZd Zy)UnsetzG
    An as-of-yet unset attribute or unprovided default parameter.
    c                      y)Nz<unset>r3   r&   s    r   r.   zUnset.__repr__3   s    r   N)r/   r0   r1   r2   r.   r3   r   r   r5   r5   .   s    r   r5   c                     t        j                  t              j                  d|  d      }|j	                  d      }t        j                  |      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datas      r   load_schemarB   7   sE    
 ??;'008D61GHD>>7>+D::dr   c                 F    |s| S |  ddj                  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              3   2   K   | ]  }t        |        y wr   r-   ).0indexs     r   	<genexpr>z"format_as_index.<locals>.<genexpr>T   s     #EEDK#E   ])join)	containerindicess     r   format_as_indexrO   A   s0    " [$))#EW#EEFaHHr   c              #      K   |j                  di       }dj                  |j                  di             }| D ]$  }||vs|rt        j                  ||      r!| & yw)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)getrL   research)instanceschemarQ   patternspropertys        r   find_additional_propertiesr[   W   sa      L"-Jxx

#6;<H :%BIIh9N	s   =A   A c                 n    t        |       dk(  rd}nd}dj                  d t        |       D              |fS )z@
    Create an error message for extra items or properties.
       waswerez, c              3   2   K   | ]  }t        |        y wr   rF   )rG   extras     r   rI   zextras_msg.<locals>.<genexpr>s   s     =UT%[=rJ   )r*   rL   sorted)extrasverbs     r   
extras_msgre   j   s8    
 6{a99=fVn==tCCr   c                 ,    t        | t              r| gS | S )z]
    Wrap ``thing`` in a list if it's a single str.

    Otherwise, return it unchanged.
    )
isinstancestr)things    r   ensure_listrj   v   s     %wLr   c                 x    t        |       t              k7  ryt        fd| j                         D              S )zI
    Check if two mappings are equal using the semantics of `equal`.
    Fc              3   N   K   | ]  \  }}|v xr t        ||           y wr   equal)rG   keyr    twos      r   rI   z!_mapping_equal.<locals>.<genexpr>   s4      C 	s
-uUCH--s   "%)r*   allitemsonerp   s    `r   _mapping_equalru      s8     3x3s8 ))+  r   c                 j    t        |       t        |      k7  ryt        d t        | |      D              S )zJ
    Check if two sequences are equal using the semantics of `equal`.
    Fc              3   :   K   | ]  \  }}t        ||        y wr   rm   )rG   ijs      r   rI   z"_sequence_equal.<locals>.<genexpr>   s     5tq!uQ{5s   )r*   rq   ziprs   s     r   _sequence_equalr{      s.     3x3s85s3}555r   c                 *   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.
    )rg   rh   r   r{   r   ru   unboolrs   s     r   rn   rn      st     #sz#s3cz#x ZX%>sC((#wJsG$<c3''#;&+%%r   c                     | du r|S | du r|S | S )zH
    A hack to make True and 1 and False and 0 unique for ``uniq``.
    TFr3   )elementtruefalses      r   r}   r}      s"    
 $	E	Nr   c                 @   	 t        d | D              }t        j                  |dd      }t        ||      D ]  \  }}t	        ||      s y 	 y# t
        t        f$ r? g }| D ]5  }t        |      }|D ]  }t	        ||      s  Y y |j                  |       7 Y yw xY 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              3   2   K   | ]  }t        |        y wr   )r}   )rG   rx   s     r   rI   zuniq.<locals>.<genexpr>   s     3AfQi3rJ   r]   NFT)	rb   	itertoolsislicerz   rn   NotImplementedError	TypeErrorr}   append)rM   sortslicedrx   ry   seenes          r   uniqr      s    333!!$40f% 	DAqQ{	   + 	 	Aq	A !A; ! KKN	 	s*   AA 
A A 2BBBBc           
         | j                  |d      rg S g }d|v rt        t        dt        |                  S d|v rg| j                  j                  |d         \  }}| j                  j                  |       	 |t        | ||      z  }| j                  j                          d|v r$|t        t        dt        |d                     z  }d|v rf| j                  |d         j                  |      r+|t        | ||d         z  }d|v r+|t        | ||d         z  }nd	|v r|t        | ||d	         z  }d
D ]P  }||v st        |      D ];  \  }}| j                  ||         j                  |      s+|j                  |       = R dD ]?  }||v s||   D ]0  }	t        | j                  ||	            }
|
r!|t        | ||	      z  }2 A |S # | j                  j                          w xY w)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
    booleanrr   r   $refprefixItemsifrX   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	enumerater   descend)	validatorrW   rX   evaluated_indexesscoperesolvedkeywordkv	subschemaerrss              r   r   r      sF    +	&E!S]+,,#,,44VF^Dx%%e,	+!F8X"  ((*T%3vm/D+E"FGGv~6$<099(C!F8VD\"  !%Jx& ! !%Jx& ! 4 0f!(+ 01##6'?#;DDQG%,,Q/00 / f#G_ 	I--h	BC%)N!8Y* % G ((*s   :G G-c                    | j                  |d      rg S g }d|v rg| j                  j                  |d         \  }}| j                  j                  |       	 |t	        | ||      z  }| j                  j                          dD ]  }||v s| j                  ||   d      rP|j                         D ]=  \  }}| j                  ||         j                  ||i      s-|j                  |       ? | j                  ||   d      s||   j                         D ]@  \  }}	||v s| j                  |	      j                  ||         s0|j                  |       B  d|v r|j                         D ]o  \  }}|d   j                         D ]T  \  }
}t        j                  |
|      s| j                  |d         j                  ||i      sD|j                  |       V q d|v r0|d   j                         D ]  \  }}	||vr|t	        | ||	      z  } dD ]?  }||v s||   D ]0  }	t        | j                  ||	            }|r!|t	        | ||	      z  }2 A d	|v rg| j                  |d	         j                  |      r,|t	        | ||d	         z  }d
|v r|t	        | ||d
         z  }|S d|v r|t	        | ||d         z  }|S # | j                  j                          w xY w)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
    r   r   )rQ   additionalPropertiesunevaluatedPropertiesr   objectrS   dependentSchemasr   r   r   r   )r   r   r   r   &find_evaluated_property_keys_by_schemar   rr   r   r   r   rU   rV   r   r   )r   rW   rX   evaluated_keysr   r   r   rZ   r    r   pattern_r   s                r   r   r     s    +	N#,,44VF^Dx%%e,	+D8X N ((* 8 f  )<'/~~'7 8OHe ''vg'?HH!5) '--h7	8   (;+1'?+@+@+B 8'Hi8+	0@0@( 1A 1hx1213 '--h7	88$ f$'~~/ 	4OHe$%89??A 4
99Wh/I4D4D!"56 5E 5(He,-5. #))(3	4	4 V##)*<#=#C#C#E 	Hix'D8Y N	 / f#G_ 	I--h	BC"&L!8Y' N v~6$<099(CD8VD\ N "Hx#   "Hx#  y ((*s   K
 
K&)collections.abcr   r   r   urllib.parser   r   r=   rU   sysversion_info	importlibr	   importlib_resourcesr   r   r5   rB   rO   r[   re   rj   ru   r{   rn   r}   r   r   r   r3   r   r   <module>r      s    = = !   	 
 v#+ n  >F I,&	D		6&    	8:zQr   