
_w                 @   sW  d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 d d	 l
 m Z d d
 l
 m Z d d l
 m Z d d l
 m Z d d l
 m Z d d l
 m Z d d l
 m Z d d l
 m Z d d l
 m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m  Z  d d d d d  d! d" d# d$ d% d& d' d( d) d* g Z! e Z" d+ d'   Z# d, d$   Z$ d- d%   Z% d d d d d. d/  Z& Gd0 d   d e'  Z( d1 d2   Z) Gd3 d4   d4 e*  Z+ e d5 d6  Z, Gd7 d8   d8 e e+   Z- e j. j/ e-  Gd9 d:   d: e'  Z0 e Gd; d   d   Z1 Gd< d   d e'  Z2 e Gd= d*   d* e'   Z3 d d d> d?  Z4 Gd@ dA   dA e3  Z5 e GdB dC   dC e3   Z6 e GdD dE   dE e3   Z7 e3 `8 e5 `8 e6 `8 e7 `8 d S)Fz;The runtime functions and state used by compiled templates.    N)chain)
MethodType)escape)Markup)soft_unicode   )abc)imap)implements_iterator)implements_to_string)	iteritems)PY2)string_types)	text_type)with_metaclass)TemplateNotFound)TemplateRuntimeError)UndefinedError)EvalContext)concat)evalcontextfunction)internalcode)missing)	Namespace)object_type_reprLoopContextTemplateReferenceMacror   r   r   r   r   markup_joinunicode_join	to_stringidentityr   r   	Undefinedc             C   s   |  S)zLReturns its argument. Useful for certain things in the
    environment.
     )xr#   r#   0/tmp/pip-build-5gj8f0j9/Jinja2/jinja2/runtime.pyr!   7   s    c             C   sh   g  } t  t |   } xF | D]> } | j |  t | d  r t d  j t | |   Sq Wt |  S)z@Concatenation that escapes if necessary and converts to unicode.__html__ )r	   r   appendhasattrr   joinr   r   )seq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   I   s    c       
      C   s   | d k r i  } | r! | } n t  | p- f  |  } | r | rN t  |  } x0 t |  D]" \ } }	 |	 t k	 r[ |	 | | <q[ W|  j |  | | |  S)z%Internal helper for context creation.N)dictr   r   Zcontext_class)
environmentZtemplate_nameblocksvarsZsharedglobalslocalsparentkeyvaluer#   r#   r%   new_contextN   s    
	r8   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__l   s    zTemplateReference.__init__c             C   s&   |  j  j | } t | |  j  | d  S)Nr   )r9   r1   BlockReference)r:   namer1   r#   r#   r%   __getitem__o   s    zTemplateReference.__getitem__c             C   s   d |  j  j |  j j f S)Nz<%s %r>)	__class____name__r9   r>   )r:   r#   r#   r%   __repr__s   s    zTemplateReference.__repr__N)rA   
__module____qualname____doc__r<   r?   rB   r#   r#   r#   r%   r   i   s   c             C   s   t  |  d |   S)N__func__)getattr)r$   r#   r#   r%   	_get_funcw   s    rH   c               @   s   e  Z d  Z d d   Z d S)ContextMetac       	      C   s   t  j |  | | |  } | f  k r( | St | j  } t t j  } t | j  } t t j  } | | k	 r | | k r d | _ n! | | k r | | k r d | _ | S)NT)type__new__rH   resolveContextresolve_or_missing_legacy_resolve_mode_fast_resolve_mode)	Zmcsr>   basesdrvrL   Zdefault_resolverN   Zdefault_resolve_or_missingr#   r#   r%   rK   |   s    	zContextMeta.__new__N)rA   rC   rD   rK   r#   r#   r#   r%   rI   {   s   rI   c             C   s8   | |  j  k r |  j  | S| |  j k r4 |  j | S| S)N)r2   r5   )r;   r6   r   r#   r#   r%   rN      s
    rN   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)$rM   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 r t 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>)r5   r2   r0   r   eval_ctxsetexported_varsr>   r/   r   r1   rP   r   rN   )r:   r0   r5   r>   r1   r#   r#   r%   r<      s    				"	zContext.__init__c             C   sn   y, |  j  | } | j |  d } | | Wn, t k
 rZ |  j j d | d d SYn Xt | |  | |  S)zRender a parent block.r   z#there is no parent block called %r.r>   super)r1   indexLookupErrorr0   	undefinedr=   )r:   r>   currentr1   r\   r#   r#   r%   r[      s    	zContext.superNc             C   s)   y |  | SWn t  k
 r$ | SYn Xd S)zfReturns an item from the template context, if it doesn't exist
        `default` is returned.
        N)KeyError)r:   r6   defaultr#   r#   r%   get   s    zContext.getc             C   sM   |  j  r t |  |  } n |  j |  } | t k rI |  j j d |  S| S)zLooks up a variable like `__getitem__` or `get` but returns an
        :class:`Undefined` object with the name of the name looked up.
        r>   )rO   rN   r   r0   r^   )r:   r6   rS   r#   r#   r%   rL      s    	zContext.resolvec             C   s>   |  j  r1 |  j |  } t | t  r- t } | St |  |  S)zxResolves a variable like :meth:`resolve` but returns the
        special `missing` value if it cannot be found.
        )rO   rL   
isinstancer"   r   rN   )r:   r6   rS   r#   r#   r%   rN      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)r2   )rT   rU   )r:   r#   r%   rW      s    z'Context.get_exported.<locals>.<genexpr>)r/   rZ   )r:   r#   )r:   r%   get_exported   s    zContext.get_exportedc             C   s3   |  j  s |  j S|  j s  |  j  St |  j |  j   S)zReturn 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.
        )r2   r5   r/   )r:   r#   r#   r%   get_all   s
    		zContext.get_allc             O   s  d } t  | d  rE | j } x$ d	 D] } t  | |  r% | } Pq% Wt |  r t | d d  d k ry |  f | } nS t | d d  d k r |  j f | } n( t | d d  d k r |  j f | } y | | |   SWn" t k
 r|  j j d  SYn Xd S)
zCall 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   environmentfunctionFzGvalue was undefined because a callable raised a StopIteration exceptionN)rg   r   rh   )r)   rf   callablerG   rX   r0   StopIterationr^   )Z_Context__selfZ_Context__objargskwargsZ__traceback_hide__fnZfn_typer#   r#   r%   call  s,    	  
	zContext.callc             C   s`   t  |  j |  j i  |  j   d d |  } |  j | _ | j j d d   t |  j  D  | S)zInternal 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)rT   rU   rV   r#   r#   r%   rW   3  s    z"Context.derived.<locals>.<genexpr>)r8   r0   r>   re   rX   r1   updater   )r:   r4   r;   r#   r#   r%   derived*  s
    '&zContext.derivedc                s4     f d d   } t  t    j | _   | _ | S)Nc                s   t  |  j        S)N)rG   re   )r:   )methr#   r%   proxy7  s    zContext._all.<locals>.proxy)rG   r/   rE   rA   )rr   rs   r#   )rr   r%   _all6  s    	zContext._allkeysvaluesitemsiterkeys
itervaluesr   c             C   s   | |  j  k p | |  j k S)N)r2   r5   )r:   r>   r#   r#   r%   __contains__I  s    zContext.__contains__c             C   s+   |  j  |  } | t k r' t |   | S)zTLookup a variable or raise `KeyError` if the variable is
        undefined.
        )rN   r   r`   )r:   r6   itemr#   r#   r%   r?   L  s    zContext.__getitem__c             C   s&   d |  j  j t |  j    |  j f S)Nz<%s %s of %r>)r@   rA   reprre   r>   )r:   r#   r#   r%   rB   U  s    	zContext.__repr__)rA   rC   rD   rE   rO   rP   r<   r[   rb   rL   rN   rd   re   r   rn   rq   rt   ru   rv   rw   r   rx   ry   r   rz   r?   rB   r#   r#   r#   r%   rM      s0   	&	rM   c               @   sF   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)r:   r>   r;   stackdepthr#   r#   r%   r<   c  s    			zBlockReference.__init__c             C   s_   |  j  d t |  j  k r< |  j j j d |  j d d St |  j |  j |  j |  j  d  S)zSuper the block.r   z#there is no parent block called %r.r>   r[   )r   lenr~   r}   r0   r^   r>   r=   )r:   r#   r#   r%   r[   i  s    zBlockReference.superc             C   s>   t  |  j |  j |  j   } |  j j j r: t |  } | S)N)r   r~   r   r}   rX   
autoescaper   )r:   rS   r#   r#   r%   rf   r  s    zBlockReference.__call__N)	rA   rC   rD   rE   r<   propertyr[   r   rf   r#   r#   r#   r%   r=   `  s   	r=   c               @   sf  e  Z d  Z d Z d+ Z d Z e Z e Z e Z	 e Z
 d d d d  Z e d d    Z e 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 d d   Z e d d    Z e d d    Z e d d    Z d d    Z d! d"   Z d# d$   Z d% d&   Z e d' d(    Z d) d*   Z  d S),r   zeA wrapper iterable for dynamic ``for`` loops, with information
    about the loop and iteration.
    r   Nr   c             C   s:   | |  _  |  j |  |  _ | |  _ | |  _ | |  _ d S)a@  
        :param iterable: Iterable to wrap.
        :param undefined: :class:`Undefined` class to use for next and
            previous items.
        :param recurse: The function to render the loop body when the
            loop is marked recursive.
        :param depth0: Incremented when looping recursively.
        N)	_iterable_to_iterator	_iterator
_undefined_recursedepth0)r:   iterabler^   Zrecurser   r#   r#   r%   r<     s
    				zLoopContext.__init__c             C   s
   t  |   S)N)iter)r   r#   r#   r%   r     s    zLoopContext._to_iteratorc             C   s   |  j  d k	 r |  j  Sy t |  j  |  _  WnV t k
 r t |  j  } |  j |  |  _ t |  |  j |  j t	 k	 |  _  Yn X|  j  S)zLength of the iterable.

        If the iterable is a generator or otherwise does not have a
        size, it is eagerly evaluated to get a size.
        N)
_lengthr   r   	TypeErrorro   r   r   r\   _afterr   )r:   r   r#   r#   r%   length  s    (zLoopContext.lengthc             C   s   |  j  S)N)r   )r:   r#   r#   r%   __len__  s    zLoopContext.__len__c             C   s   |  j  d S)zBHow many levels deep a recursive loop currently is, starting at 1.r   )r   )r:   r#   r#   r%   r     s    zLoopContext.depthc             C   s   |  j  d S)z-Current iteration of the loop, starting at 1.r   )index0)r:   r#   r#   r%   r\     s    zLoopContext.indexc             C   s   |  j  |  j S)zrNumber of iterations from the end of the loop, ending at 0.

        Requires calculating :attr:`length`.
        )r   r\   )r:   r#   r#   r%   	revindex0  s    zLoopContext.revindex0c             C   s   |  j  |  j S)zrNumber of iterations from the end of the loop, ending at 1.

        Requires calculating :attr:`length`.
        )r   r   )r:   r#   r#   r%   revindex  s    zLoopContext.revindexc             C   s   |  j  d k S)z0Whether this is the first iteration of the loop.r   )r   )r:   r#   r#   r%   first  s    zLoopContext.firstc             C   s2   |  j  t k	 r |  j  St |  j t  |  _  |  j  S)a  Return the next element in the iterable, or :data:`missing`
        if the iterable is exhausted. Only peeks one item ahead, caching
        the result in :attr:`_last` for use in subsequent checks. The
        cache is reset when :meth:`__next__` is called.
        )r   r   nextr   )r:   r#   r#   r%   
_peek_next  s    zLoopContext._peek_nextc             C   s   |  j    t k S)zWhether this is the last iteration of the loop.

        Causes the iterable to advance early. See
        :func:`itertools.groupby` for issues this can cause.
        The :func:`groupby` filter avoids that issue.
        )r   r   )r:   r#   r#   r%   last  s    zLoopContext.lastc             C   s   |  j  r |  j d  S|  j S)zZThe item in the previous iteration. Undefined during the
        first iteration.
        zthere is no previous item)r   r   _before)r:   r#   r#   r%   previtem  s    	zLoopContext.previtemc             C   s)   |  j    } | t k r% |  j d  S| S)zThe item in the next iteration. Undefined during the last
        iteration.

        Causes the iterable to advance early. See
        :func:`itertools.groupby` for issues this can cause.
        The :func:`groupby` filter avoids that issue.
        zthere is no next item)r   r   r   )r:   rS   r#   r#   r%   nextitem  s    	zLoopContext.nextitemc             G   s'   | s t  d   | |  j t |  S)zReturn a value from the given args, cycling through based on
        the current :attr:`index0`.

        :param args: One or more values to cycle through.
        zno items for cycling given)r   r   r   )r:   rk   r#   r#   r%   cycle  s    zLoopContext.cyclec             G   s    |  j  | k r | |  _  d Sd S)zReturn ``True`` if previously called with a different value
        (including when called for the first time).

        :param value: One or more values to compare to the last call.
        TF)_last_changed_value)r:   r7   r#   r#   r%   changed  s    	zLoopContext.changedc             C   s   |  S)Nr#   )r:   r#   r#   r%   __iter__  s    zLoopContext.__iter__c             C   sa   |  j  t k	 r$ |  j  } t |  _  n t |  j  } |  j d 7_ |  j |  _ | |  _ | |  f S)Nr   )r   r   r   r   r   _currentr   )r:   rS   r#   r#   r%   __next__  s    		zLoopContext.__next__c             C   s7   |  j  d k r t d   |  j  | |  j  d |  j S)zWhen iterating over nested data, render the body of the loop
        recursively with the given inner iterable data.

        The loop must have the ``recursive`` marker for this to work.
        NzCThe loop must have the 'recursive' marker to be called recursively.r   )r   r   r   )r:   r   r#   r#   r%   rf   (  s    	zLoopContext.__call__c             C   s   d |  j  j |  j |  j f S)Nz
<%s %d/%d>)r@   rA   r\   r   )r:   r#   r#   r%   rB   6  s    zLoopContext.__repr__)!rA   rC   rD   rE   r   r   r   r   r   r   r   r<   staticmethodr   r   r   r   r   r\   r   r   r   r   r   r   r   r   r   r   r   r   rf   rB   r#   r#   r#   r%   r   z  s4   

c               @   sU   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   s   | |  _  | |  _ t |  |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d | k |  _	 | d  k rr | j
 } | |  _ d  S)Ncaller)_environment_funcr   _argument_countr>   	argumentscatch_kwargscatch_varargsr   explicit_callerr   _default_autoescape)	r:   r0   funcr>   r   r   r   r   Zdefault_autoescaper#   r#   r%   r<   =  s    								zMacro.__init__c       
      O   s  | r9 t  | d t  r9 | d j } | d d   } n	 |  j } t | d  |  j   } t |  } d } | |  j k r xz |  j t |  d   D]S } y | j |  } Wn t	 k
 r t
 } Yn X| d k r d } | j |  q Wn	 |  j } |  j rL| rL| j d d   }	 |	 d  k r?|  j j d d d }	 | j |	  |  j re| j |  nJ | rd | k rt d |  j   t d	 |  j t t |   f   |  j r| j | |  j d    n7 t |  |  j k rt d
 |  j t |  j  f   |  j | |  S)Nr   r   Fr   TzNo caller definedr>   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))rc   r   r   r   ro   r   r   r   popr`   r   r(   r   r   r   r^   r   r   r>   r   r   r   _invoke)
r:   rk   rl   r   r   offZfound_callerr>   r7   r   r#   r#   r%   rf   U  sN    	 			zMacro.__call__c             C   s%   |  j  |   } | r! t |  } | S)z=This method is being swapped out by the async implementation.)r   r   )r:   r   r   rS   r#   r#   r%   r     s    zMacro._invokec             C   s2   d |  j  j |  j d  k r! d p- t |  j  f S)Nz<%s %s>Z	anonymous)r@   rA   r>   r|   )r:   r#   r#   r%   rB     s    	zMacro.__repr__)
rA   rC   rD   rE   r<   r   r   rf   r   rB   r#   r#   r#   r%   r   :  s   Oc               @   s>  e  Z d  Z d Z d Z d e d e d d  Z e 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   Z0 d S) r"   ah  The default undefined type.  This undefined type can be printed and
    iterated over, but every other access will raise an :exc:`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   )r:   hintobjr>   excr#   r#   r%   r<     s    			zUndefined.__init__c             C   sp   |  j  r |  j  S|  j t k r* d |  j St |  j t  sV d t |  j  |  j f Sd t |  j  |  j f S)zXBuild a message about the undefined value based on how it was
        accessed.
        z%r is undefinedz%s has no element %rz%r has no attribute %r)r   r   r   r   rc   r   r   )r:   r#   r#   r%   _undefined_message  s    	zUndefined._undefined_messagec             O   s   |  j  |  j   d S)zeRaise an :exc:`UndefinedError` when operations are performed
        on the undefined value.
        N)r   r   )r:   rk   rl   r#   r#   r%   _fail_with_undefined_error  s    z$Undefined._fail_with_undefined_errorc             C   s,   | d  d  d k r" t  |   |  j   S)N   __)AttributeErrorr   )r:   r>   r#   r#   r%   __getattr__  s    zUndefined.__getattr__c             C   s   t  |   t  |  k S)N)rJ   )r:   otherr#   r#   r%   __eq__!  s    zUndefined.__eq__c             C   s   |  j  |  S)N)r   )r:   r   r#   r#   r%   __ne__$  s    zUndefined.__ne__c             C   s   t  t |    S)N)idrJ   )r:   r#   r#   r%   __hash__'  s    zUndefined.__hash__c             C   s   d S)Nr'   r#   )r:   r#   r#   r%   __str__*  s    zUndefined.__str__c             C   s   d S)Nr   r#   )r:   r#   r#   r%   r   -  s    zUndefined.__len__c             c   s   d  S)Nr#   )r:   r#   r#   r%   r   0  s    zUndefined.__iter__c             C   s   d S)NFr#   )r:   r#   r#   r%   __nonzero__4  s    zUndefined.__nonzero__c             C   s   d S)Nr"   r#   )r:   r#   r#   r%   rB   9  s    zUndefined.__repr__)r   r   r   r   )1rA   rC   rD   rE   	__slots__r   r   r<   r   r   r   r   r   __add____radd____mul____rmul__Z__div__Z__rdiv____truediv____rtruediv____floordiv____rfloordiv____mod____rmod____pos____neg__rf   r?   __lt____le____gt____ge____int__	__float____complex____pow____rpow____sub____rsub__r   r   r   r   r   r   r   __bool__rB   r#   r#   r#   r%   r"     s&      2nc                s    d k r@ d d l  } | j t    j | j t j    d k rR t   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                s   |  j  d  k r~ |  j t k r. d |  j } q t |  j t  s_ d 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   rc   r   r   warning)Zundefr   )loggerr#   r%   _log_messageY  s    	z,make_logging_undefined.<locals>._log_messagec                   s   e  Z d  Z   f d d   Z    f d d   Z    f d d   Z e r~    f d d   Z    f d	 d
   Z n    f d d   Z	 d S)z0make_logging_undefined.<locals>.LoggingUndefinedc                sb   y   j  |  | |  SWnD |  j k
 r] } z!  j d t |   |  WYd  d  } ~ Xn Xd  S)NzTemplate variable error: %s)r   r   errorstr)r:   rk   rl   e)baser   r#   r%   r   l  s
    zKmake_logging_undefined.<locals>.LoggingUndefined._fail_with_undefined_errorc                s    j  |   }   |   | S)N)r   )r:   rS   )r   r   r#   r%   r   s  s    
z8make_logging_undefined.<locals>.LoggingUndefined.__str__c                s    j  |   }   |   | S)N)r   )r:   rS   )r   r   r#   r%   r   x  s    
z9make_logging_undefined.<locals>.LoggingUndefined.__iter__c                s    j  |   }   |   | S)N)r   )r:   rS   )r   r   r#   r%   r     s    
z<make_logging_undefined.<locals>.LoggingUndefined.__nonzero__c                s    j  |   }   |   | S)N)__unicode__)r:   rS   )r   r   r#   r%   r     s    
z<make_logging_undefined.<locals>.LoggingUndefined.__unicode__c                s    j  |   }   |   | S)N)r   )r:   rS   )r   r   r#   r%   r     s    
z9make_logging_undefined.<locals>.LoggingUndefined.__bool__N)
rA   rC   rD   r   r   r   r   r   r   r   r#   )r   r   r   r#   r%   LoggingUndefinedk  s   r   )logging	getLoggerrA   
addHandlerStreamHandlersysstderrr"   )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 d   Z e Z d S)ChainableUndefineda  An undefined that is chainable, where both ``__getattr__`` and
    ``__getitem__`` return itself rather than raising an
    :exc:`UndefinedError`.

    >>> foo = ChainableUndefined(name='foo')
    >>> str(foo.bar['baz'])
    ''
    >>> foo.bar['baz'] + 42
    Traceback (most recent call last):
      ...
    jinja2.exceptions.UndefinedError: 'foo' is undefined

    .. versionadded:: 2.11.0
    c             C   s
   |  j    S)N)r   )r:   r#   r#   r%   r&     s    zChainableUndefined.__html__c             C   s   |  S)Nr#   )r:   _r#   r#   r%   r     s    zChainableUndefined.__getattr__N)rA   rC   rD   rE   r   r&   r   r?   r#   r#   r#   r%   r     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   sN   |  j  d  k rC |  j t k r) d |  j Sd t |  j  |  j f Sd |  j  S)Nz{{ %s }}z{{ no such element: %s[%r] }}z!{{ undefined value printed: %s }})r   r   r   r   r   )r:   r#   r#   r%   r     s    zDebugUndefined.__str__N)rA   rC   rD   rE   r   r   r#   r#   r#   r%   r     s   r   c               @   sA   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)rA   rC   rD   rE   r   r"   r   r   r   r   r   r   r   r   r   r#   r#   r#   r%   r     s   r   )9rE   r   	itertoolsr   typesr   Z
markupsafer   r   r   _compatr   r	   r
   r   r   r   r   r   r   
exceptionsr   r   r   Znodesr   utilsr   r   r   r   r   r   Zexportedr    r!   r   r   r8   objectr   rH   rJ   rI   rN   rM   Mappingregisterr=   r   r   r"   r   r   r   r   r   r#   r#   r#   r%   <module>   s   		yY!