U
    P޸bĂ                     @   s  d Z ddlZddl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 edZejdej dej!f dZ"ej#rNddl$Z$ddl%Z&ddl'm(Z( G dd de&j)Z*dddd d!d"d#d$d%d&d'd(d)d*gZ+d+d,d-gZ,eed.d/d&Z-ej.ej! e/d0d1d$Z0ej.ej! e/d0d2d%Z1dNd4ej2e/ ej3e/ej d5gej4e/ f f ej2ej3e/ej!f  e5ej2ej6e/ej!f  ej2ej7e/ej!f  d5d6d7d8Z8G d9d dZ9e"e"d:d;d<Z:ej7j;G d=d5 d5Z<G d>d? d?Z=G d@d dZ>G dAd+ d+e>Z?G dBd dZ@G dCd) d)ZAdeAfej2dD ejBeA ejBeA dEdFdGZCG dHdI dIeAZDG dJdK dKeAZEG dLdM dMeAZFeA`GeD`GeE`GeF`GdS )Oz;The runtime functions and state used by compiled templates.    N)abc)chain)escape)Markup)soft_str   
auto_aiter)
auto_await)TemplateNotFound)TemplateRuntimeError)UndefinedError)EvalContext)_PassArg)concat)internalcode)missing)	Namespace)object_type_repr)pass_eval_contextVF.)bound)Environmentc                   @   s(   e Zd Zdeje d eedddZdS )LoopRenderFuncr   )reciterloop_render_funcdepthreturnc                 C   s   d S N )selfr   r   r   r    r    2/tmp/pip-unpacked-wheel-rhlcrkgz/jinja2/runtime.py__call__#   s    zLoopRenderFunc.__call__N)r   )	__name__
__module____qualname__tIterabler   intstrr#   r    r    r    r"   r   "   s    r   LoopContextTemplateReferenceMacror   r   r   r   markup_joinstr_joinidentityr   r   	Undefinedr   AsyncLoopContextr	   r
   )xr   c                 C   s   | S )zLReturns its argument. Useful for certain things in the
    environment.
    r    )r3   r    r    r"   r0   D   s    )seqr   c                 C   sL   g }t t| }|D ]0}|| t|drtdt||  S qt|S )z?Concatenation that escapes if necessary and converts to string.__html__ )mapr   appendhasattrr   joinr   r   )r4   bufiteratorargr    r    r"   r.   K   s    


c                 C   s   t tt| S )z3Simple args to string conversion and concatenation.)r   r7   r*   )r4   r    r    r"   r/   V   s    Fr   Context)environmenttemplate_nameblocksvarssharedglobalslocalsr   c           
      C   sl   |dkri }|r|}nt |pdf|}|rX|r6t |}| D ]\}}	|	tk	r>|	||< q>| j| ||||dS )z%Internal helper for context creation.Nr    )rD   )dictitemsr   Zcontext_class)
r?   r@   rA   rB   rC   rD   rE   parentkeyvaluer    r    r"   new_context[   s$    

    rK   c                   @   s@   e Zd ZdZdddddZeejddd	Zed
ddZ	dS )r,   zThe `self` in templates.r>   N)contextr   c                 C   s
   || _ d S r   )_TemplateReference__context)r!   rL   r    r    r"   __init__{   s    zTemplateReference.__init__namer   c                 C   s   | j j| }t|| j |dS Nr   )rM   rA   BlockReference)r!   rP   rA   r    r    r"   __getitem__~   s    zTemplateReference.__getitem__r   c                 C   s   dt | j d| jjdS )N< >)typer$   rM   rP   r!   r    r    r"   __repr__   s    zTemplateReference.__repr__)
r$   r%   r&   __doc__rN   r*   r'   AnyrS   rZ   r    r    r    r"   r,   x   s   )dict_methodr   c                    s,   t  dtjd fdd}tt|S )Nr>   )r!   r   c                    s    |   S r   )get_allrY   r]   r    r"   f_all   s    z_dict_method_all.<locals>.f_all)	functoolswrapsr'   r\   castr   )r]   r`   r    r_   r"   _dict_method_all   s    rd   c                
   @   s  e Zd ZdZd&dejeejf eje ejeej	d gej
e f f ejejeejf  dddZeej	d gej
e f ejd dd	d
Zd'eejejdddZeejejdf dddZeejdddZejeejf dddZejeejf dddZeej	ejejejejdf dddZd(ejejeejf  d dddZeejZeejZeejZeedd d!Zeejdd"d#Zedd$d%ZdS ))r>   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:`pass_context` 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.
    Nr   )r?   rH   rP   rA   rD   c                 C   s^   || _ i | _|| _t| j|| _t | _|| _|d kr<t nt|| _dd |	 D | _
d S )Nc                 S   s   i | ]\}}||gqS r    r    .0kvr    r    r"   
<dictcomp>   s      z$Context.__init__.<locals>.<dictcomp>)rH   rB   r?   r   eval_ctxsetexported_varsrP   Zglobals_keysrG   rA   )r!   r?   rH   rP   rA   rD   r    r    r"   rN      s    zContext.__init__rR   r1   )rP   currentr   c                 C   s`   z$| j | }||d }||  W n, tk
rP   | jjd|ddd Y S X t|| ||S )zRender a parent block.r    there is no parent block called .superrP   )rA   indexLookupErrorr?   	undefinedrR   )r!   rP   rn   rA   rs   r    r    r"   rq      s    

 zContext.super)rI   defaultr   c                 C   s(   z
| | W S  t k
r"   | Y S X dS )zLook up a variable by name, or return a default if the key is
        not found.

        :param key: The variable name to look up.
        :param default: The value to return if the key is not found.
        N)KeyError)r!   rI   rv   r    r    r"   get   s    
zContext.getr1   )rI   r   c                 C   s$   |  |}|tkr | jj|dS |S )aN  Look up a variable by name, or return an :class:`Undefined`
        object if the key is not found.

        If you need to add custom behavior, override
        :meth:`resolve_or_missing`, not this method. The various lookup
        functions use that method, not this one.

        :param key: The variable name to look up.
        rr   )resolve_or_missingr   r?   ru   )r!   rI   rvr    r    r"   resolve   s    

zContext.resolvec                 C   s,   || j kr| j | S || jkr(| j| S tS )aN  Look up a variable by name, or return a ``missing`` sentinel
        if the key is not found.

        Override this method to add custom lookup behavior.
        :meth:`resolve`, :meth:`get`, and :meth:`__getitem__` use this
        method. Don't call this method directly.

        :param key: The variable name to look up.
        )rB   rH   r   )r!   rI   r    r    r"   ry      s
    




zContext.resolve_or_missingrT   c                    s    fdd j D S )z+Get a new dict with the exported variables.c                    s   i | ]}| j | qS r    )rB   )rf   rg   rY   r    r"   ri      s      z(Context.get_exported.<locals>.<dictcomp>)rl   rY   r    rY   r"   get_exported   s    zContext.get_exportedc                 C   s(   | j s| jS | js| j S t| jf| 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.
        )rB   rH   rF   rY   r    r    r"   r^      s
    zContext.get_all)_Context__objargskwargsr   c                 O   s   d}t |dr$t|jdk	r$|j}t|}|tjkrt|drP| |d } |drh| |d } | f| }n.|tjkr| jf| }n|tj	kr| j	f| }|
dd |
dd z|||W S  tk
r   | j	d Y S X dS )zCall the callable with the arguments and keyword arguments
        provided but inject the active context or environment as first
        argument if the callable has :func:`pass_context` or
        :func:`pass_environment`.
        Tr#   NZ
_loop_varsZ_block_varszGvalue was undefined because a callable raised a StopIteration exception)r9   r   Zfrom_objr#   rL   rx   derivedZeval_contextrj   r?   popStopIterationru   )Z_Context__selfr}   r~   r   Z__traceback_hide__Zpass_argr    r    r"   call  s2    






zContext.call)rE   r   c                 C   sD   t | j| ji |  dd|}| j|_|jdd | 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 r   )listre   r    r    r"   	<genexpr>:  s     z"Context.derived.<locals>.<genexpr>)rK   r?   rP   r^   rj   rA   updaterG   )r!   rE   rL   r    r    r"   r   1  s          zContext.derivedrO   c                 C   s   || j kp|| jkS r   )rB   rH   r!   rP   r    r    r"   __contains__A  s    zContext.__contains__c                 C   s   |  |}|tkrt||S )zpLook up a variable by name with ``[]`` syntax, or raise a
        ``KeyError`` if the key is not found.
        )ry   r   rw   )r!   rI   itemr    r    r"   rS   D  s    
zContext.__getitem__c                 C   s$   dt | j d|  d| jdS )NrU   rV   z of rW   )rX   r$   r^   rP   rY   r    r    r"   rZ   O  s    zContext.__repr__)N)N)N) r$   r%   r&   r[   r'   Dictr*   r\   OptionalCallableIteratorMutableMappingrN   Unionrq   rx   r{   ry   r|   r^   r   r   r   rd   rF   keysvaluesrG   boolr   rS   rZ   r    r    r    r"   r>      s>       ,$


c                   @   sz   e Zd ZdZedejejdgeje f  e	ddddZ
eejd dd	d
ZeedddZeedddZdS )rR   z"One block on a template reference.r>   N)rP   rL   stackr   r   c                 C   s   || _ || _|| _|| _d S r   )rP   _context_stack_depth)r!   rP   rL   r   r   r    r    r"   rN   V  s    zBlockReference.__init__rm   rT   c                 C   sJ   | j d t| jkr0| jjjd| jdddS t| j| j| j| j d S )zSuper the block.r   ro   rp   rq   rr   )r   lenr   r   r?   ru   rP   rR   rY   r    r    r"   rq   b  s     zBlockReference.superc                    s<   t dd | j| j | j2 I d H }| jjjr8t|S |S )Nc                    s   g | z3 d H W }|q6 S r   r    rf   r3   r    r    r"   
<listcomp>n  s     z.BlockReference._async_call.<locals>.<listcomp>)r   r   r   r   rj   
autoescaper   r!   rz   r    r    r"   _async_callk  s     
zBlockReference._async_callc                 C   s>   | j jjr|  S t| j| j | j }| j jjr:t	|S |S r   )
r   r?   is_asyncr   r   r   r   rj   r   r   r   r    r    r"   r#   v  s    

zBlockReference.__call__)r$   r%   r&   r[   r*   r'   Listr   r   r)   rN   propertyr   rq   r   r   r#   r    r    r    r"   rR   S  s   
rR   c                   @   s  e Zd ZU dZdZdZeje e	d< e
Zeje	d< e
Zeje	d< e
Zeje	d< e
Zeje	d< d7eje ejd
 ejd eddddZeeje eje dddZeedddZedddZeedddZeedddZeedddZeedddZeeddd Zejdd!d"Z eedd#d$Z!eej"ejd
f dd%d&Z#eej"ejd
f dd'd(Z$eed)d*d+Z%ejed,d-d.Z&d dd/d0Z'ej(ejd f dd1d2Z)e*eje e+dd3d4Z,e+dd5d6Z-dS )8r+   zeA wrapper iterable for dynamic ``for`` loops, with information
    about the loop and iteration.
    N_length_after_current_before_last_changed_valuer   r1   r   )iterableru   recursedepth0r   c                 C   s(   || _ | || _|| _|| _|| _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_recurser   )r!   r   ru   r   r   r    r    r"   rN     s
    zLoopContext.__init__r   r   c                 C   s   t | S r   )iterr   r    r    r"   r     s    zLoopContext._to_iteratorrT   c                 C   sl   | j dk	r| j S zt| j| _ W nD tk
rd   t| j}| || _t|| j | jt	k	 | _ Y n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)
r   r   r   	TypeErrorr   r   r   rs   r   r   r!   r   r    r    r"   length  s    

 zLoopContext.lengthc                 C   s   | j S r   )r   rY   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   rY   r    r    r"   r     s    zLoopContext.depthc                 C   s
   | j d S )z-Current iteration of the loop, starting at 1.r   index0rY   r    r    r"   rs     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   rs   rY   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   rY   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   rY   r    r    r"   first  s    zLoopContext.firstc                 C   s$   | j tk	r| j S t| 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   rY   r    r    r"   
_peek_next  s    
zLoopContext._peek_nextc                 C   s   |   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   rY   r    r    r"   last  s    zLoopContext.lastc                 C   s   | j r| dS | jS )zZThe item in the previous iteration. Undefined during the
        first iteration.
        zthere is no previous item)r   r   r   rY   r    r    r"   previtem  s    
zLoopContext.previtemc                 C   s   |   }|tkr| dS |S )a	  The 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:`jinja-filters.groupby` filter avoids that issue.
        there is no next itemr   r   r   r   r    r    r"   nextitem   s    	
zLoopContext.nextitem)r~   r   c                 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!   r~   r    r    r"   cycle  s    zLoopContext.cycle)rJ   r   c                 G   s   | j |kr|| _ dS d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)r   )r!   rJ   r    r    r"   changed  s    
zLoopContext.changedc                 C   s   | S r   r    rY   r    r    r"   __iter__'  s    zLoopContext.__iter__c                 C   sF   | j tk	r| j }t| _ n
t| j}|  jd7  _| j| _|| _|| fS Nr   )r   r   r   r   r   r   r   r   r    r    r"   __next__*  s    

zLoopContext.__next__c                 C   s&   | j dkrtd| j || j | jd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#   6  s
    
zLoopContext.__call__c                 C   s"   dt | j d| j d| j dS )NrU   rV   /rW   )rX   r$   rs   r   rY   r    r    r"   rZ   D  s    zLoopContext.__repr__)Nr   ).r$   r%   r&   r[   r   r   r'   r   r)   __annotations__r   r   r\   r   r   r   r(   r   TyperN   staticmethodr   r   r   r   r   r   rs   r   r   r   r   r   r   r   r   r   r   r   r   Tupler   r   r*   r#   rZ   r    r    r    r"   r+     sZ   
  		c                   @   s   e Zd ZU ejej ed< eejej	e
 eje
 f eje
 dddZeedddZeeddd	Zeedd
dZejdddZeedddZeejejdf dddZd dddZejejd f dddZdS )r2   r   r   c                 C   s   t | S r   r   r   r    r    r"   r   K  s    zAsyncLoopContext._to_iteratorrT   c                    sx   | j d k	r| j S zt| j| _ W nP tk
rp   dd | j2 I d H }| || _t|| j | jtk	 | _ Y nX | j S )Nc                    s   g | z3 d H W }|q6 S r   r    r   r    r    r"   r   Y  s     z+AsyncLoopContext.length.<locals>.<listcomp>)	r   r   r   r   r   r   rs   r   r   r   r    r    r"   r   Q  s    
 zAsyncLoopContext.lengthc                    s   | j I d H | j S r   r   rY   r    r    r"   r   _  s    zAsyncLoopContext.revindex0c                    s   | j I d H | j S r   r   rY   r    r    r"   r   c  s    zAsyncLoopContext.revindexc                    sH   | j tk	r| j S z| j I d H | _ W n tk
r@   t| _ Y nX | j S r   )r   r   r   	__anext__StopAsyncIterationrY   r    r    r"   r   g  s    
zAsyncLoopContext._peek_nextc                    s   |   I d H tkS r   r   rY   r    r    r"   r   r  s    zAsyncLoopContext.lastr1   c                    s$   |   I d H }|tkr | dS |S )Nr   r   r   r    r    r"   r   v  s    
zAsyncLoopContext.nextitemc                 C   s   | S r   r    rY   r    r    r"   	__aiter__  s    zAsyncLoopContext.__aiter__c                    sL   | j tk	r| j }t| _ n| j I d H }|  jd7  _| j| _|| _|| fS r   )r   r   r   r   r   r   r   r   r    r    r"   r     s    
zAsyncLoopContext.__anext__N)r$   r%   r&   r'   AsyncIteratorr\   r   r   r   r(   r   AsyncIterabler   r   r)   r   r   r   r   r   r   r   r   r   r   r    r    r    r"   r2   H  s$   
c                
   @   s   e Zd ZdZddejdef eeje eeeej	e dddZ
eeejejedd	d
Zejej eedddZejej eedddZedddZdS )r-   zWraps a macro function.Nr   .)r?   funcrP   	argumentscatch_kwargscatch_varargscallerdefault_autoescapec	           	      C   sl   || _ || _t|| _|| _|| _|| _|| _|| _d|k| _	|d krbt
|jr\|d }n|j}|| _d S )Nr   )_environment_funcr   _argument_countrP   r   r   r   r   explicit_callercallabler   _default_autoescape)	r!   r?   r   rP   r   r   r   r   r   r    r    r"   rN     s    


zMacro.__init__r~   r   r   c           
   	   O   s  |r*t |d tr*|d j}|dd  }n| j}t|d | j }t|}d}|| jkr| jt|d  D ]B}z||}W n t	k
r   t
}Y nX |dkrd}|| qjn| j}| jr|s|dd }	|	d kr| jjddd}	||	 | jr|| n@|rBd|kr$td| jd	td| jd
tt|| jr`||| jd   n.t|| jkrtd| jdt| j d| ||S )Nr   r   Fr   TzNo caller definedrr   zmacro zX was invoked with two values for the special caller argument. This is most likely a bug.z takes no keyword argument z takes not more than z argument(s))
isinstancer   r   r   r   r   r   r   r   rw   r   r8   r   r   r   ru   r   r   rP   r   r   r   _invoke)
r!   r~   r   r   r   offZfound_callerrP   rJ   r   r    r    r"   r#     sN    





zMacro.__call__)r   r   r   c                    s    | j | I d H }|rt|S |S r   )r   r   r!   r   r   rz   r    r    r"   _async_invoke  s    zMacro._async_invokec                 C   s.   | j jr| ||S | j| }|r*t|}|S r   )r   r   r   r   r   r   r    r    r"   r     s    
zMacro._invokerT   c                 C   s0   | j d krdnt| j }dt| j d| dS )NZ	anonymousrU   rV   rW   )rP   reprrX   r$   r   r    r    r"   rZ     s    zMacro.__repr__)N)r$   r%   r&   r[   r'   r   r*   r   r   r   rN   r   r   r\   r#   r   r   rZ   r    r    r    r"   r-     s$    Lc                   @   s  e Zd ZdZdZdedefeje	 ej
eje	 eje ddddZee	ddd	Zeej
ej
d
dddZee	ej
dddZe Z Z ZZe Z Z ZZe ZZe ZZe ZZ e Z!Z"e Z#Z$e Z% Z& Z'Z(e Z) Z*Z+e Z,Z-ej
e.dddZ/ej
e.dddZ0e1dddZ2e	dddZ3e1dddZ4ej5ej
 dddZ6ej7ej
 dddZ8e.dd d!Z9e	dd"d#Z:dS )$r1   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_exceptionN)hintobjrP   excr   c                 C   s   || _ || _|| _|| _d S r   r   )r!   r   r   rP   r   r    r    r"   rN   +  s    zUndefined.__init__rT   c                 C   sZ   | j r| j S | jtkr"| jdS t| jtsDt| j d| jS t| jd| jS )zXBuild a message about the undefined value based on how it was
        accessed.
        z is undefinedz has no element z has no attribute )r   r   r   r   r   r*   r   rY   r    r    r"   _undefined_message7  s    
zUndefined._undefined_messagete.NoReturnr   c                 O   s   |  | jdS )zeRaise an :exc:`UndefinedError` when operations are performed
        on the undefined value.
        N)r   r   )r!   r~   r   r    r    r"   _fail_with_undefined_errorM  s    z$Undefined._fail_with_undefined_errorrO   c                 C   s    |d d dkrt ||  S )N   __)AttributeErrorr   r   r    r    r"   __getattr__V  s    zUndefined.__getattr__)otherr   c                 C   s   t | t |kS r   )rX   r!   r   r    r    r"   __eq__h  s    zUndefined.__eq__c                 C   s   |  | S r   )r   r   r    r    r"   __ne__k  s    zUndefined.__ne__c                 C   s   t t| S r   )idrX   rY   r    r    r"   __hash__n  s    zUndefined.__hash__c                 C   s   dS )Nr6   r    rY   r    r    r"   __str__q  s    zUndefined.__str__c                 C   s   dS rQ   r    rY   r    r    r"   r   t  s    zUndefined.__len__c                 c   s   dE d H  d S Nr    r    rY   r    r    r"   r   w  s    zUndefined.__iter__c                 C  s   dD ]
}d V  qd S r   r    r!   _r    r    r"   r   z  s    zUndefined.__aiter__c                 C   s   dS )NFr    rY   r    r    r"   __bool__~  s    zUndefined.__bool__c                 C   s   dS )Nr1   r    rY   r    r    r"   rZ     s    zUndefined.__repr__);r$   r%   r&   r[   	__slots__r   r   r'   r   r*   r\   r   r   rN   r   r   r   r   r   __add____radd____sub____rsub____mul____rmul__Z__div__Z__rdiv____truediv____rtruediv____floordiv____rfloordiv____mod____rmod____pos____neg__r#   rS   __lt____le____gt____ge____int__	__float____complex____pow____rpow__r   r   r   r)   r   r   r   r   r   r   r   r   rZ   r    r    r    r"   r1     sR   	 zlogging.Logger)loggerbaser   c                    sZ   dkr,ddl }|t|tj tdd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   )undefr   c                    s     d| j d S )NzTemplate variable warning: %s)warningr   )r  )r  r    r"   _log_message  s     z,make_logging_undefined.<locals>._log_messagec                       st   e Zd ZdZejejdd fddZed fddZej	ej d fd	d
Z
ed fddZ  ZS )z0make_logging_undefined.<locals>.LoggingUndefinedr    r   r   c              
      sL   zt  j|| W n4 | jk
rF } zd| |W 5 d }~X Y nX d S )NzTemplate variable error: %s)rq   r   r   error)r!   r~   r   e)	__class__r  r    r"   r     s
    zKmake_logging_undefined.<locals>.LoggingUndefined._fail_with_undefined_errorrT   c                    s   |  t   S r   )rq   r   rY   r  r  r    r"   r     s    z8make_logging_undefined.<locals>.LoggingUndefined.__str__c                    s   |  t   S r   )rq   r   rY   r   r    r"   r     s    z9make_logging_undefined.<locals>.LoggingUndefined.__iter__c                    s   |  t   S r   )rq   r   rY   r   r    r"   r     s    z9make_logging_undefined.<locals>.LoggingUndefined.__bool__)r$   r%   r&   r   r'   r\   r   r*   r   r   r   r   r   __classcell__r    r  r  )r  r"   LoggingUndefined  s    	r#  )logging	getLoggerr$   
addHandlerStreamHandlersysstderrr1   )r  r  r$  r#  r    r"  r"   make_logging_undefined  s    
r*  c                   @   s6   e Zd ZdZdZedddZed d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
    r    rT   c                 C   s   t | S r   )r*   rY   r    r    r"   r5     s    zChainableUndefined.__html__)r   r   c                 C   s   | S r   r    r   r    r    r"   r     s    zChainableUndefined.__getattr__N)	r$   r%   r&   r[   r   r*   r5   r   rS   r    r    r    r"   r+    s
   r+  c                   @   s"   e Zd ZdZdZed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
    r    rT   c                 C   sL   | j rd| j  }n,| jtkr&| j}ndt| j d| jd}d| dS )Nzundefined value printed: zno such element: []z{{ z }})r   r   r   r   r   )r!   messager    r    r"   r     s    
zDebugUndefined.__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Zej Z ZZ	ej Z
 Z ZZej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
    r    N)r$   r%   r&   r[   r   r1   r   r   r   r   r   r   r   r   r   r    r    r    r"   r0    s
   r0  )NFNN)Hr[   ra   r(  typingr'   collectionsr   	itertoolsr   Z
markupsafer   r   r   Zasync_utilsr	   r
   
exceptionsr   r   r   Znodesr   utilsr   r   r   r   r   r   r   TypeVarr   r   r\   r   TYPE_CHECKINGr$  Ztyping_extensionster?   r   Protocolr   ZexportedZasync_exportedr0   r(   r*   r.   r/   r   r   r   r   r   MappingrK   r,   rd   registerr>   rR   r+   r2   r-   r1   r   r*  r+  r,  r0  r   r    r    r    r"   <module>   s   
	     E0 FG q  < 