B
    òès\£  ã               @   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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 )ÚURIDictz9
    Dictionary which uses normalized URIs as keys.

    c             C   s   t |ƒ ¡ S )N)r   Zgeturl)ÚselfÚuri© r   ú0lib/python3.7/site-packages/jsonschema/_utils.pyÚ	normalize   s    zURIDict.normalizec             O   s   t ƒ | _| jj||Ž d S )N)ÚdictÚstoreÚupdate)r   ÚargsÚkwargsr   r   r	   Ú__init__   s    zURIDict.__init__c             C   s   | j |  |¡ S )N)r   r
   )r   r   r   r   r	   Ú__getitem__   s    zURIDict.__getitem__c             C   s   || j |  |¡< d S )N)r   r
   )r   r   Úvaluer   r   r	   Ú__setitem__   s    zURIDict.__setitem__c             C   s   | j |  |¡= d S )N)r   r
   )r   r   r   r   r	   Ú__delitem__   s    zURIDict.__delitem__c             C   s
   t | jƒS )N)Úiterr   )r   r   r   r	   Ú__iter__   s    zURIDict.__iter__c             C   s
   t | jƒS )N)Úlenr   )r   r   r   r	   Ú__len__"   s    zURIDict.__len__c             C   s
   t | jƒS )N)Úreprr   )r   r   r   r	   Ú__repr__%   s    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 )ÚUnsetzH
    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 )zD
    Load a schema from ./schemas/``name``.json and return it.

    Z
jsonschemazschemas/{0}.jsonzutf-8)ÚpkgutilÚget_dataÚformatÚjsonÚloadsÚdecode)ÚnameÚdatar   r   r	   Úload_schema3   s    r(   é   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>C   s    zindent.<locals>.<genexpr>)ÚjoinÚ
splitlines)Ústringr/   r   )r/   r	   Úindent=   s    r4   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   s   | ]}t |ƒV  qd S )N)r   )r-   Úindexr   r   r	   r0   V   s    z"format_as_index.<locals>.<genexpr>)r1   )Úindicesr   r   r	   Úformat_as_indexF   s    r8   c             c   sP   |  di ¡}d |  di ¡¡}x,| D ]$}||kr$|rBt ||¡rBq$|V  q$W 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ú|ZpatternPropertiesN)Úgetr1   ÚreÚsearch)ÚinstanceZschemar9   ZpatternsÚpropertyr   r   r	   Úfind_additional_propertiesY   s    
r@   c             C   s.   t | ƒdkrd}nd}d dd„ | D ƒ¡|fS )zA
    Create an error message for extra items or properties.

    r)   ZwasZwerez, c             s   s   | ]}t |ƒV  qd S )N)r   )r-   Zextrar   r   r	   r0   w   s    zextras_msg.<locals>.<genexpr>)r   r1   )ZextrasZverbr   r   r	   Ú
extras_msgm   s    rA   c          	   C   s^   g }xF|D ]>}y|  t|d ƒ¡ W q
 tk
rF   |  t|ƒ¡ Y q
X 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 %sz, )Úappendr   Ú	Exceptionr1   )r>   ÚtypesZreprsÚtyper   r   r	   Ú	types_msgz   s    
rF   c             C   sP   t ƒ }t| tƒs| f} x0| D ](}t|tƒr:| t|ƒ¡ q| |¡ qW 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)Zsuitable_for_isinstancerD   Úthingr   r   r	   rJ   Ž   s    


rJ   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.

    )rH   r   )rL   r   r   r	   Úensure_list¥   s    
rM   c             C   s   | dkr|S | dkr|S | S )zI
    A hack to make True and 1 and False and 0 unique for ``uniq``.

    TFr   )ÚelementÚtrueZfalser   r   r	   Úunbool²   s
    rP   c             C   sÊ   yt tdd„ | D ƒƒƒt | ƒkS  tk
rÄ   yHtdd„ | D ƒƒ}t |dd¡}x"t||ƒD ]\}}||kr\dS q\W W nH ttfk
r¾   g }x*| D ]"}t|ƒ}||kr¬dS | 	|¡ q”W Y nX Y nX dS )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   s   | ]}t |ƒV  qd S )N)rP   )r-   Úir   r   r	   r0   Ê   s    zuniq.<locals>.<genexpr>c             s   s   | ]}t |ƒV  qd S )N)rP   )r-   rQ   r   r   r	   r0   Í   s    r)   NFT)
r   rG   Ú	TypeErrorÚsortedÚ	itertoolsÚisliceÚzipÚNotImplementedErrorrP   rB   )Z	containerÚsortZslicedrQ   ÚjÚseenÚer   r   r	   Úuniq¿   s"    

r\   )r)   )rT   r#   r    r<   Zjsonschema.compatr   r   r   r   Úobjectr   r(   r4   r8   r@   rA   rF   rJ   rM   rP   r\   r   r   r   r	   Ú<module>   s     


	