
Á«‘_1  ã               @   s  d  d l  m Z d  d l  m Z d  d l  m Z d  d l  m Z Gd d „  d e ƒ Z e Gd d „  d e e e ƒ ƒ Z	 Gd	 d
 „  d
 e	 ƒ Z
 e Gd d „  d e ƒ ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z d S)é   )Úimap)Úimplements_to_string)ÚPY2)Ú	text_typec               @   sm   e  Z d  Z d Z e rH d d d „ Z e d d „  ƒ Z d d „  Z n! d d	 d „ Z e d
 d „  ƒ Z d S)ÚTemplateErrorz"Baseclass for all template errors.Nc             C   s5   | d  k	 r! t  | ƒ j d ƒ } t j |  | ƒ d  S)Nzutf-8)r   ÚencodeÚ	ExceptionÚ__init__)ÚselfÚmessage© r   ú3/tmp/pip-build-5gj8f0j9/Jinja2/jinja2/exceptions.pyr	      s    zTemplateError.__init__c             C   s6   |  j  r2 |  j  d } | d  k	 r2 | j d d ƒ Sd  S)Né    zutf-8Úreplace)ÚargsÚdecode)r
   r   r   r   r   r      s    	zTemplateError.messagec             C   s   |  j  p d S)NÚ )r   )r
   r   r   r   Ú__unicode__   s    zTemplateError.__unicode__c             C   s   t  j |  | ƒ d  S)N)r   r	   )r
   r   r   r   r   r	      s    c             C   s*   |  j  r& |  j  d } | d  k	 r& | Sd  S)Nr   )r   )r
   r   r   r   r   r   !   s    	)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   Úpropertyr   r   r   r   r   r   r      s   r   c               @   s7   e  Z d  Z d Z d Z d d d „ Z d d „  Z d S)ÚTemplateNotFoundzÀRaised if a template does not exist.

    .. versionchanged:: 2.11
        If the given name is :class:`Undefined` and no message was
        provided, an :exc:`UndefinedError` is raised.
    Nc             C   sm   t  j |  | ƒ | d  k rK d d l m } t | | ƒ rE | j ƒ  | } | |  _ | |  _ | g |  _ d  S)Nr   )Ú	Undefined)	ÚIOErrorr	   Úruntimer   Ú
isinstanceZ_fail_with_undefined_errorr   ÚnameÚ	templates)r
   r   r   r   r   r   r   r	   6   s    
		zTemplateNotFound.__init__c             C   s   |  j  S)N)r   )r
   r   r   r   Ú__str__E   s    zTemplateNotFound.__str__)r   r   r   r   r   r	   r    r   r   r   r   r   )   s   r   c               @   s(   e  Z d  Z d Z f  d d d „ Z d S)ÚTemplatesNotFounda”  Like :class:`TemplateNotFound` but raised if multiple templates
    are selected.  This is a subclass of :class:`TemplateNotFound`
    exception, so just catching the base exception will catch both.

    .. versionchanged:: 2.11
        If a name in the list of names is :class:`Undefined`, a message
        about it being undefined is shown rather than the empty string.

    .. versionadded:: 2.2
    Nc             C   s´   | d  k r~ d d l  m } g  } x= | D]5 } t | | ƒ rQ | j | j ƒ q) | j | ƒ q) Wd d j t t | ƒ ƒ } t j	 |  | r— | d pš d  | ƒ t
 | ƒ |  _ d  S)Nr   )r   z(none of the templates given were found: z, éÿÿÿÿ)r   r   r   ÚappendZ_undefined_messageÚjoinr   r   r   r	   Úlistr   )r
   Únamesr   r   Úpartsr   r   r   r   r	   U   s    	#zTemplatesNotFound.__init__)r   r   r   r   r	   r   r   r   r   r!   I   s   
r!   c               @   s@   e  Z d  Z d Z d d d d „ Z d d „  Z d d „  Z d S)	ÚTemplateSyntaxErrorzBRaised to tell the user that there is a problem with the template.Nc             C   sA   t  j |  | ƒ | |  _ | |  _ | |  _ d  |  _ d |  _ d  S)NF)r   r	   Úlinenor   ÚfilenameÚsourceÚ
translated)r
   r   r)   r   r*   r   r   r   r	   l   s    				zTemplateSyntaxError.__init__c             C   sÊ   |  j  r |  j Sd |  j } |  j p, |  j } | rE d | | f } |  j d | g } |  j d  k	 r½ y |  j j ƒ  |  j d } Wn t k
 rŸ d  } Yn X| r½ | j d | j	 ƒ  ƒ d j
 | ƒ S)Nzline %dzFile "%s", %sz  r   z    Ú
)r,   r   r)   r*   r   r+   Ú
splitlinesÚ
IndexErrorr#   Ústripr$   )r
   Úlocationr   ÚlinesÚliner   r   r   r    w   s    	zTemplateSyntaxError.__str__c             C   s%   |  j  |  j |  j |  j |  j f f S)N)Ú	__class__r   r)   r   r*   )r
   r   r   r   Ú
__reduce__Ž   s    zTemplateSyntaxError.__reduce__)r   r   r   r   r	   r    r5   r   r   r   r   r(   h   s   r(   c               @   s   e  Z d  Z d Z d S)ÚTemplateAssertionErrora  Like a template syntax error, but covers cases where something in the
    template caused an error at compile time that wasn't necessarily caused
    by a syntax error.  However it's a direct subclass of
    :exc:`TemplateSyntaxError` and has the same attributes.
    N)r   r   r   r   r   r   r   r   r6   –   s   r6   c               @   s   e  Z d  Z d Z d S)ÚTemplateRuntimeErrorzoA generic runtime error in the template engine.  Under some situations
    Jinja may raise this exception.
    N)r   r   r   r   r   r   r   r   r7   ž   s   r7   c               @   s   e  Z d  Z d Z d S)ÚUndefinedErrorz<Raised if a template tries to operate on :class:`Undefined`.N)r   r   r   r   r   r   r   r   r8   ¤   s   r8   c               @   s   e  Z d  Z d Z d S)ÚSecurityErrorzWRaised if a template tries to do something insecure if the
    sandbox is enabled.
    N)r   r   r   r   r   r   r   r   r9   ¨   s   r9   c               @   s   e  Z d  Z d Z d S)ÚFilterArgumentErrorzQThis error is raised if a filter was called with inappropriate
    arguments
    N)r   r   r   r   r   r   r   r   r:   ®   s   r:   N)Ú_compatr   r   r   r   r   r   r   ÚLookupErrorr   r!   r(   r6   r7   r8   r9   r:   r   r   r   r   Ú<module>   s   !-