
    t                     J   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e      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      ZeefdZ e       ZefdZy)    )defaultdictdequeN)_utils)PY3	iteritemsanyOfoneOfc            	            e Zd Zedddeeeddf	 fd	Zd Zd ZereZnd Ze	d        Z
ed        Zed	        Zd
 Zd Z xZS )_Error Nc                 F   t         t        |   |||||||||	|

       || _        t	        |      x| _        | _        t	        |	      x| _        | _        t        |      | _
        |x| _        | _        || _        || _        || _        || _        |
| _        |D ]	  }| |_         y 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__s               (lib/third_party/jsonschema/exceptions.pyr   z_Error.__init__   s     	fd$	
 ).t4	D&7<[7II44G}&++
T^". EEL     c                 P    d| j                   j                  d| j                  dS )N<z: >)r!   __name__r   r   s    r"   __repr__z_Error.__repr__8   s    !^^44dllCCr#   c           	      z   | j                   | j                  | j                  | j                  f}t	        d |D              r| j
                  S t        j                  | j                  d      }t        j                  | j                  d      }| j
                  t        j                  dj                               | j                   t        j                  t        | j                        d d       t        j                  |      t        j                  | j                         t        j                  |      fz  z   S )Nc              3   ,   K   | ]  }|t         u   y wr   )_unset).0ms     r"   	<genexpr>z%_Error.__unicode__.<locals>.<genexpr>?   s     :$9qqF{$9s   H   widthzv

            Failed validating %r in schema%s:
            %s

            On instance%s:
            %s
            )r   r   r   r   anyr   pprintpformattextwrapdedentrstripr   format_as_indexr   r   indentr   )r   essential_for_verbosepschema	pinstances       r"   __unicode__z_Error.__unicode__;   s    NND00$--!
 :$9::<<..B7NN4==;	||hoo / 
 NN""4(A(A#B3B#GHMM'"""4#5#56MM)$

 
 	
r#   c                 6    t        |       j                  d      S Nzutf-8unicodeencoder(   s    r"   __str__z_Error.__str__W       4=''00r#   c                 .     | di |j                         S )Nr   	_contents)clsothers     r"   create_fromz_Error.create_fromZ   s    'U__&''r#   c                     | j                   }|| j                  S t        | j                        }|j                  t	        |j
                               |S r   )r   r   r   
extendleftreversedabsolute_pathr   r   r   s      r"   rP   z_Error.absolute_path^   sH    >%%%T''(!5!567r#   c                     | j                   }|| j                  S t        | j                        }|j                  t	        |j
                               |S r   )r   r   r   rN   rO   absolute_schema_pathrQ   s      r"   rS   z_Error.absolute_schema_pathh   sH    >,,,T../!<!<=>r#   c                 j    t        |      D ]%  \  }}t        | |      t        u st        | ||       ' y r   )r   getattrr,   setattr)r   kwargskvs       r"   _setz_Error._setr   s0    f%DAqtQ6)a# &r#   c                 0     d}t         fd|D              S )N)
r   r   r   r   r   r   r   r   r   r   c              3   :   K   | ]  }|t        |      f  y wr   )rU   )r-   attrr   s     r"   r/   z#_Error._contents.<locals>.<genexpr>|   s     BEDT74./Es   )dict)r   attrss   ` r"   rI   z_Error._contentsw   s    
 BEBBBr#   )r'   
__module____qualname__r,   r   r)   r?   r   rE   classmethodrL   propertyrP   rS   rZ   rI   __classcell__r!   s   @r"   r   r      s     % ND
2 	1 ( (    $
Cr#   r   c                       e Zd Zy)ValidationErrorNr'   r`   ra   r   r#   r"   rg   rg          r#   rg   c                       e Zd Zy)SchemaErrorNrh   r   r#   r"   rk   rk      ri   r#   rk   c                       e Zd Zy)RefResolutionErrorNrh   r   r#   r"   rm   rm      ri   r#   rm   c                   (    e Zd Zd Zd ZereZyd Zy)UnknownTypec                 .    || _         || _        || _        y r   )typer   r   )r   rq   r   r   s       r"   r   zUnknownType.__init__   s    	 r#   c                 8   t        j                  | j                  d      }t        j                  | j                  d      }t	        j
                  dj                               | j                  t        j                  |      t        j                  |      fz  S )Nr0   r1   z
            Unknown type %r for validator with schema:
            %s

            While checking instance:
            %s
            )
r5   r6   r   r   r7   r8   r9   rq   r   r;   )r   r=   r>   s      r"   r?   zUnknownType.__unicode__   sr    ..B7NN4==;	   
 YYg.i0HIJ 	Jr#   c                 6    t        |       j                  d      S rA   rB   r(   s    r"   rE   zUnknownType.__str__   rF   r#   N)r'   r`   ra   r   r?   r   rE   r   r#   r"   ro   ro      s    

J 	1r#   ro   c                   <     e Zd Zd fd	Zd ZereZ xZS d Z xZS )FormatErrorc                 X    t         t        |   ||       || _        |x| _        | _        y r   )r   ru   r   r   r   r   )r   r   r   r!   s      r"   r   zFormatError.__init__   s)    k4)'59&++
T^r#   c                     | j                   S r   )r   r(   s    r"   r?   zFormatError.__unicode__   s    ||r#   c                 8    | j                   j                  d      S rA   )r   rD   r(   s    r"   rE   zFormatError.__str__   s    <<&&w//r#   r   )r'   r`   ra   r   r?   r   rE   rd   re   s   @r"   ru   ru      s    ,
 	0r#   ru   c                   P    e Zd ZdZeZddZd Zd Zd Z	d Z
d Zd Zed	        Zy
)	ErrorTreezG
    ErrorTrees make it easier to check which validations failed.

    c                     i | _         t        | j                        | _        |D ]D  }| }|j                  D ]  }||   }	 ||j                   |j
                  <   |j                  |_        F y r   )errorsr   r!   rI   r   r   r   	_instance)r   r|   r    	containerelements        r"   r   zErrorTree.__init__   s`    $T^^4EI ::%g.	 &05IU__-"'..I r#   c                     || j                   v S )zD
        Check whether ``instance[index]`` has any errors.

        rH   r   indexs     r"   __contains__zErrorTree.__contains__   s     &&r#   c                 j    | j                   t        ur|| v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`.

        )r}   r,   rI   r   s     r"   __getitem__zErrorTree.__getitem__   s2     >>'E,=NN5!~~e$$r#   c                 "    || j                   |<   y r   rH   )r   r   values      r"   __setitem__zErrorTree.__setitem__   s     %ur#   c                 ,    t        | j                        S )zZ
        Iterate (non-recursively) over the indices in the instance with errors.

        )iterrI   r(   s    r"   __iter__zErrorTree.__iter__   s     DNN##r#   c                     | j                   S )z0
        Same as :attr:`total_errors`.

        )total_errorsr(   s    r"   __len__zErrorTree.__len__   s        r#   c                 N    d| j                   j                  dt        |       dS )Nr%   z (z total errors)>)r!   r'   lenr(   s    r"   r)   zErrorTree.__repr__   s    +/>>+B+BCINNr#   c                 |    t        d t        | j                        D              }t        | j                        |z   S )zU
        The total number of errors in the entire tree, including children.

        c              3   8   K   | ]  \  }}t        |        y wr   )r   )r-   _trees      r"   r/   z)ErrorTree.total_errors.<locals>.<genexpr>   s     N4MD3t94Ms   )sumr   rI   r   r|   )r   child_errorss     r"   r   zErrorTree.total_errors   s1     NIdnn4MNN4;;,..r#   N)r   )r'   r`   ra   __doc__r,   r}   r   r   r   r   r   r   r)   rc   r   r   r#   r"   rz   rz      sF    
 I
1'%&$!O / /r#   rz   c                       fd}|S )Nc                 V    | j                   }t        | j                         |v|v fS r   )r   r   r   )r    r   strongweaks     r"   	relevancezby_relevance.<locals>.relevance  s.    OO	EJJ$!6	V8KKKr#   r   )r   r   r   s   `` r"   by_relevancer      s    L r#   c                     t        |       } t        | d       }|y t        t        j                  |g|       |      }|j
                  r$t        |j
                  |      }|j
                  r$|S )N)key)r   nextmax	itertoolschainr   min)r|   r   bests      r"   
best_matchr   
  s]    &\FD|yvv.C8D
,,4<<S) ,,Kr#   )collectionsr   r   r   r5   r7   
jsonschemar   jsonschema.compatr   r   	frozensetWEAK_MATCHESSTRONG_MATCHESUnsetr,   	Exceptionr   rg   rk   rm   ro   ru   objectrz   r   r   r   r   r#   r"   <module>r      s    *     , '7+,	lCY lC^	f 		& 		 	1) 120) 0 I/ I/X #>  N	 % 	r#   