
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
sÝ¨\kl  ã               @   s  d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
mZmZmZmZmZmZmZmZ ddlmZmZmZ ddlmZmZmZmZmZmZmZmZ d	d
ddddddddddddgZ eZ!dd„ Z"e#ƒ Z$e#ƒ Z%dd„ Z&dd„ Z'd7dd„Z(G dd
„ d
e#ƒZ)dd„ Z*G d d!„ d!e+ƒZ,efd"d#„Z-G d$d%„ d%ee,ƒƒZ.ydd&l/m0Z0 e0j1e.ƒ W n e2k
�rf   Y nX G d'd(„ d(e#ƒZ3G d)d*„ d*e#ƒZ4G d+d	„ d	e4ƒZ5eG d,d-„ d-e#ƒƒZ6G d.d„ de#ƒZ7eG d/d0„ d0e#ƒƒZ8d8d1d2„Z9eG d3d4„ d4e8ƒƒZ:eG d5d6„ d6e8ƒƒZ;e8`<e:`<e;`<dS )9z}
    jinja2.runtime
    ~~~~~~~~~~~~~~

    Runtime helpers.

    :copyright: (c) 2017 by the Jinja Team.
    :license: BSD.
é    N)Úchain)Ú
MethodType)ÚEvalContextÚ_context_function_types)	ÚMarkupÚsoft_unicodeÚescapeÚmissingÚconcatÚinternalcodeÚobject_type_reprÚevalcontextfunctionÚ	Namespace)ÚUndefinedErrorÚTemplateRuntimeErrorÚTemplateNotFound)ÚimapÚ	text_typeÚ	iteritemsÚimplements_iteratorÚimplements_to_stringÚstring_typesÚPY2Úwith_metaclassÚLoopContextÚTemplateReferenceÚMacror   r   r	   r
   r   Úmarkup_joinÚunicode_joinÚ	to_stringÚidentityr   r   c             C   s   | S )N© )Úxr!   r!   ú/usr/lib/python3.6/runtime.pyÚ<lambda>%   s    r$   c             C   sL   g }t t| ƒ}x4|D ],}|j|ƒ t|dƒrtdƒjt||ƒƒS qW t|ƒS )z@Concatenation that escapes if necessary and converts to unicode.Z__html__Ú )r   r   ÚappendÚhasattrr   Újoinr   r
   )ÚseqZbufÚiteratorÚargr!   r!   r#   r   +   s    



c             C   s   t tt| ƒƒS )z4Simple args to unicode conversion and concatenation.)r
   r   r   )r)   r!   r!   r#   r   6   s    c       
      C   sl   |dkri }|r|}nt |pf f|Ž}|r\|r6t |ƒ}x$t|ƒD ]\}}	|	tk	r@|	||< q@W | j| |||ƒS )z(Internal helper to for context creation.N)Údictr   r	   Zcontext_class)
ÚenvironmentZtemplate_nameÚblocksÚvarsZsharedÚglobalsÚlocalsÚparentÚkeyÚvaluer!   r!   r#   Únew_context;   s    
r5   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r   zThe `self` in templates.c             C   s
   || _ d S )N)Ú_TemplateReference__context)ÚselfÚcontextr!   r!   r#   Ú__init__S   s    zTemplateReference.__init__c             C   s   | j j| }t|| j |dƒS )Nr   )r6   r.   ÚBlockReference)r7   Únamer.   r!   r!   r#   Ú__getitem__V   s    zTemplateReference.__getitem__c             C   s   d| j j| jjf S )Nz<%s %r>)Ú	__class__Ú__name__r6   r;   )r7   r!   r!   r#   Ú__repr__Z   s    zTemplateReference.__repr__N)r>   Ú
__module__Ú__qualname__Ú__doc__r9   r<   r?   r!   r!   r!   r#   r   P   s   c             C   s   t | d| ƒS )NÚ__func__)Úgetattr)r"   r!   r!   r#   Ú	_get_funca   s    rE   c               @   s   e Zd Zdd„ ZdS )ÚContextMetac       	      C   sv   t j| |||ƒ}|f kr|S t|jƒ}ttjƒ}t|jƒ}ttjƒ}||k	r\||kr\d|_n||krr||krrd|_|S )NT)ÚtypeÚ__new__rE   ÚresolveÚContextÚresolve_or_missingÚ_legacy_resolve_modeÚ_fast_resolve_mode)	Úclsr;   ÚbasesÚdÚrvrI   Zdefault_resolverK   Zdefault_resolve_or_missingr!   r!   r#   rH   g   s    



zContextMeta.__new__N)r>   r@   rA   rH   r!   r!   r!   r#   rF   e   s   rF   c             C   s,   || j kr| j | S || jkr(| j| S |S )N)r/   r2   )r8   r3   r	   r!   r!   r#   rK   }   s
    



rK   c               @   s¾   e Zd ZdZdZdZdd„ Zdd„ Zd$dd	„Zd
d„ Z	dd„ Z
dd„ Zdd„ Zedd„ ƒZd%dd„Zdd„ ZedƒZedƒZedƒZer edƒZedƒZedƒZ[dd„ Zd d!„ Zd"d#„ ZdS )&rJ   aï  The template context holds the variables of a template.  It stores the
    values passed to the template and also the names the template exports.
    Creating instances is neither supported nor useful as it's created
    automatically at various stages of the template evaluation and should not
    be created by hand.

    The context is immutable.  Modifications on :attr:`parent` **must not**
    happen and modifications on :attr:`vars` are allowed from generated
    template code only.  Template filters and global functions marked as
    :func:`contextfunction`\s get the active context passed as first argument
    and are allowed to access the context read-only.

    The template context supports read only dict operations (`get`,
    `keys`, `values`, `items`, `iterkeys`, `itervalues`, `iteritems`,
    `__getitem__`, `__contains__`).  Additionally there is a :meth:`resolve`
    method that doesn't fail with a `KeyError` but returns an
    :class:`Undefined` object for missing variables.
    Fc             C   s\   || _ i | _|| _t| j|ƒ| _tƒ | _|| _tdd„ t	|ƒD ƒƒ| _
| jrXtt| ƒ| _d S )Nc             s   s   | ]\}}||gfV  qd S )Nr!   )Ú.0ÚkÚvr!   r!   r#   ú	<genexpr>¨   s    z#Context.__init__.<locals>.<genexpr>)r2   r/   r-   r   Úeval_ctxÚsetÚexported_varsr;   r,   r   r.   rM   r   rK   )r7   r-   r2   r;   r.   r!   r!   r#   r9   �   s    zContext.__init__c             C   sX   y$| j | }|j|ƒd }||  W n$ tk
rH   | jjd| dd�S X t|| ||ƒS )zRender a parent block.é   z#there is no parent block called %r.Úsuper)r;   )r.   ÚindexÚLookupErrorr-   Ú	undefinedr:   )r7   r;   Zcurrentr.   r[   r!   r!   r#   rZ   ¯   s    

zContext.superNc             C   s"   y| | S  t k
r   |S X dS )zfReturns an item from the template context, if it doesn't exist
        `default` is returned.
        N)ÚKeyError)r7   r3   Údefaultr!   r!   r#   Úget»   s    zContext.getc             C   s6   | j rt| |ƒ}n
| j|ƒ}|tkr2| jj|d�S |S )zŽLooks up a variable like `__getitem__` or `get` but returns an
        :class:`Undefined` object with the name of the name looked up.
        )r;   )rL   rK   r	   r-   r]   )r7   r3   rQ   r!   r!   r#   rI   Ä   s    
zContext.resolvec             C   s,   | j r"| j|ƒ}t|tƒrt}|S t| |ƒS )zxResolves a variable like :meth:`resolve` but returns the
        special `missing` value if it cannot be found.
        )rL   rI   Ú
isinstanceÚ	Undefinedr	   rK   )r7   r3   rQ   r!   r!   r#   rK   Ð   s    

zContext.resolve_or_missingc                s   t ‡ fdd„ˆ jD ƒƒS )z+Get a new dict with the exported variables.c             3   s   | ]}|ˆ j | fV  qd S )N)r/   )rR   rS   )r7   r!   r#   rU   Ý   s    z'Context.get_exported.<locals>.<genexpr>)r,   rX   )r7   r!   )r7   r#   Úget_exportedÛ   s    zContext.get_exportedc             C   s(   | j s| jS | js| j S t| jf| j ŽS )z»Return the complete context as dict including the exported
        variables.  For optimizations reasons this might not return an
        actual copy so be careful with using it.
        )r/   r2   r,   )r7   r!   r!   r#   Úget_allß   s
    zContext.get_allc             O   s²   d}t |dƒr2|j}xd	D ]}t ||ƒr|}P qW t|tƒr†t|ddƒrT| f| }n2t|ddƒrn| jf| }nt|ddƒr†| jf| }y
|||ŽS  tk
r¬   | jjdƒS X dS )
zðCall the callable with the arguments and keyword arguments
        provided but inject the active context or environment as first
        argument if the callable is a :func:`contextfunction` or
        :func:`environmentfunction`.
        TÚ__call__Úcontextfunctionr   Úenvironmentfunctionr   zGvalue was undefined because a callable raised a StopIteration exceptionN)rf   r   rg   )	r'   re   ra   r   rD   rV   r-   ÚStopIterationr]   )Z_Context__selfZ_Context__objÚargsÚkwargsZ__traceback_hide__ÚfnZfn_typer!   r!   r#   Úcallê   s(    
 


zContext.callc             C   sD   t | j| ji | jƒ dd|ƒ}| j|_|jjdd„ t| jƒD ƒƒ |S )z¹Internal helper function to create a derived context.  This is
        used in situations where the system needs a new context in the same
        template that is independent.
        TNc             s   s   | ]\}}|t |ƒfV  qd S )N)Úlist)rR   rS   rT   r!   r!   r#   rU     s    z"Context.derived.<locals>.<genexpr>)r5   r-   r;   rd   rV   r.   Úupdater   )r7   r1   r8   r!   r!   r#   Úderived  s
    zContext.derivedc                s$   ‡ fdd„}t tˆ ƒj|_ˆ |_|S )Nc                s   t | jƒ ˆ ƒƒ S )N)rD   rd   )r7   )Úmethr!   r#   r$     s    zContext._all.<locals>.<lambda>)rD   r,   rB   r>   )rp   Úproxyr!   )rp   r#   Ú_all  s    zContext._allÚkeysÚvaluesÚitemsÚiterkeysÚ
itervaluesr   c             C   s   || j kp|| jkS )N)r/   r2   )r7   r;   r!   r!   r#   Ú__contains__(  s    zContext.__contains__c             C   s   | j |ƒ}|tkrt|ƒ‚|S )zTLookup a variable or raise `KeyError` if the variable is
        undefined.
        )rK   r	   r^   )r7   r3   Úitemr!   r!   r#   r<   +  s    
zContext.__getitem__c             C   s   d| j jt| jƒ ƒ| jf S )Nz<%s %s of %r>)r=   r>   Úreprrd   r;   )r7   r!   r!   r#   r?   4  s    
zContext.__repr__)N)N)r>   r@   rA   rB   rL   rM   r9   rZ   r`   rI   rK   rc   rd   r   rl   ro   rr   rs   rt   ru   r   rv   rw   r   rx   r<   r?   r!   r!   r!   r#   rJ   …   s0   
	"
	rJ   )ÚMappingc               @   s0   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdS )	r:   z"One block on a template reference.c             C   s   || _ || _|| _|| _d S )N)r;   Ú_contextÚ_stackÚ_depth)r7   r;   r8   ÚstackÚdepthr!   r!   r#   r9   G  s    zBlockReference.__init__c             C   sF   | j d t| jƒkr,| jjjd| j dd�S t| j| j| j| j d ƒS )zSuper the block.rY   z#there is no parent block called %r.rZ   )r;   )r~   Úlenr}   r|   r-   r]   r;   r:   )r7   r!   r!   r#   rZ   M  s    zBlockReference.superc             C   s,   t | j| j | jƒƒ}| jjjr(t|ƒ}|S )N)r
   r}   r~   r|   rV   Ú
autoescaper   )r7   rQ   r!   r!   r#   re   W  s    
zBlockReference.__call__N)	r>   r@   rA   rB   r9   ÚpropertyrZ   r   re   r!   r!   r!   r#   r:   D  s   
r:   c               @   s¼   e Zd ZdZeZeZeZdZ	ddd„Z
dd„ Zdd	„ Zed
d„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zedd„ ƒZeZ[dd„ ZdS )ÚLoopContextBasez%A loop context for dynamic iteration.Nr   c             C   s"   || _ || _d| _|| _t| _d S )NrY   éÿÿÿÿ)Ú
_undefinedÚ_recurseÚindex0Údepth0r	   Ú_last_checked_value)r7   r]   Úrecurser‰   r!   r!   r#   r9   g  s
    zLoopContextBase.__init__c             G   s   |st dƒ‚|| jt|ƒ  S )z7Cycles among the arguments with the current loop index.zno items for cycling given)Ú	TypeErrorrˆ   r�   )r7   ri   r!   r!   r#   Úcyclen  s    zLoopContextBase.cyclec             G   s   | j |kr|| _ dS dS )z9Checks whether the value has changed since the last call.TF)rŠ   )r7   r4   r!   r!   r#   Úchangedt  s    
zLoopContextBase.changedc             C   s
   | j dkS )Nr   )rˆ   )r"   r!   r!   r#   r$   {  s    zLoopContextBase.<lambda>c             C   s
   | j tkS )N)Ú_afterÚ_last_iteration)r"   r!   r!   r#   r$   |  s    c             C   s
   | j d S )NrY   )rˆ   )r"   r!   r!   r#   r$   }  s    c             C   s   | j | j S )N)Úlengthrˆ   )r"   r!   r!   r#   r$   ~  s    c             C   s   | j | j S )N)r‘   r[   )r"   r!   r!   r#   r$     s    c             C   s
   | j d S )NrY   )r‰   )r"   r!   r!   r#   r$   €  s    c             C   s   | j tkr| jdƒS | j S )Nzthere is no previous item)Ú_beforeÚ_first_iterationr†   )r7   r!   r!   r#   Úprevitem‚  s    

zLoopContextBase.previtemc             C   s   | j tkr| jdƒS | j S )Nzthere is no next item)r�   r�   r†   )r7   r!   r!   r#   Únextitemˆ  s    

zLoopContextBase.nextitemc             C   s   | j S )N)r‘   )r7   r!   r!   r#   Ú__len__Ž  s    zLoopContextBase.__len__c             C   s(   | j d krtdƒ‚| j || j | jd ƒS )NzMTried to call non recursive loop.  Maybe you forgot the 'recursive' modifier.rY   )r‡   rŒ   r‰   )r7   Úiterabler!   r!   r#   Úloop‘  s    
zLoopContextBase.loopc             C   s   d| j j| j| jf S )Nz
<%s %r/%r>)r=   r>   r[   r‘   )r7   r!   r!   r#   r?   �  s    zLoopContextBase.__repr__)Nr   )r>   r@   rA   rB   r“   r’   Ú_currentr�   r�   Ú_lengthr9   r�   rŽ   rƒ   ÚfirstZlastr[   ZrevindexZ	revindex0r€   r”   r•   r–   r   r˜   re   r?   r!   r!   r!   r#   r„   _  s*   
	r„   c               @   s2   e Zd Zddd„Zedd„ ƒZdd„ Zd	d
„ ZdS )r   Nr   c             C   sV   t j| |||ƒ t|ƒ| _yt|ƒ| _W n ttfk
rF   d | _Y nX | jƒ | _	d S )N)
r„   r9   ÚiterÚ	_iteratorr�   rš   rŒ   ÚAttributeErrorÚ
_safe_nextr�   )r7   r—   r]   r‹   r‰   r!   r!   r#   r9   §  s    
zLoopContext.__init__c             C   s<   | j d kr6t| jƒ}t|ƒ| _| jd }t|ƒ| | _ | j S )Né   )rš   Útupler�   rœ   rˆ   r�   )r7   r—   Ziterations_doner!   r!   r#   r‘   µ  s    



zLoopContext.lengthc             C   s   t | ƒS )N)ÚLoopContextIterator)r7   r!   r!   r#   Ú__iter__Â  s    zLoopContext.__iter__c             C   s$   y
t | jƒS  tk
r   tS X d S )N)Únextr�   rh   r�   )r7   r!   r!   r#   rŸ   Å  s    
zLoopContext._safe_next)Nr   )r>   r@   rA   r9   rƒ   r‘   r£   rŸ   r!   r!   r!   r#   r   ¥  s   
c               @   s,   e Zd ZdZd
Zdd„ Zdd„ Zdd„ Zd	S )r¢   z The iterator for a loop context.r8   c             C   s
   || _ d S )N)r8   )r7   r8   r!   r!   r#   r9   Ñ  s    zLoopContextIterator.__init__c             C   s   | S )Nr!   )r7   r!   r!   r#   r£   Ô  s    zLoopContextIterator.__iter__c             C   sH   | j }| jd7  _|jtkr$tƒ ‚|j|_|j|_|jƒ |_|j|fS )NrY   )r8   rˆ   r�   r�   rh   r™   r’   rŸ   )r7   Zctxr!   r!   r#   Ú__next__×  s    

zLoopContextIterator.__next__N)r8   )r>   r@   rA   rB   Ú	__slots__r9   r£   r¥   r!   r!   r!   r#   r¢   Ì  s
   r¢   c               @   s:   e Zd ZdZddd„Zeedd„ ƒƒZdd„ Zd	d
„ Z	dS )r   zWraps a macro function.Nc	       	      C   sV   || _ || _t|ƒ| _|| _|| _|| _|| _|| _d|k| _	|d krL|j
}|| _d S )NÚcaller)Ú_environmentÚ_funcr�   Ú_argument_countr;   Ú	argumentsÚcatch_kwargsÚcatch_varargsr§   Úexplicit_callerr‚   Ú_default_autoescape)	r7   r-   Úfuncr;   r«   r¬   r­   r§   Zdefault_autoescaper!   r!   r#   r9   å  s    

zMacro.__init__c             O   sš  |r*t |d tƒr*|d j}|dd … }n| j}t|d | j… ƒ}t|ƒ}d}|| jkr¼xht| jt|ƒd … ƒD ]F\}}y|j	|ƒ}	W n t
k
rž   t}	Y nX |dkr¬d}|j|	ƒ qpW n| j}| jrü| rü|j	dd ƒ}
|
d krò| jjddd�}
|j|
ƒ | j�r|j|ƒ n8|�rHd|k�r.td| j ƒ‚td	| jtt|ƒƒf ƒ‚| j�rf|j|| jd … ƒ n(t|ƒ| jk�rŽtd
| jt| jƒf ƒ‚| j||ƒS )Nr   rY   Fr§   TzNo caller defined)r;   zamacro %r was invoked with two values for the special caller argument.  This is most likely a bug.z%macro %r takes no keyword argument %rz+macro %r takes not more than %d argument(s))ra   r   r‚   r¯   rm   rª   r�   Ú	enumerater«   Úpopr^   r	   r&   r®   r§   r¨   r]   r¬   rŒ   r;   r¤   rœ   r­   Ú_invoke)r7   ri   rj   r‚   r«   ZoffZfound_callerÚidxr;   r4   r§   r!   r!   r#   re   õ  sJ    

 



zMacro.__call__c             C   s   | j |Ž }|rt|ƒ}|S )z=This method is being swapped out by the async implementation.)r©   r   )r7   r«   r‚   rQ   r!   r!   r#   r³   A  s    
zMacro._invokec             C   s$   d| j j| jd krdpt| jƒf S )Nz<%s %s>Z	anonymous)r=   r>   r;   rz   )r7   r!   r!   r#   r?   H  s    zMacro.__repr__)N)
r>   r@   rA   rB   r9   r   r   re   r³   r?   r!   r!   r!   r#   r   â  s   
Kc               @   sî   e Zd ZdZdZdedefdd„Zed	d
„ ƒZ	edd„ ƒZ
e	 Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z  Z! Z" Z# Z$Z%dd„ Z&dd„ Z'dd„ Z(dd„ Z)dd„ Z*dd„ Z+dd„ Z,e,Z-dd„ Z.dS )rb   az  The default undefined type.  This undefined type can be printed and
    iterated over, but every other access will raise an :exc:`jinja2.exceptions.UndefinedError`:

    >>> foo = Undefined(name='foo')
    >>> str(foo)
    ''
    >>> not foo
    True
    >>> foo + 42
    Traceback (most recent call last):
      ...
    jinja2.exceptions.UndefinedError: 'foo' is undefined
    Ú_undefined_hintÚ_undefined_objÚ_undefined_nameÚ_undefined_exceptionNc             C   s   || _ || _|| _|| _d S )N)rµ   r¶   r·   r¸   )r7   ÚhintÚobjr;   Úexcr!   r!   r#   r9   a  s    zUndefined.__init__c             O   sl   | j dkrX| jtkr d| j }q^t| jtƒsBdt| jƒ| jf }q^dt| jƒ| jf }n| j }| j|ƒ‚dS )z{Regular callback function for undefined objects that raises an
        `jinja2.exceptions.UndefinedError` on call.
        Nz%r is undefinedz%s has no element %rz%r has no attribute %r)rµ   r¶   r	   r·   ra   r   r   r¸   )r7   ri   rj   r¹   r!   r!   r#   Ú_fail_with_undefined_errorg  s    

z$Undefined._fail_with_undefined_errorc             C   s    |d d… dkrt |ƒ‚| jƒ S )Nr    Ú__)rž   r¼   )r7   r;   r!   r!   r#   Ú__getattr__}  s    zUndefined.__getattr__c             C   s   t | ƒt |ƒkS )N)rG   )r7   Úotherr!   r!   r#   Ú__eq__Š  s    zUndefined.__eq__c             C   s   | j |ƒ S )N)rÀ   )r7   r¿   r!   r!   r#   Ú__ne__�  s    zUndefined.__ne__c             C   s   t t| ƒƒS )N)ÚidrG   )r7   r!   r!   r#   Ú__hash__�  s    zUndefined.__hash__c             C   s   dS )Nr%   r!   )r7   r!   r!   r#   Ú__str__“  s    zUndefined.__str__c             C   s   dS )Nr   r!   )r7   r!   r!   r#   r–   –  s    zUndefined.__len__c             c   s   d S )Nr!   )r7   r!   r!   r#   r£   ™  s    zUndefined.__iter__c             C   s   dS )NFr!   )r7   r!   r!   r#   Ú__nonzero__�  s    zUndefined.__nonzero__c             C   s   dS )Nrb   r!   )r7   r!   r!   r#   r?   ¡  s    zUndefined.__repr__)rµ   r¶   r·   r¸   )/r>   r@   rA   rB   r¦   r	   r   r9   r   r¼   r¾   Ú__add__Ú__radd__Ú__mul__Ú__rmul__Z__div__Z__rdiv__Ú__truediv__Ú__rtruediv__Ú__floordiv__Ú__rfloordiv__Ú__mod__Ú__rmod__Ú__pos__Ú__neg__re   r<   Ú__lt__Ú__le__Ú__gt__Ú__ge__Ú__int__Ú	__float__Ú__complex__Ú__pow__Ú__rpow__Ú__sub__Ú__rsub__rÀ   rÁ   rÃ   rÄ   r–   r£   rÅ   Ú__bool__r?   r!   r!   r!   r#   rb   O  s     lrb   c                s`   ˆdkr,ddl }|jtƒ‰ˆj|jtjƒƒ ˆdkr8t‰‡fdd„‰ G ‡ ‡‡fdd„dˆƒ}|S )ak  Given a logger object this returns a new undefined class that will
    log certain failures.  It will log iterations and printing.  If no
    logger is given a default logger is created.

    Example::

        logger = logging.getLogger(__name__)
        LoggingUndefined = make_logging_undefined(
            logger=logger,
            base=Undefined
        )

    .. versionadded:: 2.8

    :param logger: the logger to use.  If not provided, a default logger
                   is created.
    :param base: the base class to add logging functionality to.  This
                 defaults to :class:`Undefined`.
    Nr   c                sn   | j d krX| jtkr d| j }q^t| jtƒsBdt| jƒ| jf }q^dt| jƒ| jf }n| j }ˆ jd|ƒ d S )Nz%s is undefinedz%s has no element %sz%s has no attribute %szTemplate variable warning: %s)rµ   r¶   r	   r·   ra   r   r   Zwarning)Zundefr¹   )Úloggerr!   r#   Ú_log_messageÀ  s    

z,make_logging_undefined.<locals>._log_messagec                   sf   e Zd Z‡‡fdd„Z‡ ‡fdd„Z‡ ‡fdd„ZerT‡ ‡fdd„Z‡ ‡fd	d
„Zn‡ ‡fdd„Z	dS )z0make_logging_undefined.<locals>.LoggingUndefinedc                sP   yˆ j | f|ž|ŽS  | jk
rJ } zˆjdt|ƒƒ |‚W Y d d }~X nX d S )NzTemplate variable error: %s)r¼   r¸   ÚerrorÚstr)r7   ri   rj   Úe)ÚbaserÞ   r!   r#   r¼   Ò  s
    zKmake_logging_undefined.<locals>.LoggingUndefined._fail_with_undefined_errorc                s   ˆj | ƒ}ˆ | ƒ |S )N)rÄ   )r7   rQ   )rß   rã   r!   r#   rÄ   Ù  s    
z8make_logging_undefined.<locals>.LoggingUndefined.__str__c                s   ˆj | ƒ}ˆ | ƒ |S )N)r£   )r7   rQ   )rß   rã   r!   r#   r£   Þ  s    
z9make_logging_undefined.<locals>.LoggingUndefined.__iter__c                s   ˆj | ƒ}ˆ | ƒ |S )N)rÅ   )r7   rQ   )rß   rã   r!   r#   rÅ   ä  s    
z<make_logging_undefined.<locals>.LoggingUndefined.__nonzero__c                s   ˆj | ƒ}ˆ | ƒ |S )N)Ú__unicode__)r7   rQ   )rß   rã   r!   r#   rä   é  s    
z<make_logging_undefined.<locals>.LoggingUndefined.__unicode__c                s   ˆj | ƒ}ˆ | ƒ |S )N)rÝ   )r7   rQ   )rß   rã   r!   r#   rÝ   î  s    
z9make_logging_undefined.<locals>.LoggingUndefined.__bool__N)
r>   r@   rA   r¼   rÄ   r£   r   rÅ   rä   rÝ   r!   )rß   rã   rÞ   r!   r#   ÚLoggingUndefinedÐ  s   rå   )ÚloggingZ	getLoggerr>   Z
addHandlerZStreamHandlerÚsysÚstderrrb   )rÞ   rã   ræ   rå   r!   )rß   rã   rÞ   r#   Úmake_logging_undefined¥  s    
#ré   c               @   s   e Zd ZdZf Zdd„ ZdS )ÚDebugUndefineda  An undefined that returns the debug info when printed.

    >>> foo = DebugUndefined(name='foo')
    >>> str(foo)
    '{{ foo }}'
    >>> not foo
    True
    >>> foo + 42
    Traceback (most recent call last):
      ...
    jinja2.exceptions.UndefinedError: 'foo' is undefined
    c             C   s<   | j d kr2| jtkrd| j S dt| jƒ| jf S d| j  S )Nz{{ %s }}z{{ no such element: %s[%r] }}z!{{ undefined value printed: %s }})rµ   r¶   r	   r·   r   )r7   r!   r!   r#   rÄ     s    



zDebugUndefined.__str__N)r>   r@   rA   rB   r¦   rÄ   r!   r!   r!   r#   rê   ö  s   rê   c               @   s6   e Zd ZdZf Zej Z Z Z	 Z
 Z Z ZZdS )ÚStrictUndefinedas  An undefined that barks on print and iteration as well as boolean
    tests and all kinds of comparisons.  In other words: you can do nothing
    with it except checking if it's defined using the `defined` test.

    >>> foo = StrictUndefined(name='foo')
    >>> str(foo)
    Traceback (most recent call last):
      ...
    jinja2.exceptions.UndefinedError: 'foo' is undefined
    >>> not foo
    Traceback (most recent call last):
      ...
    jinja2.exceptions.UndefinedError: 'foo' is undefined
    >>> foo + 42
    Traceback (most recent call last):
      ...
    jinja2.exceptions.UndefinedError: 'foo' is undefined
    N)r>   r@   rA   rB   r¦   rb   r¼   r£   rÄ   r–   rÅ   rÀ   rÁ   rÝ   rÃ   r!   r!   r!   r#   rë     s   rë   )NNNN)NN)=rB   rç   Ú	itertoolsr   Útypesr   Zjinja2.nodesr   r   Zjinja2.utilsr   r   r   r	   r
   r   r   r   r   Zjinja2.exceptionsr   r   r   Zjinja2._compatr   r   r   r   r   r   r   r   Ú__all__r   r    Úobjectr“   r�   r   r   r5   r   rE   rG   rF   rK   rJ   Úcollectionsr{   ÚregisterÚImportErrorr:   r„   r   r¢   r   rb   ré   rê   rë   r¦   r!   r!   r!   r#   Ú<module>
   sX   ,( 
 9F'mU
Q