관리-도구
편집 파일: environment.cpython-39.opt-1.pyc
a �����`������������������������@���s��d�Z�ddlZddlZddlZddlmZ�ddlmZ�ddlmZ�ddl m Z �ddlmZ�dd lm Z �dd lmZ�ddlmZ�ddlmZ�dd lmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlm Z �ddlm!Z!�ddlm"Z"�ddlm#Z#�ddlm$Z$�ddlm%Z%�dd lm&Z&�dd!lm'Z'�dd"lm(Z(�dd#l)m*Z*�dd$l)m+Z+�dd%l)m,Z,�dd&l)m-Z-�dd'l)m.Z.�dd(l/m0Z0�dd)l/m1Z1�dd*l m2Z2�dd+l3m4Z4�dd,l5m6Z6�dd-l5m7Z7�dd.l5m8Z8�dd/l9m:Z:�dd0l9m;Z;�dd1l9m<Z<�dd2l9m=Z=�dd3l9m>Z>�dd4l9m?Z?�dd5l9m@Z@�e?d6�ZAd7d8��ZBd9d:��ZCd;d<��ZDd=d>��ZEd?d@��ZFdAdB��ZGG�dCdD��dDeH�ZIG�dEdF��dFeH�ZJeG�dGdH��dHeH��ZKG�dIdJ��dJeH�ZLe G�dKdL��dLeH��ZMeJeI_NdS�)MzKClasses for managing templates and their runtime and compile time options. �����N)�partial)�reduce)�Markup����)�nodes)�encode_filename)�implements_iterator)�implements_to_string)� iteritems)�PY2)�PYPY)�reraise)�string_types)� text_type)� 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)�TokenStream)�EvalContext)�Parser)�Context)�new_context)� Undefined)�concat)�consume)�have_async_gen)� import_string)�internalcode��LRUCache)�missing� ���c�����������������G���sD���|�|f}z t�|�W�S��ty>���|�|���t�|<�}d|_|�Y�S�0�dS�)a��Return 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. TN)�_spontaneous_environments�KeyError�shared)�cls�args�key�env��r>����6/usr/lib/python3.9/site-packages/jinja2/environment.py�get_spontaneous_environmentA���s���� r@���c�����������������C���s ���|�dkrdS�|�dk�ri�S�t�|��S�)z*Return the cache class for the given size.r���Nr3���)�sizer>���r>���r?����create_cacheS���s ����rB���c�����������������C���s&���|�du�rdS�t�|��tu�ri�S�t|�j�S�)z(Create an empty copy of the given cache.N)�type�dictr4���Zcapacity)�cacher>���r>���r?���� copy_cache\���s ����rF���c�����������������C���s2���i�}|D�]$}t�|t�rt|�}||��||j<�q|S�)zwLoad the extensions from the list and bind it to the environment. Returns a dict of instantiated environments. )� isinstancer���r1���Z identifier)�environment� extensions�result� extensionr>���r>���r?����load_extensionse���s���� rL���c�������������� ���C���s\���|�|�}t�|t�rPz|����W�n0�tyN�}�zd||f�}W�Y�d�}~n d�}~0�0�t|��d�S�)Nz3%s (%s; did you forget to quote the callable name?))rG���r-����_fail_with_undefined_error� Exceptionr#���)�string�name�msg�er>���r>���r?����fail_for_missing_callableq���s���� "rS���c�����������������C���s���|�S�)z*Perform a sanity check on the environment.r>���)rH���r>���r>���r?����_environment_sanity_check{���s����rT���c�������������������@���s���e�Zd�ZdZdZdZdZdZeZ e Zee eeeeeeeeeeddedddddddfdd�Zd d ��Zdd��Zeeeeeeeeeeeeeeeeeeefd d�Zeedd�Z dd��Z!dd��Z"dd��Z#dBdd�Z$dCdd�Z%e&dDdd��Z'dd��Z(dEdd �Z)dFd!d"�Z*dGd#d$�Z+dHd%d&�Z,d'd(��Z-e&dId)d*��Z.dJd+d,�Z/dKd.d/�Z0dLd0d1�Z1dMd2d3�Z2d4d5��Z3e&d6d7���Z4e&dNd8d9��Z5e&dOd:d;��Z6e&dPd<d=��Z7dQd>d?�Z8d@dA��Z9dS�)R�Environmenta���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 you to take advantage of newer Python features. This requires Python 3.6 or later. FNr>���Ti���c�����������������C���s����||�_�||�_||�_||�_||�_||�_||�_||�_| |�_| |�_ ||�_ ||�_||�_||�_ ||�_||�_t���|�_t���|�_t���|�_||�_t|�|�_||�_||�_t���|�_t|�| �|�_||�_ |�j o�t!|�_"|�j"r�ddl#m$}�t%|���d�S�)Nr���)�asyncsupport)&�block_start_string�block_end_string�variable_start_string�variable_end_string�comment_start_string�comment_end_string�line_statement_prefix�line_comment_prefix�trim_blocks� lstrip_blocks�newline_sequence�keep_trailing_newline� undefined� optimized�finalize� autoescaper����copy�filtersr����testsr����globals�loaderrB���rE����bytecode_cache�auto_reloadr���ZpoliciesrL���rI����enable_asyncr0����is_async��rV���rT���)�selfrW���rX���rY���rZ���r[���r\���r]���r^���r_���r`���ra���rb���rI���rd���rc���re���rf���rk���� cache_sizerm���rl���rn���rV���r>���r>���r?����__init__ ��s<����% zEnvironment.__init__c�����������������C���s���|�j��t|�|g���dS�)z\Adds an extension after the environment was created. .. versionadded:: 2.5 N)rI����updaterL���)rq���rK���r>���r>���r?���� add_extensionq��s����zEnvironment.add_extensionc�����������������K���s,���t�|�D�]\}}t|�|�st|�||��qdS�)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)r ����hasattr�setattr)rq���Z attributesr<����valuer>���r>���r?����extendx��s���� zEnvironment.extendc�����������������C���s����t�t���}|d=�|d=�|d=�t�|�j�}|j�|�j��d|_|�|_t |�D�]\}}|t urJt|||��qJ|t ur|t|�|_ nt|�j �|_ i�|_t |�j�D�]\}}|�|�|j|<�q�|t ur�|j�t||���t|�S�)ag��Create 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. rq���rr���rI���T)rD����locals�object�__new__� __class__�__dict__rt���� overlayed� linked_tor ���r5���rw���rB���rE���rF���rI���ZbindrL���rT���)rq���rW���rX���rY���rZ���r[���r\���r]���r^���r_���r`���rI���rd���rc���re���rf���rk���rr���rm���rl���r;����rvr<���rx���r>���r>���r?����overlay���s$����! zEnvironment.overlayzThe lexer for this environment.)�docc�����������������C���s���t�t|�j���dd��d��S�)z)Iterates over the extensions by priority.c�����������������S���s���|�j�S��N)�priority��xr>���r>���r?����<lambda>��������z-Environment.iter_extensions.<locals>.<lambda>)r<���)�iter�sortedrI����values�rq���r>���r>���r?����iter_extensions���s����zEnvironment.iter_extensionsc�����������������C���s����z ||�W�S��t�ttfy~���t|t�rlzt|�}W�n�tyF���Y�n&0�zt||�W��Y�S��t�yj���Y�n0�|�j||d��Y�S�0�dS�)z:Get an item or attribute of an object but prefer the item.��objrP���N) �AttributeError� TypeError�LookupErrorrG���r����strrN����getattrrc���)rq���r�����argument�attrr>���r>���r?����getitem���s���� zEnvironment.getitemc�������������� ���C���sV���zt�||�W�S��ty���Y�n0�z ||�W�S��tttfyP���|�j||d��Y�S�0�dS�)z�Get an item or attribute of an object but prefer the attribute. Unlike :meth:`getitem` the attribute *must* be a bytestring. r����N)r����r����r����r����rc���)rq���r����Z attributer>���r>���r?���r�������s���� zEnvironment.getattrc�����������������C���s����|�j��|�}|du�rtd|��|gt|p*d��}t|dd�du�r^|du�rPtd��|�d|��nZt|d d�du�r�|du�r�|dur�|j}nt|��}|�d|��nt|d d�du�r�|�d|���||i�|p�i���S�)aW��Invokes a filter on a value the same way the compiler does it. Note that on Python 3 this might return a coroutine in case 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 Nzno filter named %rr>���Z contextfilterFTz2Attempted to invoke context filter without contextr���ZevalcontextfilterZenvironmentfilter) rh����getrS����listr����r#����insert�eval_ctxr)���)rq���rP���rx���r;����kwargs�contextr�����funcr>���r>���r?����call_filter���s&���� �zEnvironment.call_filterc�����������������C���s<���|�j��|�}|du�rtd|��||g|p*d�R�i�|p6i���S�)zdInvokes a test on a value the same way the compiler does it. .. versionadded:: 2.7 Nzno test named %rr>���)ri���r����rS���)rq���rP���rx���r;���r����r����r>���r>���r?���� call_test���s���� zEnvironment.call_testc�����������������C���s4���z|���|||�W�S��ty.���|�j|d��Y�n0�dS�)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. ��sourceN)�_parser%����handle_exception�rq���r����rP����filenamer>���r>���r?����parse ��s���� zEnvironment.parsec�����������������C���s���t�|�||t|�����S�)z8Internal parsing function used by `parse` and `compile`.)r*���r���r����r����r>���r>���r?���r������s����zEnvironment._parsec�����������������C���s>���t�|�}z|�j�|||�W�S��ty8���|�j|d��Y�n0�dS�)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)r����lexerZ tokeniterr%���r����r����r>���r>���r?����lex��s ���� zEnvironment.lexc��������������������s���t����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. c��������������������s���|��|�����S�r����)� preprocess)�srR����r����rP���r>���r?���r����3��r����z(Environment.preprocess.<locals>.<lambda>)r���r����r���r����r>���r����r?���r����-��s �����zEnvironment.preprocessc�����������������C���sR���|���|||�}|�j�||||�}|����D�]$}|�|�}t|t�s(t|||�}q(|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_streamrG���r(���)rq���r����rP���r�����state�stream�extr>���r>���r?���� _tokenize8��s���� zEnvironment._tokenizec�����������������C���s���t�||�||||�jd�S�)z|Internal hook that can be overridden to hook a different generate method in. .. versionadded:: 2.5 )� defer_initrd���)r���rd���)rq���r����rP���r����r����r>���r>���r?���� _generateD��s�����zEnvironment._generatec�����������������C���s���t�||d�S�)z{Internal hook that can be overridden to hook a different compile method in. .. versionadded:: 2.5 �exec)�compile)rq���r����r����r>���r>���r?����_compileS��s����zEnvironment._compilec�����������������C���s����d}z\t�|t�r"|}|��|||�}|�j||||d�}|r>|W�S�|du�rLd}nt|�}|��||�W�S��ty~���|�j|d��Y�n0�dS�)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����)rG���r���r����r����r���r����r%���r����)rq���r����rP���r�����rawr����Zsource_hintr>���r>���r?���r����[��s���� zEnvironment.compilec�����������������C���s����t�|�|dd�}z2|���}|jjs4td|jjjdd��|�|���W�n*�tyj���t� ��durf|�j |d��Y�n0�tjt� dd�|dd �g}|��tj|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 expressionNr����rJ����storer���)�lineno)r*���Zparse_expressionr����Zeosr%����currentr����Zset_environment�sys�exc_infor����r���ZAssign�Name�from_string�Template�TemplateExpression)rq���r�����undefined_to_none�parser�expr�body�templater>���r>���r?����compile_expression���s�����zEnvironment.compile_expression�deflatedc��������������������s ��ddl�m}�|du�rdd��}|r�tr(trFddl} | jdtdd ��d }n:ddl} ddl}| � ��d� d��}tjd kr�|d� d�7�}�����fdd�} �dur�ddl m}m��m}m}�|�dt||d�����|d����n"tj���s�t����|d�����z|��||�D�]�}|�j�|�|�\}}}z|��|||dd�}W�nL�t�y��}�z2|�sR��|d||f���W�Y�d}~�q W�Y�d}~n d}~0�0�|�|�}|�r�|��|t|��}| |d�||�|����|d||d�f���n| ||��|d||f����q W���r�� ���n��r�� ���0�|d��dS�)a;��Finds 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. If `py_compile` is set to `True` .pyc files will be written to the target instead of standard .py files. This flag does not do anything on pypy and Python 3 where pyc files are not picked up by itself and don't give much benefit. .. versionadded:: 2.4 r���)�ModuleLoaderNc�����������������S���s���d�S�r����r>���r����r>���r>���r?����log_function���s����z3Environment.compile_templates.<locals>.log_functionr���zV'py_compile=True' has no effect on PyPy or Python 3 and will be removed in version 3.0����)� stacklevelFu���ÿÿÿÿziso-8859-15)����r����z����c��������������������sv����r ��|��}d|_���||��nRt|t�r4|�d�}ttj��|��d��}|� |��W�d�����n1�sh0����Y��d�S�)Ni����utf8�wb) Z external_attrZwritestrrG���r����encode�open�os�path�join�write)r�����data�info�f��ZipInfo�target�zipZzip_filer>���r?���� write_file���s���� z1Environment.compile_templates.<locals>.write_file)�ZipFiler�����ZIP_DEFLATED� ZIP_STORED�w)r����ZstoredzCompiling into Zip archive "%s"zCompiling into folder "%s"TzCould not compile "%s": %s�czByte-compiled "%s" as %szCompiled "%s" as %szFinished compiling templates)!�loadersr����r���r����warnings�warn�DeprecationWarning�imp�marshalZ get_magicr����r�����version_info�zipfiler����r����r����r����rD���r����r�����isdir�makedirs�list_templatesrk���� get_sourcer����r%���Zget_module_filenamer����r����dumps�close)rq���r����rI����filter_funcr����r����� ignore_errors� py_compiler����r����r����r����Z py_headerr����r����r����r����rP���r����r�����_�coderR���r����r>���r����r?����compile_templates���sb���� � � $ � zEnvironment.compile_templatesc��������������������sL���|�j����}��dur.�dur"td����fdd���durH�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 Nz<either extensions or filter_func can be passed, but not bothc��������������������s���d|�v�o|���dd�d���v�S�)N�.r���)�rsplitr����)rI���r>���r?���r����2��s����z/Environment.list_templates.<locals>.filter_funcc��������������������s���g�|�]}��|�r|�qS�r>���r>���)�.0rP���)r����r>���r?���� <listcomp>6��r����z.Environment.list_templates.<locals>.<listcomp>)rk���r����r����)rq���rI���r�����namesr>���)rI���r����r?���r������s���� �zEnvironment.list_templatesc�����������������C���s���ddl�m}�t||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_stackr����N)�debugr����r ���)rq���r����r����r>���r>���r?���r����:��s����zEnvironment.handle_exceptionc�����������������C���s���|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>���)rq���r�����parentr>���r>���r?���� join_pathB��s���� zEnvironment.join_pathc�����������������C���sx���|�j�d�u�rtd��t�|�j��|f}|�jd�urP|�j�|�}|d�urP|�jrL|jrP|S�|�j��|�||�}|�jd�urt||�j|<�|S�)Nz(no loader for this environment specified) rk���r�����weakref�refrE���r����rm���� is_up_to_date�load)rq���rP���rj���Z cache_keyr����r>���r>���r?����_load_templateN��s���� �� zEnvironment._load_templatec�����������������C���s4���t�|t�r|S�|dur"|��||�}|��||��|��S�)a���Load a template from the loader. If a loader is configured this method asks the loader for the template and returns a :class:`Template`. If the `parent` parameter is not `None`, :meth:`join_path` is called to get the real template name before loading. The `globals` parameter can be used to provide template wide globals. These variables are available in the context at render time. If the template does not exist a :exc:`TemplateNotFound` exception is raised. .. versionchanged:: 2.4 If `name` is a :class:`Template` object it is returned from the function unchanged. N)rG���r����r���r���make_globals)rq���rP���r����rj���r>���r>���r?����get_template^��s ���� zEnvironment.get_templatec�������������� ���C���s����t�|t�r|����|s tdd��|��|�}|D�]T}t�|t�rD|��S�|durX|��||�}z|��||�W���S��tt fy����Y�q.0�q.t|��dS�)ah��Works like :meth:`get_template` but tries a number of templates before it fails. If it cannot find any of the templates, it will raise a :exc:`TemplatesNotFound` exception. .. 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 from the function unchanged. .. versionadded:: 2.3 z0Tried to select from an empty list of templates.)�messageN) rG���r-���rM���r$���r��r����r���r��r"���r&���)rq���r����r����rj���rP���r>���r>���r?����select_templateu��s"���� � zEnvironment.select_templatec�����������������C���s8���t�|ttf�r|��|||�S�t�|t�r*|S�|��|||�S�)z�Does a typecheck and dispatches to :meth:`select_template` if an iterable of template names is given, otherwise to :meth:`get_template`. .. versionadded:: 2.3 )rG���r���r-���r��r����r ��)rq���Ztemplate_name_or_listr����rj���r>���r>���r?����get_or_select_template���s ���� z"Environment.get_or_select_templatec�����������������C���s*���|���|�}|p|�j}|�|�|��|�|d�S�)zuLoad a template from a string. This parses the source given and returns a :class:`Template` object. N)r���template_class� from_coder����)rq���r����rj���r��r:���r>���r>���r?���r�������s���� zEnvironment.from_stringc�����������������C���s���|s |�j�S�t|�j�fi�|��S�)zReturn a dict for the globals.)rj���rD���)rq����dr>���r>���r?���r�����s����zEnvironment.make_globals)NNNN)NN)NN)NN)NN)NN)F)NNFF)T)NNr����NTF)NN)N)NN)NN)NN)NN):�__name__� __module__�__qualname__�__doc__Z sandboxedr���r����r9���r���Zcode_generator_classr+���Z context_classr���r���r!���r ���r���r���r���r���r���r���r���r���r-���rs���ru���ry���r5���r�����propertyr'���r����r����r����r����r����r����r2���r����r����r����r����r����r����r����r����r����r����r����r����r���r��r��r ��r ��r����r��r>���r>���r>���r?���rU�������s����~� Q� :�� ! $ /������� n # rU���c�������������������@���s����e�Zd�ZdZeZeeee e eee eeeeddedddfdd�Zed*dd ��Zed d���Zedd ���Zdd��Zdd��Zdd��Zdd��Zdd��Zd+dd�Zd,dd�Zd-dd�Ze dd���Z!e"d d!���Z#d"d#��Z$e"d$d%���Z%e"d&d'���Z&d(d)��Z'dS�).r����a���The central template object. This class represents a compiled template and is used to evaluate it. Normally the template object is generated from an :class:`Environment` but it also has a constructor that makes it possible to create a template instance directly using the constructor. It takes the same arguments as the environment constructor but it's not possible to specify a loader. Every template object has a few methods and members that are guaranteed to exist. However it's important that a template object should be considered immutable. Modifications on the object are not supported. Template objects created from the constructor rather than an environment do have an `environment` attribute that points to a temporary environment that is probably shared with other templates created with the constructor and compatible settings. >>> template = Template('Hello {{ name }}!') >>> template.render(name='John Doe') == u'Hello John Doe!' True >>> stream = template.stream(name='John Doe') >>> next(stream) == u'Hello John Doe!' True >>> next(stream) Traceback (most recent call last): ... StopIteration r>���TNFc�����������������C���sH���t�|�j|||||||| | ||| t|�||||d�ddd�|�}|j||�d�S�)Nr���F)r��)r@����environment_class� frozensetr����)r:���r����rW���rX���rY���rZ���r[���r\���r]���r^���r_���r`���ra���rb���rI���rd���rc���re���rf���rn���r=���r>���r>���r?���r|������s4�����zTemplate.__new__c�����������������C���s.���||j�d�}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. )rH����__file__)�co_filenamer�����_from_namespace� _uptodate)r:���rH���r����rj���Zuptodate� namespacer����r>���r>���r?���r�� ��s ���� zTemplate.from_codec�����������������C���s���|���|||�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��)r:���rH���Zmodule_dictrj���r>���r>���r?����from_module_dict��s����zTemplate.from_module_dictc�����������������C���sh���t��|��}||_||_|d�|_|d�|_|d�|_|d�|_d�|_|d�|_ d�|_ ||d<�||d<�|S�)NrP���r���blocks�root� debug_inforH���Z__jinja_template__)r{���r|���rH���rj���rP���r����r���root_render_func�_module�_debug_infor��)r:���rH���r��rj����tr>���r>���r?���r����s���� zTemplate._from_namespacec�����������������O���sF���t�|i�|��}zt|��|��|���W�S��ty@���|�j����Y�n0�dS�)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 unicode string. N)rD���r.���r��r,���rN���rH���r����)rq���r;���r�����varsr>���r>���r?����render4��s ���� zTemplate.renderc�����������������O���s���t�d��dS�)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') �8This feature is not available for this version of PythonN��NotImplementedError�rq���r;���r����r>���r>���r?����render_asyncD��s���� �zTemplate.render_asyncc�����������������O���s���t�|�j|i�|���S�)z[Works exactly like :meth:`generate` but returns a :class:`TemplateStream`. )�TemplateStreamr���r'��r>���r>���r?���r����R��s����zTemplate.streamc�����������������o���sR���t�|i�|��}z |��|��|��D�] }|V��q W�n�tyL���|�j���V��Y�n0�dS�)aj��For 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 unicode strings. It accepts the same arguments as :meth:`render`. N)rD���r��r,���rN���rH���r����)rq���r;���r����r"��Zeventr>���r>���r?���r���X��s����zTemplate.generatec�����������������O���s���t�d��dS�)zsAn async version of :meth:`generate`. Works very similarly but returns an async iterator instead. r$��Nr%��r'��r>���r>���r?����generate_asyncg��s�����zTemplate.generate_asyncc�����������������C���s���t�|�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,���rH���rP���r��rj����rq���r"��r9���rz���r>���r>���r?���r,���p��s�����zTemplate.new_contextc�����������������C���s���t�|�|��|||��S�)aJ��This 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. )�TemplateModuler,���r+��r>���r>���r?����make_module|��s����zTemplate.make_modulec�����������������C���s���t�d��dS�)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. r$��Nr%��r+��r>���r>���r?����make_module_async���s�����zTemplate.make_module_asyncc�����������������C���s"���|�j�d�ur|�j�S�|�����|�_�}|S�r����)r��r-��)rq���r����r>���r>���r?����_get_default_module���s���� zTemplate._get_default_modulec�����������������C���s���|�����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. )r/��r����r>���r>���r?����module���s����zTemplate.modulec�����������������C���s(���t�|�j�D�]\}}||kr |��S�q dS�)zrReturn the source line number of a line number in the generated bytecode as they are not in sync. r���)�reversedr��)rq���r����Z template_lineZ code_liner>���r>���r?����get_corresponding_lineno���s���� z!Template.get_corresponding_linenoc�����������������C���s���|�j�du�rdS�|�����S�)z?If this variable is `False` there is a newer version available.NT)r��r����r>���r>���r?���r�����s���� zTemplate.is_up_to_datec�����������������C���s ���|�j�rdd��|�j��d�D��S�g�S�)zThe debug info mapping.c�����������������S���s ���g�|�]}t�tt|�d�����qS�)�=)�tuple�map�int�split�r����r����r>���r>���r?���r�������r����z'Template.debug_info.<locals>.<listcomp>�&)r ��r7��r����r>���r>���r?���r�����s����zTemplate.debug_infoc�����������������C���s2���|�j�d�u�rdt|���}n t|�j��}d|�jj|f�S��Nz memory:%xz<%s %s>)rP����id�reprr}���r���rq���rP���r>���r>���r?����__repr__���s���� zTemplate.__repr__)N)NFN)NFN)NFN)(r��r��r��r��rU���r��r���r���r!���r ���r���r���r���r���r���r���r���r���r-���r|����classmethodr��r��r��r#��r(��r����r���r*��r,���r-��r.��r2���r/��r��r0��r2��r��r��r>��r>���r>���r>���r?���r�������sZ���� 1 r����c�������������������@���s2���e�Zd�ZdZddd�Zdd��Zdd��Zd d ��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 an unicode- or bytestrings renders the contents. Nc�����������������C���sH���|d�u�r&|j�jrtd��t|�|��}||�_|�j�|�����|j |�_ d�S�)NzuAsync mode requires a body stream to be passed to a template module. Use the async methods of the API you are using.)rH���ro����RuntimeErrorr����r���_body_streamr~���rt���Zget_exportedrP���r��)rq���r����r����Zbody_streamr>���r>���r?���rs������s�����zTemplateModule.__init__c�����������������C���s���t�t|�j��S�r����)r���r.���rA��r����r>���r>���r?����__html__���s����zTemplateModule.__html__c�����������������C���s ���t�|�j�S�r����)r.���rA��r����r>���r>���r?����__str__���s����zTemplateModule.__str__c�����������������C���s2���|�j�d�u�rdt|���}n t|�j��}d|�jj�|f�S�r:��)r��r;��r<��r}���r=��r>���r>���r?���r>�����s���� zTemplateModule.__repr__)N)r��r��r��r��rs���rB��rC��r>��r>���r>���r>���r?���r,�����s ��� r,��c�������������������@���s ���e�Zd�ZdZdd��Zdd��ZdS�)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. c�����������������C���s���||�_�||�_d�S�r����)� _template�_undefined_to_none)rq���r����r����r>���r>���r?���rs������s����zTemplateExpression.__init__c�����������������O���sH���|�j��t|i�|���}t|�j��|���|jd�}|�jrDt|t�rDd�}|S�)NrJ���) rD��r,���rD���r/���r��r"��rE��rG���r-���)rq���r;���r����r����r����r>���r>���r?����__call__���s���� zTemplateExpression.__call__N)r��r��r��r��rs���rF��r>���r>���r>���r?���r�������s���r����c�������������������@���sL���e�Zd�ZdZdd��Zddd�Zdd ��Zd d��Zdd d�Zdd��Z dd��Z dS�)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 unicode string is yielded. If buffering is enabled with a buffer size of 5, five items are combined into a new unicode string. This is mainly useful if you are streaming big templates to a client via WSGI which flushes after each iteration. c�����������������C���s���||�_�|�����d�S�r����)�_gen�disable_buffering)rq����genr>���r>���r?���rs�����s����zTemplateStream.__init__N�strictc��������������������s����d}t�|t�r(��du�rd��t|d�}d}z\��durH���fdd�|�D��}n|�}t|d�rb|�|��n|D�]}|�|��qfW�|r�|����n|r�|����0�dS�) a!��Dump the complete stream into a file or file-like object. Per default unicode 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����Tc�����������������3���s���|�]}|������V��qd�S�r����)r����r8����encoding�errorsr>���r?���� <genexpr>��r����z&TemplateStream.dump.<locals>.<genexpr>� writelines)rG���r���r����rv���rO��r����r����)rq����fprL��rM��r�����iterable�itemr>���rK��r?����dump��s$���� �zTemplateStream.dumpc�����������������C���s���t�t|�j�|�_d|�_dS�)zDisable the output buffering.FN)r����nextrG���_next�bufferedr����r>���r>���r?���rH��)��s����z TemplateStream.disable_bufferingc�����������������c���sv���g�}d}|j�}z,||k�r8t|�j�}||��|r|d7�}qW�n�tyV���|sRY�d�S�Y�n0�t|�V��|d�d��=�d}qd�S�)Nr���r���)�appendrT��rG��� StopIterationr.���)rq���rA����bufZc_size�pushr����r>���r>���r?����_buffered_generator.��s���� z"TemplateStream._buffered_generator����c�����������������C���s,���|dkrt�d��d|�_tt|��|��|�_dS�)z<Enable buffering. Buffer `size` items before yielding them.r���zbuffer size too smallTN)� ValueErrorrV��r���rT��r[��rU��)rq���rA���r>���r>���r?����enable_bufferingA��s����zTemplateStream.enable_bufferingc�����������������C���s���|�S�r����r>���r����r>���r>���r?����__iter__I��s����zTemplateStream.__iter__c�����������������C���s���|�����S�r����)rU��r����r>���r>���r?����__next__L��s����zTemplateStream.__next__)NrJ��)r\��)r��r��r��r��rs���rS��rH��r[��r^��r_��r`��r>���r>���r>���r?���r)�����s��� r)��)Or��r����r����r��� functoolsr���r���Z markupsafer���rp���r���Z_compatr���r���r ���r ���r���r���r ���r���r���Zcompilerr���r����defaultsr���r���r���r���r���r���r���r���r���r���r���r���r���r���r ���r!���� exceptionsr"���r#���r$���r%���r&���r����r'���r(���r)���r����r*���Zruntimer+���r,���r-���Zutilsr.���r/���r0���r1���r2���r4���r5���r7���r@���rB���rF���rL���rS���rT���r{���rU���r����r,��r����r)��r��r>���r>���r>���r?����<module>���s���� ������/��"U