U
    @Þ«^1  ã                   @   sÐ   d dl mZ d dl mZ d dl mZ d dl mZ G dd„ deƒZeG dd„ deeeƒƒZ	G d	d
„ d
e	ƒZ
e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dS )é   )Úimap)Úimplements_to_string)ÚPY2)Ú	text_typec                   @   sJ   e Zd ZdZer0d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   s&   |d k	rt |ƒ d¡}t | |¡ d S )Núutf-8)r   ÚencodeÚ	ExceptionÚ__init__©ÚselfÚmessage© r   ú5/tmp/pip-unpacked-wheel-o736f1kv/jinja2/exceptions.pyr
      s    zTemplateError.__init__c                 C   s(   | j r$| j d }|d k	r$| dd¡S d S )Né    r   Úreplace)ÚargsÚdecoder   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  | |¡ d S ©N)r	   r
   r   r   r   r   r
      s    c                 C   s    | j r| j d }|d k	r|S d S )Nr   )r   r   r   r   r   r   !   s    
)N)N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   Úpropertyr   r   r   r   r   r   r      s   



r   c                   @   s&   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   sN   t  | |¡ |d kr6ddlm} t||ƒr2| ¡  |}|| _|| _|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 r   r   r   r   r   r   Ú__str__E   s    zTemplateNotFound.__str__)N)r   r   r   r   r   r
   r&   r   r   r   r   r   )   s   	
r   c                   @   s   e Zd ZdZ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
    r   Nc                 C   s€   |d krXddl m} g }|D ]&}t||ƒr8| |j¡ q| |¡ qdd tt|ƒ¡ }t 	| |rj|d pld |¡ 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   N)r   r   r   r   r
   r   r   r   r   r'   I   s   r'   c                   @   s*   e Zd ZdZ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   s.   t  | |¡ || _|| _|| _d | _d| _d S )NF)r   r
   Úlinenor$   ÚfilenameÚsourceÚ
translated)r   r   r/   r$   r0   r   r   r   r
   l   s    zTemplateSyntaxError.__init__c                 C   sœ   | j r| jS d| j }| jp | j}|r2d||f }| jd| g}| jd k	r’z| j ¡ | jd  }W n tk
rz   d }Y nX |r’| d| 	¡  ¡ d 
|¡S )Nzline %dzFile "%s", %sz  r   z    Ú
)r2   r   r/   r0   r$   r1   Ú
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 r   )Ú	__class__r   r/   r$   r0   r   r   r   r   Ú
__reduce__Ž   s    zTemplateSyntaxError.__reduce__)NN)r   r   r   r   r
   r&   r;   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   r<   –   s   r<   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.
    Nr=   r   r   r   r   r>   ž   s   r>   c                   @   s   e Zd ZdZdS )ÚUndefinedErrorz<Raised if a template tries to operate on :class:`Undefined`.Nr=   r   r   r   r   r?   ¤   s   r?   c                   @   s   e Zd ZdZdS )ÚSecurityErrorzWRaised if a template tries to do something insecure if the
    sandbox is enabled.
    Nr=   r   r   r   r   r@   ¨   s   r@   c                   @   s   e Zd ZdZdS )ÚFilterArgumentErrorzQThis error is raised if a filter was called with inappropriate
    arguments
    Nr=   r   r   r   r   rA   ®   s   rA   N)Ú_compatr   r   r   r   r	   r   r!   ÚLookupErrorr   r'   r.   r<   r>   r?   r@   rA   r   r   r   r   Ú<module>   s   !-