
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
;Xt                 @   s   d dl mZmZ d dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
 eddgZe Zej ZG dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZeefddZe ZefddZdS )    )defaultdictdequeN)_utils)PY3	iteritemsZanyOfZoneOfc            	       s   e Zd Zef df eeef df	 fdd	Zdd Zdd ZerBeZndd	 Ze	d
d Z
edd Zedd Zdd Zdd Z  ZS )_ErrorNc                s   t t| j|||||||||	|

 || _t| | _| _t|	 | _| _t	|| _
| | _| _|| _|| _|| _|| _|
| _x|D ]
}| |_qW d S )N)superr   __init__messager   pathrelative_pathschema_pathrelative_schema_pathlistcontextcause	__cause__	validatorvalidator_valueinstanceschemaparent)selfr
   r   r   r   r   r   r   r   r   r   error)	__class__  /usr/lib/python3.6/exceptions.pyr	      s.    


z_Error.__init__c             C   s   d| j j| jf S )Nz<%s: %r>)r   __name__r
   )r   r   r   r   __repr__8   s    z_Error.__repr__c             C   s   | j | j| j| jf}tdd |D r,| jS tj| jdd}tj| jdd}| jtj	dj
 | j tjt| jd d tj|tj| jtj|f  S )Nc             s   s   | ]}|t kV  qd S )N)_unset).0mr   r   r   	<genexpr>?   s    z%_Error.__unicode__.<locals>.<genexpr>H   )widthzv

            Failed validating %r in schema%s:
            %s

            On instance%s:
            %s
               )r   r   r   r   anyr
   pprintpformattextwrapdedentrstripr   Zformat_as_indexr   r   indentr   )r   Zessential_for_verbosepschema	pinstancer   r   r   __unicode__;   s    
z_Error.__unicode__c             C   s   t | jdS )Nzutf-8)unicodeencode)r   r   r   r   __str__W   s    z_Error.__str__c             C   s   | f |j  S )N)	_contents)clsotherr   r   r   create_fromZ   s    z_Error.create_fromc             C   s2   | j }|d kr| jS t| j}|jt|j |S )N)r   r   r   
extendleftreversedabsolute_path)r   r   r   r   r   r   r:   ^   s    
z_Error.absolute_pathc             C   s2   | j }|d kr| jS t| j}|jt|j |S )N)r   r   r   r8   r9   absolute_schema_path)r   r   r   r   r   r   r;   h   s    
z_Error.absolute_schema_pathc             K   s4   x.t |D ]"\}}t| |tkr
t| || q
W d S )N)r   getattrr   setattr)r   kwargskvr   r   r   _setr   s    z_Error._setc          
      s   d}t  fdd|D S )Nr
   r   r   r   r   r   r   r   r   r   c             3   s   | ]}|t  |fV  qd S )N)r<   )r    attr)r   r   r   r"   |   s    z#_Error._contents.<locals>.<genexpr>)
r
   r   r   r   r   r   r   r   r   r   )dict)r   attrsr   )r   r   r4   w   s     z_Error._contents)r   
__module____qualname__r   r	   r   r0   r   r3   classmethodr7   propertyr:   r;   rA   r4   __classcell__r   r   )r   r   r      s&   

r   c               @   s   e Zd ZdS )ValidationErrorN)r   rE   rF   r   r   r   r   rJ      s   rJ   c               @   s   e Zd ZdS )SchemaErrorN)r   rE   rF   r   r   r   r   rK      s   rK   c               @   s   e Zd ZdS )RefResolutionErrorN)r   rE   rF   r   r   r   r   rL      s   rL   c               @   s.   e Zd Zdd Zdd Zer"eZndd ZdS )UnknownTypec             C   s   || _ || _|| _d S )N)typer   r   )r   rN   r   r   r   r   r   r	      s    zUnknownType.__init__c             C   sF   t j| jdd}t j| jdd}tjdj | jtj	|tj	|f S )Nr#   )r$   z
            Unknown type %r for validator with schema:
            %s

            While checking instance:
            %s
            )
r(   r)   r   r   r*   r+   r,   rN   r   r-   )r   r.   r/   r   r   r   r0      s
    zUnknownType.__unicode__c             C   s   t | jdS )Nzutf-8)r1   r2   )r   r   r   r   r3      s    zUnknownType.__str__N)r   rE   rF   r	   r0   r   r3   r   r   r   r   rM      s
   rM   c                   s8   e Zd Zd fdd	Zdd Zer(eZndd Z  ZS )	FormatErrorNc                s(   t t| j|| || _| | _| _d S )N)r   rO   r	   r
   r   r   )r   r
   r   )r   r   r   r	      s    zFormatError.__init__c             C   s   | j S )N)r
   )r   r   r   r   r0      s    zFormatError.__unicode__c             C   s   | j jdS )Nzutf-8)r
   r2   )r   r   r   r   r3      s    zFormatError.__str__)N)r   rE   rF   r	   r0   r   r3   rI   r   r   )r   r   rO      s
   rO   c               @   s\   e Zd ZdZeZf fddZdd Zdd Zdd	 Z	d
d Z
dd Zdd Zedd ZdS )	ErrorTreezG
    ErrorTrees make it easier to check which validations failed.

    c             C   sT   i | _ t| j| _x<|D ]4}| }x|jD ]}|| }q(W ||j |j< |j|_qW d S )N)errorsr   r   r4   r   r   r   	_instance)r   rQ   r   Z	containerelementr   r   r   r	      s    
zErrorTree.__init__c             C   s
   || j kS )zD
        Check whether ``instance[index]`` has any errors.

        )r4   )r   indexr   r   r   __contains__   s    zErrorTree.__contains__c             C   s&   | j tk	r|| kr| j |  | j| S )aY  
        Retrieve the child tree one level down at the given ``index``.

        If the index is not in the instance that this tree corresponds to and
        is not known by this tree, whatever error would be raised by
        ``instance.__getitem__`` will be propagated (usually this is some
        subclass of :class:`LookupError`.

        )rR   r   r4   )r   rT   r   r   r   __getitem__   s    
zErrorTree.__getitem__c             C   s   || j |< d S )N)r4   )r   rT   valuer   r   r   __setitem__   s    zErrorTree.__setitem__c             C   s
   t | jS )zZ
        Iterate (non-recursively) over the indices in the instance with errors.

        )iterr4   )r   r   r   r   __iter__   s    zErrorTree.__iter__c             C   s   | j S )z0
        Same as :attr:`total_errors`.

        )total_errors)r   r   r   r   __len__   s    zErrorTree.__len__c             C   s   d| j jt| f S )Nz<%s (%s total errors)>)r   r   len)r   r   r   r   r      s    zErrorTree.__repr__c             C   s&   t dd t| jD }t| j| S )zU
        The total number of errors in the entire tree, including children.

        c             s   s   | ]\}}t |V  qd S )N)r]   )r    _Ztreer   r   r   r"      s    z)ErrorTree.total_errors.<locals>.<genexpr>)sumr   r4   r]   rQ   )r   Zchild_errorsr   r   r   r[      s    zErrorTree.total_errorsN)r   rE   rF   __doc__r   rR   r	   rU   rV   rX   rZ   r\   r   rH   r[   r   r   r   r   rP      s   rP   c                s    fdd}|S )Nc                s    | j }t| j |k| kfS )N)r   r]   r   )r   r   )strongweakr   r   	relevance  s    zby_relevance.<locals>.relevancer   )rb   ra   rc   r   )ra   rb   r   by_relevance   s    rd   c             C   sR   t | } t| d }|d krd S ttj|g| |d}x|jrLt|j|d}q6W |S )N)key)rY   nextmax	itertoolschainr   min)rQ   re   Zbestr   r   r   
best_match
  s    
rk   )collectionsr   r   rh   r(   r*   Z
jsonschemar   Zjsonschema.compatr   r   	frozensetZWEAK_MATCHESZSTRONG_MATCHESZUnsetr   	Exceptionr   rJ   rK   rL   rM   rO   objectrP   rd   rc   rk   r   r   r   r   <module>   s$   oL