Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/jsonschema/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/jsonschema/__pycache__/_utils.cpython-35.pyc



�$�]��@sddlZddlZddlZddlZddlmZmZmZGdd�de�ZGdd�de	�Z
dd�Zd	d
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Ze	�e	�dd�Zdd�ZdS)�N)�MutableMapping�	str_types�urlsplitc@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�URIDictz9
    Dictionary which uses normalized URIs as keys.

    cCst|�j�S)N)r�geturl)�self�uri�r	�B/opt/alt/python35/lib/python3.5/site-packages/jsonschema/_utils.py�	normalizeszURIDict.normalizecOs#t�|_|jj||�dS)N)�dict�store�update)r�args�kwargsr	r	r
�__init__szURIDict.__init__cCs|j|j|�S)N)r
r)rrr	r	r
�__getitem__szURIDict.__getitem__cCs||j|j|�<dS)N)r
r)rr�valuer	r	r
�__setitem__szURIDict.__setitem__cCs|j|j|�=dS)N)r
r)rrr	r	r
�__delitem__szURIDict.__delitem__cCs
t|j�S)N)�iterr
)rr	r	r
�__iter__szURIDict.__iter__cCs
t|j�S)N)�lenr
)rr	r	r
�__len__"szURIDict.__len__cCs
t|j�S)N)�reprr
)rr	r	r
�__repr__%szURIDict.__repr__N)�__name__�
__module__�__qualname__�__doc__rrrrrrrrr	r	r	r
r	src@s"eZdZdZdd�ZdS)�UnsetzH
    An as-of-yet unset attribute or unprovided default parameter.

    cCsdS)Nz<unset>r	)rr	r	r
r/szUnset.__repr__N)rrrrrr	r	r	r
r )sr cCs1tjddj|��}tj|jd��S)zD
    Load a schema from ./schemas/``name``.json and return it.

    Z
jsonschemazschemas/{0}.jsonzutf-8)�pkgutil�get_data�format�json�loads�decode)�name�datar	r	r
�load_schema3sr)�cs&dj�fdd�|j�D��S)z?
    A dumb version of `textwrap.indent` from Python 3.3.

    �
c3s!|]}dd�|VqdS)� �Nr	)�.0�line)�timesr	r
�	<genexpr>Cszindent.<locals>.<genexpr>)�join�
splitlines)�stringr0r	)r0r
�indent=sr5cCs(|s
dSddjdd�|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][css|]}t|�VqdS)N)r)r.�indexr	r	r
r1Vsz"format_as_index.<locals>.<genexpr>)r2)�indicesr	r	r
�format_as_indexFsr9ccsn|jdi�}dj|jdi��}x:|D]2}||kr4|ratj||�raq4|Vq4WdS)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�|ZpatternPropertiesN)�getr2�re�search)�instanceZschemar:�patterns�propertyr	r	r
�find_additional_propertiesYs
rBcCsAt|�dkrd}nd}djdd�|D��|fS)zA
    Create an error message for extra items or properties.

    r*�was�werez, css|]}t|�VqdS)N)r)r.�extrar	r	r
r1wszextras_msg.<locals>.<genexpr>)rr2)�extrasZverbr	r	r
�
extras_msgms	rGcCsqg}xQ|D]I}y|jt|d��Wq
tk
rU|jt|��Yq
Xq
Wd|dj|�fS)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�	Exceptionr2)r?�typesZreprs�typer	r	r
�	types_msgzs

rLcCsnt�}t|t�s!|f}x@|D]8}t|t�rS|jt|��q(|j|�q(Wt|�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)Zsuitable_for_isinstancerJ�thingr	r	r
rP�s		
rPcCst|t�r|gS|S)z^
    Wrap ``thing`` in a list if it's a single str.

    Otherwise, return it unchanged.

    )rNr)rRr	r	r
�ensure_list�srScCs$|dkr|S|dkr |S|S)zI
    A hack to make True and 1 and False and 0 unique for ``uniq``.

    TFr	)�element�true�falser	r	r
�unbool�s
rWcCsy-ttdd�|D���t|�kSWn�tk
r�ybtdd�|D��}tj|dd�}x-t||�D]\}}||kr~dSq~WWnXttfk
r�g}x7|D]/}t|�}||kr�dS|j	|�q�WYnXYnXdS)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.

    css|]}t|�VqdS)N)rW)r.�ir	r	r
r1�szuniq.<locals>.<genexpr>css|]}t|�VqdS)N)rW)r.rXr	r	r
r1�sr*NFT)
rrM�	TypeError�sorted�	itertools�islice�zip�NotImplementedErrorrWrH)Z	container�sortZslicedrX�j�seen�er	r	r
�uniq�s"
-

rc)r[r$r!r=Zjsonschema.compatrrrr�objectr r)r5r9rBrGrLrPrSrWrcr	r	r	r
�<module>s