Your IP : 13.59.183.77


Current Path : /opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/environment.cpython-37.pyc

B

���a7��@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZddlm
Z
ddlmZd	d
lmZd	dlmZd	dlmZd	d
lmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlm Z d	dlm!Z!d	dlm"Z"d	dlm#Z#d	dlm$Z$d	dlm%Z%d	dl&m'Z'd	dl&m(Z(d	dl&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%lm0Z0d	d&l1m2Z2d	d'l3m4Z4d	d(l3m5Z5d	d)l3m6Z6d	d*l7m8Z8d	d+l7m9Z9d	d,l7m:Z:d	d-l7m;Z;d	d.l7m<Z<d	d/l7m=Z=d	d0l7m>Z>ej?�r|ddl@ZAd	d1lBmCZCd	d2lDmEZEd	d3lFmGZGejHd4d5d6�ZIe	d7d8�ejJeIejKeId9�d:d;��ZLeMejNejOejPejQeRfd<fd=�d>d?�ZSejNejOejNejOejPejQeRfd<fd@�dAdB�ZTd5ejUejVeRejJdCfejWeRdCfdD�dEdF�ZXd5d5dG�dHdI�ZYGdJd5�d5�ZZGdKd<�d<�Z[GdLdM�dM�Z\GdNdO�dO�Z]GdPdQ�dQ�Z^e[eZ__dS)RzKClasses for managing templates and their runtime and compile time
options.
�N)�ChainMap)�	lru_cache)�partial)�reduce)�CodeType)�Markup�)�nodes)�
CodeGenerator)�generate)�BLOCK_END_STRING)�BLOCK_START_STRING)�COMMENT_END_STRING)�COMMENT_START_STRING)�DEFAULT_FILTERS)�DEFAULT_NAMESPACE)�DEFAULT_POLICIES)�
DEFAULT_TESTS)�KEEP_TRAILING_NEWLINE)�LINE_COMMENT_PREFIX)�LINE_STATEMENT_PREFIX)�
LSTRIP_BLOCKS)�NEWLINE_SEQUENCE)�TRIM_BLOCKS)�VARIABLE_END_STRING)�VARIABLE_START_STRING)�TemplateNotFound)�TemplateRuntimeError)�TemplatesNotFound)�TemplateSyntaxError)�UndefinedError)�	get_lexer)�Lexer)�TokenStream)�EvalContext)�Parser)�Context)�new_context)�	Undefined)�_PassArg)�concat)�consume)�
import_string)�internalcode)�LRUCache)�missing)�
BytecodeCache)�	Extension)�
BaseLoader�
_env_bound�Environment)�bound�
)�maxsize)�cls�args�returncGs||�}d|_|S)aReturn a new spontaneous environment. A spontaneous environment
    is used for templates created directly rather than through an
    existing environment.

    :param cls: Environment class to create.
    :param args: Positional arguments passed to environment.
    T)�shared)r8r9�env�r=�C/opt/alt/python37/lib/python3.7/site-packages/jinja2/environment.py�get_spontaneous_environmentCs	r?�Template)�sizer:cCs |dkrdS|dkriSt|�S)z*Return the cache class for the given size.rN)r.)rAr=r=r>�create_cacheQs
rB)�cacher:cCs&|dkrdSt|�tkriSt|j�S)z(Create an empty copy of the given cache.N)�type�dictr.Zcapacity)rCr=r=r>�
copy_cache^s
rFr1)�environment�
extensionsr:cCsDi}x:|D]2}t|t�r.t�tjdt|��}||�||j<q
W|S)zuLoad the extensions from the list and bind it to the environment.
    Returns a dict of instantiated extensions.
    r1)�
isinstance�str�t�cast�Typer,�
identifier)rGrH�result�	extensionr=r=r>�load_extensionsks

rQ)rGr:cCsNt|jt�std��|j|jkr.|jks8ntd��|jdksJtd��|S)z*Perform a sanity check on the environment.z5'undefined' must be a subclass of 'jinja2.Undefined'.z<block, variable and comment start strings must be different.>�
�
�
z8'newline_sequence' must be one of '\n', '\r\n', or '\r'.)�
issubclass�	undefinedr(�AssertionError�block_start_string�variable_start_string�comment_start_string�newline_sequence)rGr=r=r>�_environment_config_check}sr\c@sXeZdZUdZdZdZdZejde	d<dZ
eZej
de	d<eZej
ee	d<ej
de	d	<eeeeeeeeeeeed
dedddddddfeeeeeeejeejeeed
eejej eej
dfeej
eejej!dej"fej eej!ejegeffejde#eejded�dd�Z$ej eej
dfdd�dd�Z%ej"dd�dd�Z&e'e'e'e'e'e'e'e'e'e'e'e'e'e'e'e'e'e'e'feeeeeeejeejeeeejej eej
dfeej
eejej!dej"fej eej!ejegeffejde#eejddd�dd�Z(e)e*d�dd ��Z+ej,dd�d!d"�Z-ej"ej eej"fej ej"efd#�d$d%�Z.ej"eej"d&�d'd(�Z/ej eefej"ejejej"ejej0eej"fejeeje1eej"d)�d*d+�Z2dneej"ejejej"ejej0eej"fejeeje1ej"d,�d-d.�Z3doeej"ejejej"ejej0eej"fejeeje1ej"d,�d/d0�Z4e5dpeejeejee6j7d1�d2d3��Z8eejeejee6j7d1�d4d5�Z9dqeejeejeej,ej:e#eefd1�d6d7�Z;dreejeejeed1�d8d9�Z<dseejeejeejee=d:�d;d<�Z>dte6j7ejeejeeed=�d>d?�Z?eee@d@�dAdB�ZAeBjCduej ee6j7fejeejedCee@dD�dEdF��ZDeBjCdvej ee6j7fejeejedGeedD�dHdF��ZDe5dwej ee6j7fejeejeeeej ee@fdD�dIdF��ZDdxeedJdK�dLdM�ZEdyej eeFjGfejejHeejej!egefejeejej!egdfeddO�dPdQ�ZIdzejejHeejej!egefejJedR�dSdT�ZKd{ejedUdV�dWdX�ZLeeedY�dZd[�ZMe5eejej0eej"fdd\�d]d^��ZNe5d|ej edfejeejej0eej"fdd_�d`da��ZOe5d}ejPej edfejeejej0eej"fddb�dcdd��ZQe5d~ej edejJej edffejeejej0eej"fdde�dfdg��ZRdej ee6j7fejej0eej"fejej
dddh�didj�ZSejej0eej"fejTeej"fdk�dldm�ZUdS)�r4a�The core component of Jinja is the `Environment`.  It contains
    important shared variables like configuration, filters, tests,
    globals and others.  Instances of this class may be modified if
    they are not shared and if no template was loaded so far.
    Modifications on environments after the first template was loaded
    will lead to surprising effects and undefined behavior.

    Here are the possible initialization parameters:

        `block_start_string`
            The string marking the beginning of a block.  Defaults to ``'{%'``.

        `block_end_string`
            The string marking the end of a block.  Defaults to ``'%}'``.

        `variable_start_string`
            The string marking the beginning of a print statement.
            Defaults to ``'{{'``.

        `variable_end_string`
            The string marking the end of a print statement.  Defaults to
            ``'}}'``.

        `comment_start_string`
            The string marking the beginning of a comment.  Defaults to ``'{#'``.

        `comment_end_string`
            The string marking the end of a comment.  Defaults to ``'#}'``.

        `line_statement_prefix`
            If given and a string, this will be used as prefix for line based
            statements.  See also :ref:`line-statements`.

        `line_comment_prefix`
            If given and a string, this will be used as prefix for line based
            comments.  See also :ref:`line-statements`.

            .. versionadded:: 2.2

        `trim_blocks`
            If this is set to ``True`` the first newline after a block is
            removed (block, not variable tag!).  Defaults to `False`.

        `lstrip_blocks`
            If this is set to ``True`` leading spaces and tabs are stripped
            from the start of a line to a block.  Defaults to `False`.

        `newline_sequence`
            The sequence that starts a newline.  Must be one of ``'\r'``,
            ``'\n'`` or ``'\r\n'``.  The default is ``'\n'`` which is a
            useful default for Linux and OS X systems as well as web
            applications.

        `keep_trailing_newline`
            Preserve the trailing newline when rendering templates.
            The default is ``False``, which causes a single newline,
            if present, to be stripped from the end of the template.

            .. versionadded:: 2.7

        `extensions`
            List of Jinja extensions to use.  This can either be import paths
            as strings or extension classes.  For more information have a
            look at :ref:`the extensions documentation <jinja-extensions>`.

        `optimized`
            should the optimizer be enabled?  Default is ``True``.

        `undefined`
            :class:`Undefined` or a subclass of it that is used to represent
            undefined values in the template.

        `finalize`
            A callable that can be used to process the result of a variable
            expression before it is output.  For example one can convert
            ``None`` implicitly into an empty string here.

        `autoescape`
            If set to ``True`` the XML/HTML autoescaping feature is enabled by
            default.  For more details about autoescaping see
            :class:`~markupsafe.Markup`.  As of Jinja 2.4 this can also
            be a callable that is passed the template name and has to
            return ``True`` or ``False`` depending on autoescape should be
            enabled by default.

            .. versionchanged:: 2.4
               `autoescape` can now be a function

        `loader`
            The template loader for this environment.

        `cache_size`
            The size of the cache.  Per default this is ``400`` which means
            that if more than 400 templates are loaded the loader will clean
            out the least recently used template.  If the cache size is set to
            ``0`` templates are recompiled all the time, if the cache size is
            ``-1`` the cache will not be cleaned.

            .. versionchanged:: 2.8
               The cache size was increased to 400 from a low 50.

        `auto_reload`
            Some loaders load templates from locations where the template
            sources may change (ie: file system or database).  If
            ``auto_reload`` is set to ``True`` (default) every time a template is
            requested the loader checks if the source changed and if yes, it
            will reload the template.  For higher performance it's possible to
            disable that.

        `bytecode_cache`
            If set to a bytecode cache object, this object will provide a
            cache for the internal Jinja bytecode so that templates don't
            have to be parsed if they were not changed.

            See :ref:`bytecode-cache` for more information.

        `enable_async`
            If set to true this enables async template execution which
            allows using async functions and generators.
    FN�	linked_tor
�code_generator_class�
context_classr@�template_classr=Ti�zte.Literal['\n', '\r\n', '\r']r1.r2r0)rX�block_end_stringrY�variable_end_stringrZ�comment_end_string�line_statement_prefix�line_comment_prefix�trim_blocks�
lstrip_blocksr[�keep_trailing_newlinerH�	optimizedrV�finalize�
autoescape�loader�
cache_size�auto_reload�bytecode_cache�enable_asynccCs�||_||_||_||_||_||_||_||_|	|_|
|_	||_
||_||_||_
||_||_t��|_t��|_t��|_||_t|�|_||_||_t��|_t||
�|_||_ t!|�dS)N)"rXrarYrbrZrcrdrerfrgr[rhrVrirjrkr�copy�filtersr�testsr�globalsrlrBrCrornrZpoliciesrQrH�is_asyncr\)�selfrXrarYrbrZrcrdrerfrgr[rhrHrirVrjrkrlrmrnrorpr=r=r>�__init__#s6%




zEnvironment.__init__)rPr:cCs|j�t||g��dS)z\Adds an extension after the environment was created.

        .. versionadded:: 2.5
        N)rH�updaterQ)rvrPr=r=r>�
add_extensionoszEnvironment.add_extension)�
attributesr:cKs0x*|��D]\}}t||�s
t|||�q
WdS)z�Add the items to the instance of the environment if they do not exist
        yet.  This is used by :ref:`extensions <writing-extensions>` to register
        callbacks and configuration values without breaking inheritance.
        N)�items�hasattr�setattr)rvrz�key�valuer=r=r>�extendvs
zEnvironment.extend)rXrarYrbrZrcrdrerfrgrHrirVrjrkrlrmrnror:cCs�tt��}|d=|d=|d=t�|j�}|j�|j�d|_||_x(|�	�D]\}}|t
k	rLt|||�qLW|t
k	r�t|�|_
nt|j
�|_
i|_x&|j�	�D]\}}|�|�|j|<q�W|t
k	r�|j�t||��t|�S)agCreate a new overlay environment that shares all the data with the
        current environment except for cache and the overridden attributes.
        Extensions cannot be removed for an overlayed environment.  An overlayed
        environment automatically gets all the extensions of the environment it
        is linked to plus optional extra extensions.

        Creating overlays should happen after the initial environment was set
        up completely.  Not all attributes are truly linked, some are just
        copied over so modifications on the original environment may not shine
        through.
        rvrmrHT)rE�locals�object�__new__�	__class__�__dict__rx�	overlayedr]r{r/r}rBrCrFrH�bindrQr\)rvrXrarYrbrZrcrdrerfrgrHrirVrjrkrlrmrnror9�rvr~rr=r=r>�overlays$!
zEnvironment.overlay)r:cCst|�S)zThe lexer for this environment.)r!)rvr=r=r>�lexer�szEnvironment.lexercCstt|j��dd�d��S)z)Iterates over the extensions by priority.cSs|jS)N)�priority)�xr=r=r>�<lambda>��z-Environment.iter_extensions.<locals>.<lambda>)r~)�iter�sortedrH�values)rvr=r=r>�iter_extensions�szEnvironment.iter_extensions)�obj�argumentr:cCs~y||Stttfk
rxt|t�rjyt|�}Wntk
rHYn"Xy
t||�Stk
rhYnX|j||d�SXdS)z:Get an item or attribute of an object but prefer the item.)r��nameN)�AttributeError�	TypeError�LookupErrorrIrJ�	Exception�getattrrV)rvr�r��attrr=r=r>�getitem�s

zEnvironment.getitem)r��	attributer:c
CsRy
t||�Stk
rYnXy||Stttfk
rL|j||d�SXdS)z�Get an item or attribute of an object but prefer the attribute.
        Unlike :meth:`getitem` the attribute *must* be a string.
        )r�r�N)r�r�r�r�rV)rvr�r�r=r=r>r��s
zEnvironment.getattr)r�rr9�kwargs�context�eval_ctx�	is_filterr:c
CsP|r|j}d}	n
|j}d}	|�|�}
|
dkr�d|	�d|�d�}t|t�r�y|��Wn2tk
r�}z|�d|�d�}Wdd}~XYnXt|��|f|dk	r�|nd�}|dk	r�|ni}t�	|
�}
|
tj
kr�|dkr�td	|	�d
���|�d|�nV|
tjk�r.|dk�r |dk	�r|j
}nt|�}|�d|�n|
tjk�rF|�d|�|
||�S)N�filter�testzNo z named �.z (z-; did you forget to quote the callable name?)r=zAttempted to invoke a context z without context.r)rrrs�getrIr(�_fail_with_undefined_errorr�rr)Zfrom_objr��insertZeval_contextr�r$rG)rvr�rr9r�r�r�r�Zenv_mapZ	type_name�func�msg�eZpass_argr=r=r>�_filter_test_common�s>


"



zEnvironment._filter_test_common)r�rr9r�r�r�r:c	Cs|�||||||d�S)a/Invoke a filter on a value the same way the compiler does.

        This might return a coroutine if the filter is running from an
        environment in async mode and the filter supports async
        execution. It's your responsibility to await this if needed.

        .. versionadded:: 2.7
        T)r�)rvr�rr9r�r�r�r=r=r>�call_filterszEnvironment.call_filterc	Cs|�||||||d�S)a�Invoke a test on a value the same way the compiler does.

        This might return a coroutine if the test is running from an
        environment in async mode and the test supports async execution.
        It's your responsibility to await this if needed.

        .. versionchanged:: 3.0
            Tests support ``@pass_context``, etc. decorators. Added
            the ``context`` and ``eval_ctx`` parameters.

        .. versionadded:: 2.7
        F)r�)rvr�rr9r�r�r�r=r=r>�	call_test-szEnvironment.call_test)�sourcer��filenamer:cCs4y|�|||�Stk
r.|j|d�YnXdS)a�Parse the sourcecode and return the abstract syntax tree.  This
        tree of nodes is used by the compiler to convert the template into
        executable source- or bytecode.  This is useful for debugging or to
        extract information from templates.

        If you are :ref:`developing Jinja extensions <writing-extensions>`
        this gives you a good overview of the node tree generated.
        )r�N)�_parser�handle_exception)rvr�r�r�r=r=r>�parseFszEnvironment.parsecCst||||���S)z8Internal parsing function used by `parse` and `compile`.)r%r�)rvr�r�r�r=r=r>r�ZszEnvironment._parsecCs>t|�}y|j�|||�Stk
r8|j|d�YnXdS)a�Lex the given sourcecode and return a generator that yields
        tokens as tuples in the form ``(lineno, token_type, value)``.
        This can be useful for :ref:`extension development <writing-extensions>`
        and debugging templates.

        This does not perform preprocessing.  If you want the preprocessing
        of the extensions to be applied you have to filter source through
        the :meth:`preprocess` method.
        )r�N)rJr�Z	tokeniterrr�)rvr�r�r�r=r=r>�lex`s
zEnvironment.lexcst��fdd�|��t|��S)z�Preprocesses the source with all extensions.  This is automatically
        called for all parsing and compiling methods but *not* for :meth:`lex`
        because there you usually only want the actual source tokenized.
        cs|�|���S)N)�
preprocess)�sr�)r�r�r=r>r��r�z(Environment.preprocess.<locals>.<lambda>)rr�rJ)rvr�r�r�r=)r�r�r>r�us
zEnvironment.preprocess)r�r�r��stater:cCsV|�|||�}|j�||||�}x0|��D]$}|�|�}t|t�s*t|||�}q*W|S)z�Called by the parser to do the preprocessing and filtering
        for all the extensions.  Returns a :class:`~jinja2.lexer.TokenStream`.
        )r�r��tokenizer�Z
filter_streamrIr#)rvr�r�r�r��stream�extr=r=r>�	_tokenize�s


zEnvironment._tokenize)r�r�r��
defer_initr:cCst||||||jd�S)z|Internal hook that can be overridden to hook a different generate
        method in.

        .. versionadded:: 2.5
        )r�ri)rri)rvr�r�r�r�r=r=r>�	_generate�szEnvironment._generate)r�r�r:cCst||d�S)z{Internal hook that can be overridden to hook a different compile
        method in.

        .. versionadded:: 2.5
        �exec)�compile)rvr�r�r=r=r>�_compile�szEnvironment._compilezte.Literal[False])r�r�r��rawr�r:cCsdS)Nr=)rvr�r�r�r�r�r=r=r>r��s	zEnvironment.compilezte.Literal[True]cCsdS)Nr=)rvr�r�r�r�r�r=r=r>r��s	cCsxd}yNt|t�r"|}|�|||�}|j||||d�}|r<|S|dkrHd}|�||�Stk
rr|j|d�YnXdS)a�Compile a node or template source code.  The `name` parameter is
        the load name of the template after it was joined using
        :meth:`join_path` if necessary, not the filename on the file system.
        the `filename` parameter is the estimated filename of the template on
        the file system.  If the template came from a database or memory this
        can be omitted.

        The return value of this method is a python code object.  If the `raw`
        parameter is `True` the return value will be a string with python
        code equivalent to the bytecode returned otherwise.  This method is
        mainly used internally.

        `defer_init` is use internally to aid the module code generator.  This
        causes the generated code to be able to import without the global
        environment variable to be set.

        .. versionadded:: 2.4
           `defer_init` parameter added.
        N)r�z
<template>)r�)rIrJr�r�r�rr�)rvr�r�r�r�r�Zsource_hintr=r=r>r��s
�TemplateExpression)r��undefined_to_noner:cCs�t||dd�}y2|��}|jjs4td|jjjdd��|�|�Wn tk
r`|j|d�YnXt	j
t	�dd�|dd	�g}|�t	j
|dd	��}t||�S)
a�A handy helper method that returns a callable that accepts keyword
        arguments that appear as variables in the expression.  If called it
        returns the result of the expression.

        This is useful if applications want to use the same rules as Jinja
        in template "configuration files" or similar situations.

        Example usage:

        >>> env = Environment()
        >>> expr = env.compile_expression('foo == 42')
        >>> expr(foo=23)
        False
        >>> expr(foo=42)
        True

        Per default the return value is converted to `None` if the
        expression returns an undefined value.  This can be changed
        by setting `undefined_to_none` to `False`.

        >>> env.compile_expression('var')() is None
        True
        >>> env.compile_expression('var', undefined_to_none=False)()
        Undefined

        .. versionadded:: 2.1
        �variable)r�zchunk after expressionN)r�rO�storer)�lineno)r%Zparse_expressionr�Zeosr�currentr�Zset_environmentr�r	�Assign�Name�from_stringr@r�)rvr�r��parser�expr�body�templater=r=r>�compile_expression�szEnvironment.compile_expression�deflated)�targetrH�filter_func�zip�log_function�
ignore_errorsr:cs�ddlm}|dkr$tdd�dd�}|dk	s0t�|jdk	sBtd��ttdd�����fd	d
�}�dk	r�ddlm}	m�m}
m	}|	�d
t
|
|d����|d����n$tj�
��s�t���|d����z�x�|�||�D]�}|j�||�\}
}}y|�|
||dd�}WnBtk
�rJ}z"|�s$�|d|�d|���w�Wdd}~XYnX|�|�}|||�|d|�d|���q�WWd��r����X|d�dS)a3Finds all the templates the loader can find, compiles them
        and stores them in `target`.  If `zip` is `None`, instead of in a
        zipfile, the templates will be stored in a directory.
        By default a deflate zip algorithm is used. To switch to
        the stored algorithm, `zip` can be set to ``'stored'``.

        `extensions` and `filter_func` are passed to :meth:`list_templates`.
        Each template returned will be compiled to the target folder or
        zipfile.

        By default template compilation errors are ignored.  In case a
        log function is provided, errors are logged.  If you want template
        syntax errors to abort the compilation you can set `ignore_errors`
        to `False` and you will get an exception on syntax errors.

        .. versionadded:: 2.4
        r)�ModuleLoaderN)r�r:cSsdS)Nr=)r�r=r=r>r�Bsz3Environment.compile_templates.<locals>.log_functionzNo loader configured.)r��datar:c	sT�r �|�}d|_��||�n0ttj��|�d��}|�|�d��WdQRXdS)Ni��wb�utf8)�
external_attr�writestr�open�os�path�join�write�encode)r�r��info�f)�ZipInfor�r��zip_filer=r>�
write_fileHsz1Environment.compile_templates.<locals>.write_filer)�ZipFiler��ZIP_DEFLATED�
ZIP_STORED�w)r�ZstoredzCompiling into Zip archive zCompiling into folder TzCould not compile "z": z
Compiled "z" as zFinished compiling templates)�loadersr�rJrWrl�zipfiler�r�r�r�rEr�r��isdir�makedirs�list_templates�
get_sourcer�rZget_module_filename�close)rvr�rHr�r�r�r�r�r�r�r�r�r�r�r��_�coder�r=)r�r�r�r�r>�compile_templates$s<	



zEnvironment.compile_templates)rHr�r:csf|jdk	std��|j��}�dk	rH�dk	r4td��ttd��fdd���dk	rb�fdd�|D�}|S)	a�Returns a list of templates for this environment.  This requires
        that the loader supports the loader's
        :meth:`~BaseLoader.list_templates` method.

        If there are other files in the template folder besides the
        actual templates, the returned list can be filtered.  There are two
        ways: either `extensions` is set to a list of file extensions for
        templates, or a `filter_func` can be provided which is a callable that
        is passed a template name and should return `True` if it should end up
        in the result list.

        If the loader does not support that, a :exc:`TypeError` is raised.

        .. versionadded:: 2.4
        NzNo loader configured.z<either extensions or filter_func can be passed, but not both)r�r:csd|ko|�dd�d�kS)Nr�r)�rsplit)r�)rHr=r>r��sz/Environment.list_templates.<locals>.filter_funccsg|]}�|�r|�qSr=r=)�.0r�)r�r=r>�
<listcomp>�sz.Environment.list_templates.<locals>.<listcomp>)rlrWr�r�rJ�bool)rvrHr��namesr=)rHr�r>r�rs
zEnvironment.list_templateszte.NoReturn)r�r:cCsddlm}||d��dS)z�Exception handling helper.  This is used internally to either raise
        rewritten exceptions or return a rendered traceback for the template.
        r)�rewrite_traceback_stack)r�N)�debugr�)rvr�r�r=r=r>r��szEnvironment.handle_exception)r��parentr:cCs|S)a�Join a template with the parent.  By default all the lookups are
        relative to the loader root so this method returns the `template`
        parameter unchanged, but if the paths should be relative to the
        parent template, this function can be used to calculate the real
        template name.

        Subclasses may override this method and implement template path
        joining here.
        r=)rvr�r�r=r=r>�	join_path�s
zEnvironment.join_path)r�rtr:cCs�|jdkrtd��t�|j�|f}|jdk	r`|j�|�}|dk	r`|jrL|jr`|r\|j�	|�|S|j�
|||�|��}|jdk	r�||j|<|S)Nz(no loader for this environment specified)rlr��weakref�refrCr�rn�
is_up_to_datertrx�load�make_globals)rvr�rtZ	cache_keyr�r=r=r>�_load_template�s



zEnvironment._load_template)r�r�rtr:cCs.t|t�r|S|dk	r"|�||�}|�||�S)a�Load a template by name with :attr:`loader` and return a
        :class:`Template`. If the template does not exist a
        :exc:`TemplateNotFound` exception is raised.

        :param name: Name of the template to load.
        :param parent: The name of the parent template importing this
            template. :meth:`join_path` can be used to implement name
            transformations with this.
        :param globals: Extend the environment :attr:`globals` with
            these extra variables available for all renders of this
            template. If the template has already been loaded and
            cached, its globals are updated with any new items.

        .. versionchanged:: 3.0
            If a template is loaded from cache, ``globals`` will update
            the template's globals instead of ignoring the new values.

        .. versionchanged:: 2.4
            If ``name`` is a :class:`Template` object it is returned
            unchanged.
        N)rIr@r�r)rvr�r�rtr=r=r>�get_template�s

zEnvironment.get_template)r�r�rtr:c
Cs�t|t�r|��|s tdd��xT|D]L}t|t�r8|S|dk	rL|�||�}y|�||�Sttfk
rpYq&Xq&Wt|��dS)a�Like :meth:`get_template`, but tries loading multiple names.
        If none of the names can be loaded a :exc:`TemplatesNotFound`
        exception is raised.

        :param names: List of template names to try loading in order.
        :param parent: The name of the parent template importing this
            template. :meth:`join_path` can be used to implement name
            transformations with this.
        :param globals: Extend the environment :attr:`globals` with
            these extra variables available for all renders of this
            template. If the template has already been loaded and
            cached, its globals are updated with any new items.

        .. versionchanged:: 3.0
            If a template is loaded from cache, ``globals`` will update
            the template's globals instead of ignoring the new values.

        .. versionchanged:: 2.11
            If ``names`` is :class:`Undefined`, an :exc:`UndefinedError`
            is raised instead. If no templates were found and ``names``
            contains :class:`Undefined`, the message is more helpful.

        .. versionchanged:: 2.4
            If ``names`` contains a :class:`Template` object it is
            returned unchanged.

        .. versionadded:: 2.3
        z0Tried to select from an empty list of templates.)�messageN)	rIr(r�rr@r�rrr )rvr�r�rtr�r=r=r>�select_template�s#



zEnvironment.select_template)�template_name_or_listr�rtr:cCs8t|ttf�r|�|||�St|t�r*|S|�|||�S)z�Use :meth:`select_template` if an iterable of template names
        is given, or :meth:`get_template` if one name is given.

        .. versionadded:: 2.3
        )rIrJr(rr@r)rvrr�rtr=r=r>�get_or_select_templates

z"Environment.get_or_select_template)r�rtr`r:cCs*|�|�}|p|j}|�||�|�|d�S)a�Load a template from a source string without using
        :attr:`loader`.

        :param source: Jinja source to compile into a template.
        :param globals: Extend the environment :attr:`globals` with
            these extra variables available for all renders of this
            template. If the template has already been loaded and
            cached, its globals are updated with any new items.
        :param template_class: Return an instance of this
            :class:`Template` class.
        N)rr`�	from_coder�)rvr�rtr`Zgsr8r=r=r>r�1s

zEnvironment.from_string)�dr:cCs|dkri}t||j�S)aSMake the globals map for a template. Any given template
        globals overlay the environment :attr:`globals`.

        Returns a :class:`collections.ChainMap`. This allows any changes
        to a template's globals to only affect that template, while
        changes to the environment's globals are still reflected.
        However, avoid modifying any globals after a template is loaded.

        :param d: Dict of template-specific globals.

        .. versionchanged:: 3.0
            Use :class:`collections.ChainMap` to always prevent mutating
            environment globals.
        N)rrt)rvr	r=r=r>rFszEnvironment.make_globals)NNNN)NNNN)NN)NN)NN)NN)F)NNFF)NN.F)NNFF)T)NNr�NT)NN)N)NN)NN)NN)NN)V�__name__�
__module__�__qualname__�__doc__Z	sandboxedr�r]rK�Optional�__annotations__r;r
r^rMr&r_r
rrrrrrrrrrrr(rJr��Sequence�Union�Callable�Any�intrwryr�r/r��propertyr"r��Iteratorr�r�r��Mappingr$r�r�r�r-r	r@r�r��Tupler�r�r#r�r�rr��typing�overloadr�r�r��PathLike�
Collectionr��Listr�r�r�rr�Iterablerrr��MutableMappingrr=r=r=r>r4�s"
x�5 �%1<< $$$#.PH$!*00<2c@s�eZdZUdZeZejeed<eed<ej	e
ejfed<eje
ed<eje
ed<ej
e
ejegeje
ffed<ejegeje
fed<ejd	ed
<e
ed<ejejgefed<eeeeeeeeeeeed
dedddfeje
e j!fe
e
e
e
e
e
eje
eje
eedeej"eje
ejdfeejeejejdejfejeejeje
geffeejd�dd�Z#e$dDee%ej	e
ejfejejgefdd�dd��Z&e$eej	e
ejfej	e
ejfdd�dd��Z'e$eej	e
ejfej	e
ejfdd�dd��Z(ejeje
d �d!d"�Z)ejeje
d �d#d$�Z*ejejd%d �d&d'�Z+ejejeje
d �d(d)�Z,ejejej-e
d �d*d+�Z.dEejej
e
ejfeejej/e
ejfed,�d-d.�Z0dFejej
e
ejfeejej/e
ejfd	d,�d/d0�Z1dGejej
e
ejfeejej/e
ejfd	d,�d1d2�Z2e3dHejed	d3�d4d5��Z4dIejed	d3�d6d7�Z5e6d	d8�d9d:��Z7e8e8d;�d<d=�Z9e6ed8�d>d?��Z:e6ej;ej<e8e8fd8�d@dA��Z=e
d8�dBdC�Z>dS)Jr@aoA compiled template that can be rendered.

    Use the methods on :class:`Environment` to create or load templates.
    The environment is used to configure how templates are compiled and
    behave.

    It is also possible to create a template object directly. This is
    not usually recommended. The constructor takes most of the same
    arguments as :class:`Environment`. All templates created with the
    same environment arguments share the same ephemeral ``Environment``
    instance behind the scenes.

    A template object should be considered immutable. Modifications on
    the object are not supported.
    �environment_classrGrtr�r��blocks�root_render_func�TemplateModule�_module�_debug_info�	_uptodater=TNFzte.Literal['\n', '\r\n', '\r']r1.)r�rXrarYrbrZrcrdrerfrgr[rhrHrirVrjrkrpr:cCsHt|j||||||||	|
|||
t|�||||dddd|�}|j||d�S)NrF)r`)r?r �	frozensetr�)r8r�rXrarYrbrZrcrdrerfrgr[rhrHrirVrjrkrpr<r=r=r>r�|s2zTemplate.__new__)rGr�rt�uptodater:cCs.||jd�}t||�|�|||�}||_|S)z�Creates a template object from compiled code and the globals.  This
        is used by the loaders and environment to create a template object.
        )rG�__file__)�co_filenamer��_from_namespacer&)r8rGr�rtr(�	namespacer�r=r=r>r�s

zTemplate.from_code)rG�module_dictrtr:cCs|�|||�S)z�Creates a template object from a module.  This is used by the
        module loader to create a template object.

        .. versionadded:: 2.4
        )r+)r8rGr-rtr=r=r>�from_module_dict�szTemplate.from_module_dict)rGr,rtr:cCsht�|�}||_||_|d|_|d|_|d|_|d|_d|_|d|_	d|_
||d<||d<|S)Nr�r)r!�root�
debug_inforGZ__jinja_template__)r�r�rGrtr�r�r!r"r$r%r&)r8rGr,rtrKr=r=r>r+�s





zTemplate._from_namespace)r9r�r:cOs�|jjrxddl}d}tjdkr(|��}n.y|��}Wn tk
rT|��}d}YnXz|�	|j
||��S|rv|��X|�t
||��}yt|�|��Stk
r�|j��YnXdS)a�This method accepts the same arguments as the `dict` constructor:
        A dict, a dict subclass or some keyword arguments.  If no arguments
        are given the context will be empty.  These two calls do the same::

            template.render(knights='that say nih')
            template.render({'knights': 'that say nih'})

        This will return the rendered template as a string.
        rNF)��T)rGru�asyncio�sys�version_info�get_event_loopZget_running_loop�RuntimeErrorZnew_event_loop�run_until_complete�render_asyncr�r'rEr*r"r�r�)rvr9r�r3r��loop�ctxr=r=r>�render�s&




zTemplate.renderc�s^|jjstd��|�t||��}ytdd�|�|�2�IdH�Stk
rX|j��SXdS)a.This works similar to :meth:`render` but returns a coroutine
        that when awaited returns the entire rendered template string.  This
        requires the async feature to be enabled.

        Example usage::

            await template.render_async(knights='that say nih; asynchronously')
        z8The environment was not created with async mode enabled.c
�s.g|y3dH}Wn
tk
s"X|�qYS)N)�StopAsyncIteration)r��nr=r=r>r�sz)Template.render_async.<locals>.<listcomp>N)	rGrur7r'rEr*r"r�r�)rvr9r�r;r=r=r>r9
s	zTemplate.render_async�TemplateStreamcOst|j||��S)z[Works exactly like :meth:`generate` but returns a
        :class:`TemplateStream`.
        )r?r)rvr9r�r=r=r>r�"szTemplate.streamc/s��jjrfddl}tjtd����fdd�}tjdkrL|��}|�	|��}n|�
|��}|EdHdS��t����}y��
|�EdHWn tk
r��j��VYnXdS)abFor very large templates it can be useful to not render the whole
        template at once but evaluate each statement after another and yield
        piece for piece.  This method basically does exactly that and returns
        a generator that yields one item after another as strings.

        It accepts the same arguments as :meth:`render`.
        rN)r:c�sdd��j���2�IdHS)Nc
�s.g|y3dH}Wn
tk
s"X|�qYS)N)r=)r�r�r=r=r>r�4sz6Template.generate.<locals>.to_list.<locals>.<listcomp>)�generate_asyncr=)r9r�rvr=r>�to_list3sz"Template.generate.<locals>.to_list)r1r2)rGrur3rKrrJr4r5r6r8�runr'rEr"r�r�)rvr9r�r3rAr:�outr;r=)r9r�rvr>r(s

zTemplate.generatec	Os�|jjstd��|�t||��}y<x6|�|�2y3dH}Wn
tk
sNX|Vq.YWWn tk
r||j��VYnXdS)zsAn async version of :meth:`generate`.  Works very similarly but
        returns an async iterator instead.
        z8The environment was not created with async mode enabled.N)	rGrur7r'rEr"r=r�r�)rvr9r�r;�eventr=r=r>r@Fs$zTemplate.generate_async)�varsr;r�r:cCst|j|j|j|||j|�S)a^Create a new :class:`Context` for this template.  The vars
        provided will be passed to the template.  Per default the globals
        are added to the context.  If shared is set to `True` the data
        is passed as is to the context without adding the globals.

        `locals` can be a dict of local variables for internal usage.
        )r'rGr�r!rt)rvrEr;r�r=r=r>r'Ys
zTemplate.new_contextcCs|�|||�}t||�S)aJThis method works like the :attr:`module` attribute when called
        without arguments but it will evaluate the template on every call
        rather than caching it.  It's also possible to provide
        a dict which is then used as context.  The arguments are the same
        as for the :meth:`new_context` method.
        )r'r#)rvrEr;r�r;r=r=r>�make_modulejszTemplate.make_modulec�s0|�|||�}t||dd�|�|�2�IdH�S)z�As template module creation can invoke template code for
        asynchronous executions this method must be used instead of the
        normal :meth:`make_module` one.  Likewise the module attribute
        becomes unavailable in async mode.
        c
�s.g|y3dH}Wn
tk
s"X|�qYS)N)r=)r�r�r=r=r>r��sz.Template.make_module_async.<locals>.<listcomp>N)r'r#r")rvrEr;r�r;r=r=r>�make_module_asyncyszTemplate.make_module_async)r;r:cs^|jjrtd���dk	rD�j|j��}|rD|��fdd�|D��S|jdkrX|��|_|jS)aOIf a context is passed in, this means that the template was
        imported. Imported templates have access to the current
        template's globals by default, but they can only be accessed via
        the context during runtime.

        If there are new globals, we need to create a new module because
        the cached module is already rendered and will not have access
        to globals from the current context. This new module is not
        cached because the template can be imported elsewhere, and it
        should have access to only the current template's globals.
        z&Module is not available in async mode.Ncsi|]}�j||�qSr=)r�)r��k)r;r=r>�
<dictcomp>�sz0Template._get_default_module.<locals>.<dictcomp>)rGrur7�globals_keysrt�keysrFr$)rvr;rKr=)r;r>�_get_default_module�s


zTemplate._get_default_modulec�sZ�dk	r:�j|j��}|r:|��fdd�|D��IdHS|jdkrT|��IdH|_|jS)Ncsi|]}�j||�qSr=)r�)r�rH)r;r=r>rI�sz6Template._get_default_module_async.<locals>.<dictcomp>)rJrtrKrGr$)rvr;rKr=)r;r>�_get_default_module_async�s
z"Template._get_default_module_async)r:cCs|��S)a�The template as module.  This is used for imports in the
        template runtime but is also useful if one wants to access
        exported template variables from the Python layer:

        >>> t = Template('{% macro foo() %}42{% endmacro %}23')
        >>> str(t.module)
        '23'
        >>> t.module.foo() == u'42'
        True

        This attribute is not available if async mode is enabled.
        )rL)rvr=r=r>�module�szTemplate.module)r�r:cCs(x"t|j�D]\}}||kr|SqWdS)zrReturn the source line number of a line number in the
        generated bytecode as they are not in sync.
        r)�reversedr0)rvr�Z
template_lineZ	code_liner=r=r>�get_corresponding_lineno�sz!Template.get_corresponding_linenocCs|jdkrdS|��S)z?If this variable is `False` there is a newer version available.NT)r&)rvr=r=r>r��s
zTemplate.is_up_to_datecCs |jrdd�|j�d�D�SgS)zThe debug info mapping.cSs g|]}ttt|�d����qS)�=)�tuple�mapr�split)r�r�r=r=r>r��sz'Template.debug_info.<locals>.<listcomp>�&)r%rT)rvr=r=r>r0�szTemplate.debug_infocCs>|jdkrdt|�d��}n
t|j�}dt|�j�d|�d�S)Nzmemory:r��<� �>)r��id�reprrDr
)rvr�r=r=r>�__repr__�s

zTemplate.__repr__)N)NFN)NFN)NFN)N)N)?r
rrr
r4r rKrMrrrJrr�Dictrr&rr�r
rrrrrrrrrrrr(rr	r@rr��classmethodrrr.r+r<r9r�r�
AsyncIteratorr@rr'rFrGr-rLrMrrNrrPr�rrr0r[r=r=r=r>r@]s�
$�&
%,,,
	 
c@s\eZdZdZd
eeejeje	dd�dd�Z
ed�dd�Ze	d�d	d
�Z
e	d�dd�ZdS)r#z�Represents an imported template.  All the exported names of the
    template are available as attributes on this object.  Additionally
    converting it into a string renders the contents.
    N)r�r��body_streamr:cCsH|dkr&|jjrtd��t|�|��}||_|j�|���|j	|_
dS)NztAsync mode requires a body stream to be passed to a template module. Use the async methods of the API you are using.)rGrur7�listr"�_body_streamr�rxZget_exportedr�r
)rvr�r�r_r=r=r>rw�szTemplateModule.__init__)r:cCstt|j��S)N)rr*ra)rvr=r=r>�__html__�szTemplateModule.__html__cCs
t|j�S)N)r*ra)rvr=r=r>�__str__szTemplateModule.__str__cCs>|jdkrdt|�d��}n
t|j�}dt|�j�d|�d�S)Nzmemory:r�rVrWrX)r
rYrZrD)rvr�r=r=r>r[s

zTemplateModule.__repr__)N)r
rrr
r@r&rKrrrJrwrrbrcr[r=r=r=r>r#�sr#c@s@eZdZdZeedd�dd�Zejejej	ejd�dd�Z
dS)	r�z�The :meth:`jinja2.Environment.compile_expression` method returns an
    instance of this object.  It encapsulates the expression-like access
    to the template with an expression it wraps.
    N)r�r�r:cCs||_||_dS)N)�	_template�_undefined_to_none)rvr�r�r=r=r>rwszTemplateExpression.__init__)r9r�r:cOsD|j�t||��}t|j�|��|jd}|jr@t|t�r@d}|S)NrO)	rdr'rEr+r"rErerIr()rvr9r�r�r�r=r=r>�__call__s
zTemplateExpression.__call__)r
rrr
r@r�rwrKrrrfr=r=r=r>r�
sr�c@s�eZdZdZejedd�dd�Zdejeej	fej
eej
edd�dd	�Zdd
�dd�Ze
ejed
�dd�Zde
dd
�dd�Zdd
�dd�Zed
�dd�ZdS)r?a�A template stream works pretty much like an ordinary python generator
    but it can buffer multiple items to reduce the number of total iterations.
    Per default the output is unbuffered which means that for every unbuffered
    instruction in the template one string is yielded.

    If buffering is enabled with a buffer size of 5, five items are combined
    into a new string.  This is mainly useful if you are streaming
    big templates to a client via WSGI which flushes after each iteration.
    N)�genr:cCs||_|��dS)N)�_gen�disable_buffering)rvrgr=r=r>rw+szTemplateStream.__init__�strict)�fp�encoding�errorsr:cs�d}t|t�r(�dkrd�t|d�}d}zT�dk	rH��fdd�|D�}n|}t|d�rb|�|�nx|D]}|�|�qhWWd|r�|��XdS)	aDump the complete stream into a file or file-like object.
        Per default strings are written, if you want to encode
        before writing specify an `encoding`.

        Example usage::

            Template('Hello {{ name }}!').stream(name='foo').dump('hello.html')
        FNzutf-8r�Tc3s|]}|����VqdS)N)r�)r�r�)rlrmr=r>�	<genexpr>Gsz&TemplateStream.dump.<locals>.<genexpr>�
writelines)rIrJr�r|ror�r�)rvrkrlrmr��iterable�itemr=)rlrmr>�dump/s 



zTemplateStream.dump)r:cCstt|j�|_d|_dS)zDisable the output buffering.FN)r�nextrh�_next�buffered)rvr=r=r>riTsz TemplateStream.disable_buffering)rAr:ccs~g}d}|j}xjy0x*||kr<t|j�}||�|r|d7}qWWntk
r\|sXdSYnXt|�V|dd�=d}qWdS)Nrr)�appendrsrh�
StopIterationr*)rvrA�bufZc_size�push�cr=r=r>�_buffered_generatorYs 




z"TemplateStream._buffered_generator�cCs,|dkrtd��d|_tt|�|��|_dS)z<Enable buffering.  Buffer `size` items before yielding them.rzbuffer size too smallTN)�
ValueErrorrurrsr{rt)rvrAr=r=r>�enable_bufferinglszTemplateStream.enable_bufferingcCs|S)Nr=)rvr=r=r>�__iter__tszTemplateStream.__iter__cCs|��S)N)rt)rvr=r=r>�__next__wszTemplateStream.__next__)Nrj)r|)r
rrr
rKrrJrwr�IOrrrrirr{r~rr�r=r=r=r>r? s	  r?)`r
r�r4rrKr��collectionsr�	functoolsrrr�typesrZ
markupsafer�r	�compilerr
r�defaultsrr
rrrrrrrrrrrrrr�
exceptionsrrrrr r�r!r"r#r$r�r%Zruntimer&r'r(�utilsr)r*r+r,r-r.r/�
TYPE_CHECKINGZtyping_extensions�teZbccacher0r�r1r�r2�TypeVarr3rMrr?rrrrr�rJrBrFrrr\rQr\r4r@r#r�r?r`r=r=r=r>�<module>s�*
*U(]

?>