%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/current/lib/python3/dist-packages/jinja2/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/current/lib/python3/dist-packages/jinja2/__pycache__/runtime.cpython-38.pyc

U

��g�l�@sDdZddlZddlmZddlmZddlmZmZddl	m
Z
mZmZm
Z
mZmZmZmZmZddlmZmZmZddlmZmZmZmZmZmZmZmZd	d
ddd
dddddddddgZ eZ!dd�Z"e#�Z$e#�Z%dd�Z&dd�Z'd7dd�Z(Gdd
�d
e#�Z)dd�Z*Gd d!�d!e+�Z,e
fd"d#�Z-Gd$d%�d%ee,��Z.zdd&l/m0Z0e0�1e.�WnHe2k
�r�zdd&l3m0Z0e0�1e.�Wne2k
�r�YnXYnXGd'd(�d(e#�Z4Gd)d*�d*e#�Z5Gd+d	�d	e5�Z6eGd,d-�d-e#��Z7Gd.d�de#�Z8eGd/d0�d0e#��Z9d8d1d2�Z:eGd3d4�d4e9��Z;eGd5d6�d6e9��Z<e9`=e;`=e<`=dS)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�Macrorrr	r
r�markup_join�unicode_join�	to_string�identityrrcCs|S�N���xr"r"�0/usr/lib/python3/dist-packages/jinja2/runtime.py�<lambda>%�r&cCsLg}tt|�}|D]0}|�|�t|d�rtd��t||��Sqt|�S)z@Concatenation that escapes if necessary and converts to unicode.Z__html__�)rr�append�hasattrr�joinrr
)�seqZbuf�iterator�argr"r"r%r+s


cCsttt|��S)z4Simple args to unicode conversion and concatenation.)r
rr)r,r"r"r%r6sc
Csh|dkri}|r|}nt|pdf|�}|rX|r6t|�}t|�D]\}}	|	tk	r>|	||<q>|�||||�S)z(Internal helper to for context creation.Nr")�dictrr	Z
context_class)
�environmentZ
template_name�blocks�varsZshared�globals�locals�parent�key�valuer"r"r%�new_context;s

�r8c@s(eZdZdZdd�Zdd�Zdd�ZdS)	rzThe `self` in templates.cCs
||_dSr!)�_TemplateReference__context��self�contextr"r"r%�__init__SszTemplateReference.__init__cCs|jj|}t||j|d�S�Nr)r9r1�BlockReference)r;�namer1r"r"r%�__getitem__VszTemplateReference.__getitem__cCsd|jj|jjfS)Nz<%s %r>)�	__class__�__name__r9r@�r;r"r"r%�__repr__Zs�zTemplateReference.__repr__N)rC�
__module__�__qualname__�__doc__r=rArEr"r"r"r%rPscCst|d|�S)N�__func__)�getattrr#r"r"r%�	_get_funcasrKc@seZdZdd�ZdS)�ContextMetac	Csvt�||||�}|dkr|St|j�}ttj�}t|j�}ttj�}||k	r\||kr\d|_n||krr||krrd|_|S)Nr"T)�type�__new__rK�resolve�Context�resolve_or_missing�_legacy_resolve_mode�_fast_resolve_mode)	�clsr@�bases�d�rvrOZdefault_resolverQZdefault_resolve_or_missingr"r"r%rNgs 



��zContextMeta.__new__N)rCrFrGrNr"r"r"r%rLesrLcCs,||jkr|j|S||jkr(|j|S|Sr!�r2r5)r<r6r	r"r"r%rQ}s




rQc@s�eZdZdZdZdZdd�Zdd�Zd$dd	�Zd
d�Z	dd
�Z
dd�Zdd�Ze
dd��Zd%dd�Zdd�Zed�Zed�Zed�Zer�ed�Zed�Zed�Z[dd�Zd d!�Zd"d#�ZdS)&rPa�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.
    FcCs\||_i|_||_t|j|�|_t�|_||_tdd�t	|�D��|_
|jrXtt
|�|_
dS)Ncss|]\}}||gfVqdSr!r"��.0�k�vr"r"r%�	<genexpr>�sz#Context.__init__.<locals>.<genexpr>)r5r2r0r�eval_ctx�set�
exported_varsr@r/rr1rSrrQ)r;r0r5r@r1r"r"r%r=�szContext.__init__cCs\z$|j|}|�|�d}||Wn(tk
rL|jjd|dd�YSXt||||�S)zRender a parent block.��#there is no parent block called %r.�super�r@)r1�index�LookupErrorr0�	undefinedr?)r;r@Zcurrentr1rer"r"r%rc�s
��z
Context.superNcCs(z
||WStk
r"|YSXdS)zfReturns an item from the template context, if it doesn't exist
        `default` is returned.
        N)�KeyError)r;r6�defaultr"r"r%�get�s
zContext.getcCs6|jrt||�}n
|�|�}|tkr2|jj|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.
        rd)rRrQr	r0rg�r;r6rWr"r"r%rO�s
zContext.resolvecCs,|jr"|�|�}t|t�rt}|St||�S)zxResolves a variable like :meth:`resolve` but returns the
        special `missing` value if it cannot be found.
        )rRrO�
isinstance�	Undefinedr	rQrkr"r"r%rQ�s

zContext.resolve_or_missingcst�fdd��jD��S)z+Get a new dict with the exported variables.c3s|]}|�j|fVqdSr!)r2)rZr[rDr"r%r]�sz'Context.get_exported.<locals>.<genexpr>)r/r`rDr"rDr%�get_exported�szContext.get_exportedcCs(|js|jS|js|jSt|jf|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.
        )r2r5r/rDr"r"r%�get_all�s
zContext.get_allcOs�d}t|d�r0|j}dD]}t||�r|}q0qt|t�r�t|dd�rR|f|}n2t|dd�rl|jf|}nt|dd�r�|jf|}z|||�WStk
r�|j�d�YSXd	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
�environmentfunctionrqrr
rrzGvalue was undefined because a callable raised a StopIteration exceptionN)	r*rprlrrJr^r0�
StopIterationrg)Z_Context__selfZ
_Context__obj�args�kwargsZ__traceback_hide__�fnZfn_typer"r"r%�call�s$


zContext.callcCsDt|j|ji|��dd|�}|j|_|j�dd�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.
        TNcss|]\}}|t|�fVqdSr!)�listrYr"r"r%r]sz"Context.derived.<locals>.<genexpr>)r8r0r@ror^r1�updater)r;r4r<r"r"r%�deriveds�zContext.derivedcs$�fdd�}tt��j|_�|_|S)Ncst|�����Sr!)rJrorD��methr"r%r&r'zContext._all.<locals>.<lambda>)rJr/rHrC)r|�proxyr"r{r%�_allszContext._all�keys�values�items�iterkeys�
itervaluesrcCs||jkp||jkSr!rX�r;r@r"r"r%�__contains__(szContext.__contains__cCs|�|�}|tkrt|��|S)zTLookup a variable or raise `KeyError` if the variable is
        undefined.
        )rQr	rh)r;r6�itemr"r"r%rA+s
zContext.__getitem__cCsd|jjt|���|jfS)Nz
<%s %s of %r>)rBrC�reprror@rDr"r"r%rE4s

�zContext.__repr__)N)N)rCrFrGrHrRrSr=rcrjrOrQrnrorrwrzr~rr�r�rr�r�rr�rArEr"r"r"r%rP�s2
	
!
	rP)�Mappingc@s0eZdZdZdd�Zedd��Zedd��ZdS)	r?z"One block on a template reference.cCs||_||_||_||_dSr!)r@�_context�_stack�_depth)r;r@r<�stack�depthr"r"r%r=KszBlockReference.__init__cCsF|jdt|j�kr,|jjjd|jdd�St|j|j|j|jd�S)zSuper the block.rarbrcrd)r��lenr�r�r0rgr@r?rDr"r"r%rcQs���zBlockReference.supercCs,t|j|j|j��}|jjjr(t|�}|Sr!)r
r�r�r�r^�
autoescaper�r;rWr"r"r%rp[s
zBlockReference.__call__N)	rCrFrGrHr=�propertyrcrrpr"r"r"r%r?Hs
	r?c@s�eZdZdZeZeZeZdZ	ddd�Z
dd�Zdd	�Ze
d
d��Ze
dd��Ze
d
d��Ze
dd��Ze
dd��Ze
dd��Ze
dd��Ze
dd��Zdd�Zedd��ZeZ[dd�ZdS)�LoopContextBasez%A loop context for dynamic iteration.NrcCs"||_||_d|_||_t|_dS)N���)�
_undefined�_recurse�index0�depth0r	�_last_checked_value)r;rg�recurser�r"r"r%r=ks
zLoopContextBase.__init__cGs|std��||jt|�S)z7Cycles among the arguments with the current loop index.zno items for cycling given)�	TypeErrorr�r�)r;rtr"r"r%�cyclerszLoopContextBase.cyclecGs|j|kr||_dSdS)z9Checks whether the value has changed since the last call.TF)r�)r;r7r"r"r%�changedxs
zLoopContextBase.changedcCs
|jdkSr>�r�r#r"r"r%r&r'zLoopContextBase.<lambda>cCs
|jtkSr!)�_after�_last_iterationr#r"r"r%r&�r'cCs
|jdS�Nrar�r#r"r"r%r&�r'cCs|j|jSr!)�lengthr�r#r"r"r%r&�r'cCs|j|jSr!)r�rer#r"r"r%r&�r'cCs
|jdSr�)r�r#r"r"r%r&�r'cCs|jtkr|�d�S|jS)Nzthere is no previous item)�_before�_first_iterationr�rDr"r"r%�previtem�s

zLoopContextBase.previtemcCs|jtkr|�d�S|jS)Nzthere is no next item)r�r�r�rDr"r"r%�nextitem�s

zLoopContextBase.nextitemcCs|jSr!)r�rDr"r"r%�__len__�szLoopContextBase.__len__cCs(|jdkrtd��|�||j|jd�S)NzMTried to call non recursive loop.  Maybe you forgot the 'recursive' modifier.ra)r�r�r�)r;�iterabler"r"r%�loop�s
zLoopContextBase.loopcCsd|jj|j|jfS)Nz
<%s %r/%r>)rBrCrer�rDr"r"r%rE�s
�zLoopContextBase.__repr__)Nr)rCrFrGrHr�r��_currentr�r��_lengthr=r�r�r��firstZlastreZrevindexZ	revindex0r�r�r�r�rr�rprEr"r"r"r%r�cs0



r�c@s2eZdZddd�Zedd��Zdd�Zd	d
�ZdS)rNrc	CsVt�||||�t|�|_zt|�|_Wnttfk
rFd|_YnX|��|_	dSr!)
r�r=�iter�	_iteratorr�r�r��AttributeError�
_safe_nextr�)r;r�rgr�r�r"r"r%r=�s
zLoopContext.__init__cCs<|jdkr6t|j�}t|�|_|jd}t|�||_|jS)N�)r��tupler�r�r�r�)r;r�Ziterations_doner"r"r%r��s



zLoopContext.lengthcCst|�Sr!)�LoopContextIteratorrDr"r"r%�__iter__�szLoopContext.__iter__cCs*zt|j�WStk
r$tYSXdSr!)�nextr�rsr�rDr"r"r%r��szLoopContext._safe_next)Nr)rCrFrGr=r�r�r�r�r"r"r"r%r�s


c@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
r�z The iterator for a loop context.�r<cCs
||_dSr!r�r:r"r"r%r=�szLoopContextIterator.__init__cCs|Sr!r"rDr"r"r%r��szLoopContextIterator.__iter__cCsH|j}|jd7_|jtkr$t��|j|_|j|_|��|_|j|fSr�)r<r�r�r�rsr�r�r�)r;Zctxr"r"r%�__next__�s

zLoopContextIterator.__next__N)rCrFrGrH�	__slots__r=r�r�r"r"r"r%r��s
r�c@s:eZdZdZddd�Zeedd���Zdd�Zd	d
�Z	dS)rzWraps a macro function.Nc		CsV||_||_t|�|_||_||_||_||_||_d|k|_	|dkrL|j
}||_dS)N�caller)�_environment�_funcr��_argument_countr@�	arguments�catch_kwargs�
catch_varargsr��explicit_callerr��_default_autoescape)	r;r0�funcr@r�r�r�r�Zdefault_autoescaper"r"r%r=�s

zMacro.__init__c	Os�|r*t|dt�r*|dj}|dd�}n|j}t|d|j��}t|�}d}||jkr�t|jt|�d��D]F\}}z|�	|�}	Wnt
k
r�t}	YnX|dkr�d}|�|	�qnn|j
}|jr�|s�|�	dd�}
|
dkr�|jjddd�}
|�|
�|j�r
|�|�n8|�rBd|k�r(td|j��td	|jtt|��f��|j�r`|�||jd��n(t|�|jk�r�td
|jt|j�f��|�||�S)NrraFr�TzNo caller definedrdzamacro %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))rlrr�r�rxr�r��	enumerater��poprhr	r)r�r�r�rgr�r�r@r�r�r��_invoke)r;rtrur�r�ZoffZfound_caller�idxr@r7r�r"r"r%rp�sR



�

���zMacro.__call__cCs|j|�}|rt|�}|S)z=This method is being swapped out by the async implementation.)r�r)r;r�r�rWr"r"r%r�Es
z
Macro._invokecCs$d|jj|jdkrdpt|j�fS)Nz<%s %s>Z	anonymous)rBrCr@r�rDr"r"r%rELs�zMacro.__repr__)N)
rCrFrGrHr=rr
rpr�rEr"r"r"r%r�s�
Jc@s�eZdZdZdZdedefdd�Zedd��Z	edd	��Z
e	ZZZ
ZZZZZZZZZZZZZZZZZZZ Z!Z"Z#Z$Z%d
d�Z&dd
�Z'dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,e,Z-dd�Z.dS)rmazThe 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_exceptionNcCs||_||_||_||_dSr!r�)r;�hint�objr@�excr"r"r%r=eszUndefined.__init__cOsl|jdkrX|jtkr d|j}q^t|jt�sBdt|j�|jf}q^dt|j�|jf}n|j}|�|��dS)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�rlrrr�)r;rtrur�r"r"r%�_fail_with_undefined_errorks

��z$Undefined._fail_with_undefined_errorcCs |dd�dkrt|��|��S)Nr��__)r�r�r�r"r"r%�__getattr__�szUndefined.__getattr__cCst|�t|�kSr!)rM�r;�otherr"r"r%�__eq__�szUndefined.__eq__cCs|�|�Sr!)r�r�r"r"r%�__ne__�szUndefined.__ne__cCstt|��Sr!)�idrMrDr"r"r%�__hash__�szUndefined.__hash__cCsdS)Nr(r"rDr"r"r%�__str__�szUndefined.__str__cCsdSr>r"rDr"r"r%r��szUndefined.__len__ccsdSr!r"rDr"r"r%r��szUndefined.__iter__cCsdS)NFr"rDr"r"r%�__nonzero__�szUndefined.__nonzero__cCsdS)Nrmr"rDr"r"r%rE�szUndefined.__repr__)/rCrFrGrHr�r	rr=rr�r��__add__�__radd__�__mul__�__rmul__Z__div__Z__rdiv__�__truediv__�__rtruediv__�__floordiv__�
__rfloordiv__�__mod__�__rmod__�__pos__�__neg__rprA�__lt__�__le__�__gt__�__ge__�__int__�	__float__�__complex__�__pow__�__rpow__�__sub__�__rsub__r�r�r�r�r�r�r��__bool__rEr"r"r"r%rmSst



��������������������rmcs`�dkr,ddl}|�t����|�tj���dkr8t��fdd��G���fdd�d��}|S)akGiven 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`.
    Nrcsn|jdkrX|jtkr d|j}q^t|jt�sBdt|j�|jf}q^dt|j�|jf}n|j}��d|�dS)Nz%s is undefinedz%s has no element %sz%s has no attribute %szTemplate variable warning: %s)r�r�r	r�rlrrZwarning)Zundefr�)�loggerr"r%�_log_message�s

��z,make_logging_undefined.<locals>._log_messagecsfeZdZ��fdd�Z��fdd�Z��fdd�ZerT��fdd�Z��fd	d
�Zn��fdd�Z	d
S)z0make_logging_undefined.<locals>.LoggingUndefinedc
sRz�j|f|�|�WS|jk
rL}z��dt|��|�W5d}~XYnXdS)NzTemplate variable error: %s)r�r��error�str)r;rtru�e)�baser�r"r%r��s
zKmake_logging_undefined.<locals>.LoggingUndefined._fail_with_undefined_errorcs��|�}�|�|Sr!)r�r��r�r�r"r%r��s
z8make_logging_undefined.<locals>.LoggingUndefined.__str__cs��|�}�|�|Sr!)r�r�r�r"r%r��s
z9make_logging_undefined.<locals>.LoggingUndefined.__iter__cs��|�}�|�|Sr!)r�r�r�r"r%r��s
z<make_logging_undefined.<locals>.LoggingUndefined.__nonzero__cs��|�}�|�|Sr!)�__unicode__r�r�r"r%r��s
z<make_logging_undefined.<locals>.LoggingUndefined.__unicode__cs��|�}�|�|Sr!)r�r�r�r"r%r��s
z9make_logging_undefined.<locals>.LoggingUndefined.__bool__N)
rCrFrGr�r�r�rr�r�r�r"�r�r�r�r"r%�LoggingUndefined�sr�)�loggingZ	getLoggerrCZ
addHandlerZ
StreamHandler�sys�stderrrm)r�r�r�r�r"r�r%�make_logging_undefined�s
#r�c@seZdZdZdZdd�ZdS)�DebugUndefinedaAn 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"cCs<|jdkr2|jtkrd|jSdt|j�|jfSd|jS)Nz{{ %s }}z{{ no such element: %s[%r] }}z!{{ undefined value printed: %s }})r�r�r	r�rrDr"r"r%r�
s


�zDebugUndefined.__str__N)rCrFrGrHr�r�r"r"r"r%r��sr�c@s6eZdZdZdZejZZZ	Z
ZZZ
ZdS)�StrictUndefinedasAn 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)rCrFrGrHr�rmr�r�r�r�r�r�r�r�r�r"r"r"r%rs���r)NNNN)NN)>rHr��	itertoolsr�typesrZjinja2.nodesrrZjinja2.utilsrrrr	r
rrr
rZjinja2.exceptionsrrrZjinja2._compatrrrrrrrr�__all__rr �objectr�r�rrr8rrKrMrLrQrPZcollections.abcr��register�ImportError�collectionsr?r�rr�rrmr�r�rr�r"r"r"r%�<module>sv	,(��
9F'mU
Q

Zerion Mini Shell 1.0