ó
V]c           @   s}  d  d l  m Z m Z d  d l 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 d e f d     YZ d	 e f d
     YZ d e f d     YZ e j d e  d e f d     Y Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ e e d  Z e   Z e d  Z d S(   i’’’’(   t   defaultdictt   dequeN(   t   _utils(   t   PY3t	   iteritemst   anyOft   oneOft   _Errorc        
   B   s   e  Z e d	 d
 d e e e d d
 d  	 Z d   Z d   Z e rK e Z n	 d   Z e	 d    Z
 e d    Z e d    Z d   Z d   Z RS(   c         C   sŠ   t  t |   j | | | | | | | | |	 |
 
 | |  _ t |  |  _ |  _ t |	  |  _ |  _ t	 |  |  _
 | |  _ |  _ | |  _ | |  _ | |  _ | |  _ |
 |  _ x | D] } |  | _ q¹ Wd  S(   N(   t   superR   t   __init__t   messageR   t   patht   relative_patht   schema_patht   relative_schema_patht   listt   contextt   causet	   __cause__t	   validatort   validator_valuet   instancet   schemat   parent(   t   selfR
   R   R   R   R   R   R   R   R   R   t   error(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR	      s.    						c         C   s   d |  j  j |  j f S(   Ns   <%s: %r>(   t	   __class__t   __name__R
   (   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   __repr__:   s    c      
   C   sŪ   |  j  |  j |  j |  j f } t d   | D  r; |  j St j |  j d d } t j |  j d d } |  j t j	 d j
    |  j  |  j t j t |  j  d   t j |  |  j t j |  j  t j |  f S(   Nc         s   s   |  ] } | t  k Vq d  S(   N(   t   _unset(   t   .0t   m(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pys	   <genexpr>A   s    t   widthiH   sl   

            Failed validating %r in %s%s:
            %s

            On %s%s:
            %s
            i’’’’(   R   R   R   R   t   anyR
   t   pprintt   pformatt   textwrapt   dedentt   rstript!   _word_for_schema_in_error_messageR   t   format_as_indexR   R   t   indentt#   _word_for_instance_in_error_messageR   (   R   t   essential_for_verboset   pschemat	   pinstance(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   __unicode__=   s    c         C   s   t  |   j d  S(   Ns   utf-8(   t   unicodet   encode(   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   __str__[   s    c         C   s   |  | j      S(   N(   t	   _contents(   t   clst   other(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   create_from^   s    c         C   sE   |  j  } | d  k r |  j St |  j  } | j t | j   | S(   N(   R   t   NoneR   R   t
   extendleftt   reversedt   absolute_path(   R   R   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR9   b   s    	c         C   sE   |  j  } | d  k r |  j St |  j  } | j t | j   | S(   N(   R   R6   R   R   R7   R8   t   absolute_schema_path(   R   R   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR:   l   s    	c         K   sI   xB t  |  D]4 \ } } t |  |  t k r t |  | |  q q Wd  S(   N(   R   t   getattrR   t   setattr(   R   t   kwargst   kt   v(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   _setv   s    c      
      s    d } t    f 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   t   attr(   R   (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pys	   <genexpr>   s    (
   R
   R   R   R   R   R   R   R   R   R   (   t   dict(   R   t   attrs(    (   R   s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR2   {   s     (    N(    (    (   R   t
   __module__R   R6   R	   R   R.   R   R1   t   classmethodR5   t   propertyR9   R:   R@   R2   (    (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR      s&   				

	t   ValidationErrorc           B   s   e  Z d  Z d Z RS(   R   R   (   R   RD   R'   R*   (    (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyRG      s   t   SchemaErrorc           B   s   e  Z d  Z d Z RS(   t
   metaschemaR   (   R   RD   R'   R*   (    (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyRH      s   t   hasht   RefResolutionErrorc           B   s   e  Z e j   Z d    Z RS(   c         C   s   t  |  j  S(   N(   t   strt   _cause(   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR1      s    (   R   RD   RA   t   ibRM   R1   (    (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyRK      s   t   UndefinedTypeCheckc           B   s2   e  Z d    Z d   Z e r' e Z n	 d   Z RS(   c         C   s   | |  _  d  S(   N(   t   type(   R   RP   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR	      s    c         C   s   d |  j  S(   Ns'   Type %r is unknown to this type checker(   RP   (   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR.      s    c         C   s   t  |   j d  S(   Ns   utf-8(   R/   R0   (   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR1       s    (   R   RD   R	   R.   R   R1   (    (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyRO      s
   			t   UnknownTypec           B   s2   e  Z d    Z d   Z e r' e Z n	 d   Z RS(   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   RP   R   R   (   R   RP   R   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR	   „   s    		c         C   se   t  j |  j d d } t  j |  j d d } t j d j    |  j t j	 |  t j	 |  f S(   NR    iH   s   
            Unknown type %r for validator with schema:
            %s

            While checking instance:
            %s
            (
   R"   R#   R   R   R$   R%   R&   RP   R   R)   (   R   R,   R-   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR.   Ŗ   s
    c         C   s   t  |   j d  S(   Ns   utf-8(   R/   R0   (   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR1   ¹   s    (   R   RD   R	   R.   R   R1   (    (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyRQ   ¤   s
   			t   FormatErrorc           B   s5   e  Z d d   Z d   Z e r* e Z n	 d   Z RS(   c         C   s6   t  t |   j | |  | |  _ | |  _ |  _ d  S(   N(   R   RR   R	   R
   R   R   (   R   R
   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR	   ¾   s    	c         C   s   |  j  S(   N(   R
   (   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR.   Ć   s    c         C   s   |  j  j d  S(   Ns   utf-8(   R
   R0   (   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR1   É   s    N(   R   RD   R6   R	   R.   R   R1   (    (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyRR   ½   s
   		t	   ErrorTreec           B   se   e  Z d  Z e Z d	 d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z e d    Z RS(
   sG   
    ErrorTrees make it easier to check which validations failed.

    c         C   sp   i  |  _  t |  j  |  _ xN | D]F } |  } x | j D] } | | } q8 W| | j  | j <| j | _ q" Wd  S(   N(   t   errorsR    R   R2   R   R   R   t	   _instance(   R   RT   R   t	   containert   element(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR	   Õ   s    	c         C   s   | |  j  k S(   sD   
        Check whether ``instance[index]`` has any errors.

        (   R2   (   R   t   index(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   __contains__į   s    c         C   s4   |  j  t k	 r) | |  k r) |  j  | n  |  j | S(   s]  
        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 `exceptions.LookupError`.

        (   RU   R   R2   (   R   RX   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   __getitem__é   s    c         C   s   | |  j  | <d  S(   N(   R2   (   R   RX   t   value(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   __setitem__ų   s    c         C   s   t  |  j  S(   sZ   
        Iterate (non-recursively) over the indices in the instance with errors.

        (   t   iterR2   (   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   __iter__ū   s    c         C   s   |  j  S(   s*   
        Same as `total_errors`.

        (   t   total_errors(   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   __len__  s    c         C   s   d |  j  j t |   f S(   Ns   <%s (%s total errors)>(   R   R   t   len(   R   (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR     s    c         C   s0   t  d   t |  j  D  } t |  j  | S(   sU   
        The total number of errors in the entire tree, including children.

        c         s   s!   |  ] \ } } t  |  Vq d  S(   N(   Ra   (   R   t   _t   tree(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pys	   <genexpr>  s    (   t   sumR   R2   Ra   RT   (   R   t   child_errors(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyR_     s    (    (   R   RD   t   __doc__R   RU   R	   RY   RZ   R\   R^   R`   R   RF   R_   (    (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyRS   Ķ   s   						c            s      f d   } | S(   Nc            s,   |  j  } t |  j  |  k |   k f S(   N(   R   Ra   R   (   R   R   (   t   strongt   weak(    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt	   relevance  s    	(    (   Rh   Rg   Ri   (    (   Rg   Rh   s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   by_relevance  s    c         C   su   t  |   }  t |  d   } | d  k r+ d  St t j | g |   d | } x" | j rp t | j d | } qO W| S(   Nt   key(   R]   t   nextR6   t   maxt	   itertoolst   chainR   t   min(   RT   Rk   t   best(    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt
   best_match#  s    !(    t   collectionsR    R   Rn   R"   R$   RA   t
   jsonschemaR   t   jsonschema.compatR   R   t	   frozensett   WEAK_MATCHESt   STRONG_MATCHESt   UnsetR   t	   ExceptionR   RG   RH   t   st   TrueRK   RO   RQ   RR   t   objectRS   Rj   Ri   Rr   (    (    (    s4   lib/python2.7/site-packages/jsonschema/exceptions.pyt   <module>   s*   	qL	