U
    ±[Öe0  ã                   @   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   úS/var/www/html/services/stratfitenv/lib/python3.8/site-packages/jsonschema/_utils.pyÚ	normalize   s    zURIDict.normalizec                 O   s   t ƒ | _| jj||Ž 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   s
   t | jƒS r   )Úiterr   ©r	   r   r   r   Ú__iter__   s    zURIDict.__iter__c                 C   s
   t | jƒS r   )Úlenr   r   r   r   r   Ú__len__!   s    zURIDict.__len__c                 C   s
   t | jƒS r   )Ú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 )Ú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.
    Z
jsonschemazschemas/{0}.jsonzutf-8)ÚpkgutilÚget_dataÚformatÚjsonÚloadsÚdecode)ÚnameÚdatar   r   r   Úload_schema1   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>?   s     zindent.<locals>.<genexpr>)ÚjoinÚ
splitlines)Ústringr5   r   r4   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   s   | ]}t |ƒV  qd S r   ©r   )r2   Úindexr   r   r   r6   Q   s     z"format_as_index.<locals>.<genexpr>)r7   )Úindicesr   r   r   Úformat_as_indexB   s    r?   c                 c   sL   |  di ¡}d |  di ¡¡}| D ]$}||k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ú|ZpatternPropertiesN)Úgetr7   ÚreÚsearch)ÚinstanceZschemar@   ÚpatternsÚpropertyr   r   r   Úfind_additional_propertiesT   s    
rH   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.
    r.   ÚwasÚwereú, c                 s   s   | ]}t |ƒV  qd S r   r<   )r2   Úextrar   r   r   r6   p   s     zextras_msg.<locals>.<genexpr>)r   r7   )ÚextrasÚverbr   r   r   Ú
extras_msgg   s    rO   c              	   C   sZ   g }|D ]>}z|  t|d ƒ¡ W q tk
rD   |  t|ƒ¡ Y qX q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 %srK   )Úappendr   Ú	Exceptionr7   )rE   ÚtypesZreprsÚtyper   r   r   Ú	types_msgs   s    
rT   c                 C   sL   t ƒ }t| tƒs| f} | D ](}t|tƒr8| 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)Zsuitable_for_isinstancerR   Úthingr   r   r   rX   †   s    


rX   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.
    )rV   r   )rZ   r   r   r   Úensure_listœ   s    
r[   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    r`   c                 C   s   | dkr|S | dkr|S | S )zH
    A hack to make True and 1 and False and 0 unique for ``uniq``.
    TFr   )ÚelementÚtrueÚfalser   r   r   r]   ¯   s
    r]   c                 C   sÐ   z t tdd„ | D ƒƒƒt | ƒkW S  tk
rÊ   zJtdd„ | D ƒƒ}t |dd¡}t||ƒD ]\}}||kr\ W Y dS q\W nJ ttfk
rÄ   g }| D ](}t|ƒ}||kr´ Y Y dS | 	|¡ q–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 r   r\   ©r2   Úir   r   r   r6   Å   s     zuniq.<locals>.<genexpr>c                 s   s   | ]}t |ƒV  qd S r   r\   rd   r   r   r   r6   È   s     r.   NFT)
r   rU   Ú	TypeErrorÚsortedÚ	itertoolsÚisliceÚzipÚNotImplementedErrorr]   rP   )Ú	containerÚsortZslicedre   ÚjÚseenÚer   r   r   Úuniq»   s"    	 
rq   )r.   )rh   r(   r%   rC   Zjsonschema.compatr   r   r   r   Úobjectr$   r-   r:   r?   rH   rO   rT   rX   r[   r`   r]   rq   r   r   r   r   Ú<module>   s"   		
