o
    >]0                     @   s   d dl Z d dlZd dlZd dlZd dlmZmZmZ G dd deZG dd de	Z
dd Z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e	 e	 fddZdd ZdS )    N)MutableMapping	str_typesurlsplitc                   @   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   3/usr/lib/python3/dist-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!   -   s   zUnset.__repr__N)r"   r#   r$   r%   r!   r   r   r   r   r&   (   s    r&   c                 C   s"   t dd| }t|dS )zC
    Load a schema from ./schemas/``name``.json and return it.
    
jsonschemazschemas/{0}.jsonzutf-8)pkgutilget_dataformatjsonloadsdecode)namedatar   r   r   load_schema1   s   r0      c                    s   d  fdd|  D S )z>
    A dumb version of `textwrap.indent` from Python 3.3.
    
c                 3   s     | ]}d d   | V  qdS )    Nr   ).0linetimesr   r   	<genexpr>?   s    zindent.<locals>.<genexpr>)join
splitlines)stringr8   r   r7   r   indent:   s   r=   c                 C   s    | sdS dd dd | D  S )z
    Construct a single string containing indexing operations for the indices.

    For example, [1, 2, "foo"] -> [1][2]["foo"]

    Arguments:

        indices (sequence):

            The indices to format.
     z[%s]z][c                 s       | ]}t |V  qd S r   r    )r5   indexr   r   r   r9   Q       z"format_as_index.<locals>.<genexpr>)r:   )indicesr   r   r   format_as_indexB   s   rD   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schemarE   patternspropertyr   r   r   find_additional_propertiesT   s   
rO   c                 C   s.   t | dkr	d}nd}ddd | D |fS )z@
    Create an error message for extra items or properties.
    r1   waswere, c                 s   r?   r   r@   )r5   extrar   r   r   r9   p   rB   zextras_msg.<locals>.<genexpr>)r   r:   )extrasverbr   r   r   
extras_msgg   s   rV   c              	   C   sV   g }|D ]}z| t|d  W q ty!   | t| Y qw d| d|f S )a+  
    Create an error message for a failure to match the given types.

    If the ``instance`` is an object and contains a ``name`` property, it will
    be considered to be a description of that object and used as its type.

    Otherwise the message is simply the reprs of the given ``types``.
    r.   z%r is not of type %srR   )appendr    	Exceptionr:   )rK   typesreprstyper   r   r   	types_msgs   s   
r\   c                 C   sL   t  }t| ts| f} | D ]}t|tr|t| q|| qt|S )z
    isinstance() can accept a bunch of really annoying different types:
        * a single type
        * a tuple of types
        * an arbitrary nested tree of tuples

    Return a flattened tuple of the given argument.
    )set
isinstancetupler   flattenadd)suitable_for_isinstancerY   thingr   r   r   r`      s   


r`   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.
    )r^   r   )rc   r   r   r   ensure_list   s   
rd   c                 C   s   t | t |kS )zQ
    Check if two things are equal, but evade booleans and ints being equal.
    unbool)onetwor   r   r   equal   s   ri   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   rf      s
   rf   c                 C   s   zt tdd | D t | kW S  tye   z'tdd | D }t|dd}t||D ]\}}||kr: W Y dS q-W Y dS  ttfyd   g }| D ]}t|}||v rZ Y Y dS |	| qKY Y dS w w )z
    Check if all of a container's elements are unique.

    Successively tries first to rely that the elements are hashable, then
    falls back on them being sortable, and finally falls back on brute
    force.
    c                 s   r?   r   re   r5   ir   r   r   r9      rB   zuniq.<locals>.<genexpr>c                 s   r?   r   re   rm   r   r   r   r9      rB   r1   NFT)
r   r]   	TypeErrorsorted	itertoolsislicezipNotImplementedErrorrf   rW   )	containersortslicedrn   jseener   r   r   uniq   s.   	 


r{   )r1   )rq   r+   r(   rI   jsonschema.compatr   r   r   r   objectr&   r0   r=   rD   rO   rV   r\   r`   rd   ri   rf   r{   r   r   r   r   <module>   s$    	
	