HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/tornado/__pycache__/template.cpython-310.pyc
o

;j&��@sXdZddlZddlmZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZmZmZddlmZmZmZmZmZmZmZmZddlZejrYddlmZmZd	ZGd
d�d�Ze�Z de!d
e!de!fdd�Z"Gdd�d�Z#Gdd�d�Z$Gdd�de$�Z%Gdd�de$�Z&Gdd�d�Z'Gdd�de'�Z(Gdd�de'�Z)Gdd �d e'�Z*Gd!d"�d"e'�Z+Gd#d$�d$e'�Z,Gd%d&�d&e'�Z-Gd'd(�d(e'�Z.Gd)d*�d*e'�Z/Gd+d,�d,e'�Z0Gd-d.�d.e'�Z1Gd/d0�d0e1�Z2Gd1d2�d2e'�Z3Gd3d4�d4e4�Z5Gd5d6�d6�Z6Gd7d8�d8�Z7d9e!de!fd:d;�Z8		dBd<e7d=e#d>ee!d?ee!de)f
d@dA�Z9dS)Ca�A simple template system that compiles templates to Python code.

Basic usage looks like::

    t = template.Template("<html>{{ myvalue }}</html>")
    print(t.generate(myvalue="XXX"))

`Loader` is a class that loads templates from a root directory and caches
the compiled templates::

    loader = template.Loader("/home/btaylor")
    print(loader.load("test.html").generate(myvalue="XXX"))

We compile all templates to raw Python. Error-reporting is currently... uh,
interesting. Syntax for the templates::

    ### base.html
    <html>
      <head>
        <title>{% block title %}Default title{% end %}</title>
      </head>
      <body>
        <ul>
          {% for student in students %}
            {% block student %}
              <li>{{ escape(student.name) }}</li>
            {% end %}
          {% end %}
        </ul>
      </body>
    </html>

    ### bold.html
    {% extends "base.html" %}

    {% block title %}A bolder title{% end %}

    {% block student %}
      <li><span style="bold">{{ escape(student.name) }}</span></li>
    {% end %}

Unlike most other template systems, we do not put any restrictions on the
expressions you can include in your statements. ``if`` and ``for`` blocks get
translated exactly into Python, so you can do complex expressions like::

   {% for student in [p for p in people if p.student and p.age > 23] %}
     <li>{{ escape(student.name) }}</li>
   {% end %}

Translating directly to Python means you can apply functions to expressions
easily, like the ``escape()`` function in the examples above. You can pass
functions in to your template just like any other variable
(In a `.RequestHandler`, override `.RequestHandler.get_template_namespace`)::

   ### Python code
   def add(x, y):
      return x + y
   template.execute(add=add)

   ### The template
   {{ add(1, 2) }}

We provide the functions `escape() <.xhtml_escape>`, `.url_escape()`,
`.json_encode()`, and `.squeeze()` to all templates by default.

Typical applications do not create `Template` or `Loader` instances by
hand, but instead use the `~.RequestHandler.render` and
`~.RequestHandler.render_string` methods of
`tornado.web.RequestHandler`, which load templates automatically based
on the ``template_path`` `.Application` setting.

Variable names beginning with ``_tt_`` are reserved by the template
system and should not be used by application code.

Syntax Reference
----------------

Template expressions are surrounded by double curly braces: ``{{ ... }}``.
The contents may be any python expression, which will be escaped according
to the current autoescape setting and inserted into the output.  Other
template directives use ``{% %}``.

To comment out a section so that it is omitted from the output, surround it
with ``{# ... #}``.


To include a literal ``{{``, ``{%``, or ``{#`` in the output, escape them as
``{{!``, ``{%!``, and ``{#!``, respectively.


``{% apply *function* %}...{% end %}``
    Applies a function to the output of all template code between ``apply``
    and ``end``::

        {% apply linkify %}{{name}} said: {{message}}{% end %}

    Note that as an implementation detail apply blocks are implemented
    as nested functions and thus may interact strangely with variables
    set via ``{% set %}``, or the use of ``{% break %}`` or ``{% continue %}``
    within loops.

``{% autoescape *function* %}``
    Sets the autoescape mode for the current file.  This does not affect
    other files, even those referenced by ``{% include %}``.  Note that
    autoescaping can also be configured globally, at the `.Application`
    or `Loader`.::

        {% autoescape xhtml_escape %}
        {% autoescape None %}

``{% block *name* %}...{% end %}``
    Indicates a named, replaceable block for use with ``{% extends %}``.
    Blocks in the parent template will be replaced with the contents of
    the same-named block in a child template.::

        <!-- base.html -->
        <title>{% block title %}Default title{% end %}</title>

        <!-- mypage.html -->
        {% extends "base.html" %}
        {% block title %}My page title{% end %}

``{% comment ... %}``
    A comment which will be removed from the template output.  Note that
    there is no ``{% end %}`` tag; the comment goes from the word ``comment``
    to the closing ``%}`` tag.

``{% extends *filename* %}``
    Inherit from another template.  Templates that use ``extends`` should
    contain one or more ``block`` tags to replace content from the parent
    template.  Anything in the child template not contained in a ``block``
    tag will be ignored.  For an example, see the ``{% block %}`` tag.

``{% for *var* in *expr* %}...{% end %}``
    Same as the python ``for`` statement.  ``{% break %}`` and
    ``{% continue %}`` may be used inside the loop.

``{% from *x* import *y* %}``
    Same as the python ``import`` statement.

``{% if *condition* %}...{% elif *condition* %}...{% else %}...{% end %}``
    Conditional statement - outputs the first section whose condition is
    true.  (The ``elif`` and ``else`` sections are optional)

``{% import *module* %}``
    Same as the python ``import`` statement.

``{% include *filename* %}``
    Includes another template file.  The included file can see all the local
    variables as if it were copied directly to the point of the ``include``
    directive (the ``{% autoescape %}`` directive is an exception).
    Alternately, ``{% module Template(filename, **kwargs) %}`` may be used
    to include another template with an isolated namespace.

``{% module *expr* %}``
    Renders a `~tornado.web.UIModule`.  The output of the ``UIModule`` is
    not escaped::

        {% module Template("foo.html", arg=42) %}

    ``UIModules`` are a feature of the `tornado.web.RequestHandler`
    class (and specifically its ``render`` method) and will not work
    when the template system is used on its own in other contexts.

``{% raw *expr* %}``
    Outputs the result of the given expression without autoescaping.

``{% set *x* = *y* %}``
    Sets a local variable.

``{% try %}...{% except %}...{% else %}...{% finally %}...{% end %}``
    Same as the python ``try`` statement.

``{% while *condition* %}... {% end %}``
    Same as the python ``while`` statement.  ``{% break %}`` and
    ``{% continue %}`` may be used inside the loop.

``{% whitespace *mode* %}``
    Sets the whitespace mode for the remainder of the current file
    (or until the next ``{% whitespace %}`` directive). See
    `filter_whitespace` for available options. New in Tornado 4.3.
�N)�StringIO)�escape)�app_log)�
ObjectDict�exec_in�unicode_type)�Any�Union�Callable�List�Dict�Iterable�Optional�TextIO)�Tuple�ContextManager�xhtml_escapec@seZdZdS)�_UnsetMarkerN)�__name__�
__module__�__qualname__�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/tornado/template.pyr�sr�mode�text�returncCsV|dkr|S|dkrt�dd|�}t�dd|�}|S|dkr%t�dd|�Std	|��)
a�Transform whitespace in ``text`` according to ``mode``.

    Available modes are:

    * ``all``: Return all whitespace unmodified.
    * ``single``: Collapse consecutive whitespace with a single whitespace
      character, preserving newlines.
    * ``oneline``: Collapse all runs of whitespace into a single space
      character, removing all newlines in the process.

    .. versionadded:: 4.3
    �all�singlez([\t ]+)� z
(\s*\n\s*)�
Zonelinez(\s+)zinvalid whitespace mode %s)�re�sub�	Exception)rrrrr�filter_whitespace�s
r#c@s�eZdZdZddeedfdeeefdededdee	e
fd	eeee
fd
eeddfdd
�Zdedefdd�Z
deddefdd�Zdeddedfdd�ZdS)�Templatez�A compiled template.

    We compile into Python from the given template_string. You can generate
    the template from variables with generate().
    z<string>N�template_string�name�loader�
BaseLoader�compress_whitespace�
autoescape�
whitespacerc	CsHt�|�|_|tur|durtd��|rdnd}|dur4|r%|jr%|j}n|�d�s/|�d�r2d}nd}|dus:J�t|d�t|t	�sH||_
n
|rO|j
|_
nt|_
|rW|jni|_t
|t�|�|�}t|t||��|_|�|�|_||_ztt�|j�d|j�d	d
�ddd
�|_WdSty�t|j���}t�d|j|��w)a�Construct a Template.

        :arg str template_string: the contents of the template file.
        :arg str name: the filename from which the template was loaded
            (used for error message).
        :arg tornado.template.BaseLoader loader: the `~tornado.template.BaseLoader` responsible
            for this template, used to resolve ``{% include %}`` and ``{% extend %}`` directives.
        :arg bool compress_whitespace: Deprecated since Tornado 4.3.
            Equivalent to ``whitespace="single"`` if true and
            ``whitespace="all"`` if false.
        :arg str autoescape: The name of a function in the template
            namespace, or ``None`` to disable escaping by default.
        :arg str whitespace: A string specifying treatment of whitespace;
            see `filter_whitespace` for options.

        .. versionchanged:: 4.3
           Added ``whitespace`` parameter; deprecated ``compress_whitespace``.
        Nz2cannot set both whitespace and compress_whitespacerrz.htmlz.js�z%s.generated.py�.�_�execT)�dont_inheritz%s code:
%s)rZ
native_strr&�_UNSETr"r+�endswithr#�
isinstancerr*�_DEFAULT_AUTOESCAPE�	namespace�_TemplateReader�_File�_parse�file�_generate_python�coder'�compileZ
to_unicode�replace�compiled�_format_code�rstripr�error)	�selfr%r&r'r)r*r+�readerZformatted_coderrr�__init__sF




��zTemplate.__init__�kwargscs�tjtjtjtjtjtjttjtt	f�j
�dd�t�fdd�d�d�}|�
�j�|�
|�t�j|�t�tgt	f|d�}t��|�S)z0Generate this template with the given arguments.r-r.cs�jS�N)r;�r&�rBrr�<lambda>`sz#Template.generate.<locals>.<lambda>)�
get_source)rr�
url_escape�json_encode�squeeze�linkify�datetimeZ_tt_utf8Z_tt_string_typesr�
__loader__Z_tt_execute)rrrKrLrMrNrO�utf8r�bytesr&r=r�updater5rr>�typing�castr
�	linecache�
clearcache)rBrEr5ZexecuterrHr�generateQs$�
zTemplate.generatecCsrt�}z0i}|�|�}|��|D]}|�||�qt||||dj�}|d�|�|��W|��S|��w�Nr)	r�_get_ancestors�reverse�find_named_blocks�_CodeWriter�templaterX�getvalue�close)rBr'�buffer�named_blocks�	ancestorsZancestor�writerrrrr:ls
zTemplate._generate_pythonr7cCsR|jg}|jjjD]}t|t�r&|std��|�|j|j�}|�|�	|��q	|S)Nz1{% extends %} block found, but no template loader)
r9�body�chunksr3�
_ExtendsBlock�
ParseError�loadr&�extendrZ)rBr'rc�chunkr^rrrrZ{s
��zTemplate._get_ancestors)rrr�__doc__r1r	�strrRr�boolrrDrrXr:rrZrrrrr$�s2�
���
���
�Kr$c	@s�eZdZdZeddfdeedeeeefdeeddfdd�Z	dd	d
�Z
ddedeedefd
d�Zddedeedefdd�Z
dedefdd�ZdS)r(z�Base class for template loaders.

    You must use a template loader to use template constructs like
    ``{% extends %}`` and ``{% include %}``. The loader caches all
    templates after they are loaded the first time.
    Nr*r5r+rcCs*||_|pi|_||_i|_t��|_dS)a�Construct a template loader.

        :arg str autoescape: The name of a function in the template
            namespace, such as "xhtml_escape", or ``None`` to disable
            autoescaping by default.
        :arg dict namespace: A dictionary to be added to the default template
            namespace, or ``None``.
        :arg str whitespace: A string specifying default behavior for
            whitespace in templates; see `filter_whitespace` for options.
            Default is "single" for files ending in ".html" and ".js" and
            "all" for other files.

        .. versionchanged:: 4.3
           Added ``whitespace`` parameter.
        N)r*r5r+�	templates�	threading�RLock�lock)rBr*r5r+rrrrD�s

zBaseLoader.__init__cCs2|j�i|_Wd�dS1swYdS)z'Resets the cache of compiled templates.N)rrrorHrrr�reset�s"�zBaseLoader.resetr&�parent_pathcC�t��)z@Converts a possibly-relative path to absolute (used internally).��NotImplementedError�rBr&rtrrr�resolve_path�szBaseLoader.resolve_pathcCs\|j||d�}|j�||jvr|�|�|j|<|j|Wd�S1s'wYdS)zLoads a template.)rtN)ryrrro�_create_templaterxrrrri�s
$�zBaseLoader.loadcCrurFrv�rBr&rrrrz��zBaseLoader._create_template)rNrF)rrrrlr4rrmrrrDrsryr$rirzrrrrr(�s$	����
�
 r(cs\eZdZdZdededdf�fdd�Zdded	eedefd
d�Zdede	fdd
�Z
�ZS)�Loaderz:A template loader that loads from a single root directory.�root_directoryrErNcs$t�jdi|��tj�|�|_dS�Nr)�superrD�os�path�abspath�root)rBr~rE��	__class__rrrD�szLoader.__init__r&rtcCs�|r?|�d�s?|�d�s?|�d�s?tj�|j|�}tj�tj�|��}tj�tj�||��}|�|j�r?|t|j�dd�}|S)N�<�/�)�
startswithr�r��joinr��dirnamer��len)rBr&rtZcurrent_path�file_dirZ
relative_pathrrrry�s����zLoader.resolve_pathcCsTtj�|j|�}t|d��}t|��||d�}|Wd�S1s#wYdS)N�rb�r&r')r�r�r�r��openr$�read)rBr&r��fr^rrrrz�s
$�zLoader._create_templaterF)rrrrlrmrrDrryr$rz�
__classcell__rrr�rr}�s
r}csdeZdZdZdeeefdeddf�fdd�Zdded	eedefd
d�Z	dede
fdd
�Z�ZS)�
DictLoaderz/A template loader that loads from a dictionary.�dictrErNcst�jdi|��||_dSr)r�rDr�)rBr�rEr�rrrD�s
zDictLoader.__init__r&rtcCsB|r|�d�s|�d�s|�d�st�|�}t�t�||��}|S)Nr�r�)r��	posixpathr��normpathr�)rBr&rtr�rrrry�s����
zDictLoader.resolve_pathcCst|j|||d�S)Nr�)r$r�r{rrrrz��zDictLoader._create_templaterF)
rrrrlrrmrrDrryr$rzr�rrr�rr��s
"r�c@sJeZdZdedfdd�Zddd�Zd	eed
ee	dfddfdd
�Z
dS)�_NodercCsdSrrrHrrr�
each_child��z_Node.each_childrdr]NcCrurFrv�rBrdrrrrX�r|z_Node.generater'rb�_NamedBlockcCs|��D]}|�||�qdSrF)r�r\)rBr'rb�childrrrr\�s�z_Node.find_named_blocks�rdr]rN)rrrr
r�rXrr(rrmr\rrrrr��s
�
��r�c@s>eZdZdeddddfdd�Zdd
d�Zdedfd
d�ZdS)r7r^re�
_ChunkListrNcCs||_||_d|_dSrY)r^re�line)rBr^rerrrrD�
z_File.__init__rdr]cCsr|�d|j�|���$|�d|j�|�d|j�|j�|�|�d|j�Wd�dS1s2wYdS)Nzdef _tt_execute():�_tt_buffer = []�_tt_append = _tt_buffer.append�$return _tt_utf8('').join(_tt_buffer))�
write_liner��indentrerXr�rrrrXs
"�z_File.generater�cC�|jfSrF�rerHrrrr��z_File.each_childr�)rrrr$rDrXr
r�rrrrr7s
r7c@s>eZdZdeeddfdd�Zd
dd	�Zded
fdd�ZdS)r�rfrNcC�
||_dSrF�rf)rBrfrrrrD�
z_ChunkList.__init__rdr]cCs|jD]}|�|�qdSrF)rfrX)rBrdrkrrrrXs
�z_ChunkList.generater�cC�|jSrFr�rHrrrr�r|z_ChunkList.each_childr�)	rrrrr�rDrXr
r�rrrrr�s
r�c
@sheZdZdededededdf
dd�Zded	fd
d�Z	ddd�Z
deede
edfddfdd�ZdS)r�r&rer^r�rNcCs||_||_||_||_dSrF)r&rer^r�)rBr&rer^r�rrrrD$s
z_NamedBlock.__init__r�cCr�rFr�rHrrrr�*r�z_NamedBlock.each_childrdr]cCsN|j|j}|�|j|j��|j�|�Wd�dS1s wYdSrF)rbr&�includer^r�rerX)rBrd�blockrrrrX-s"�z_NamedBlock.generater'rbcCs|||j<t�|||�dSrF)r&r�r\)rBr'rbrrrr\2s
z_NamedBlock.find_named_blocksr�)rrrrmr�r$�intrDr
r�rXrr(rr\rrrrr�#s
�
��r�c@seZdZdeddfdd�ZdS)rgr&rNcCr�rFrGr{rrrrD:r�z_ExtendsBlock.__init__)rrrrmrDrrrrrg9srgc@sReZdZdedddeddfdd�Zd	eed
eee	fddfdd�Z
ddd�ZdS)�
_IncludeBlockr&rCr6r�rNcCs||_|j|_||_dSrF)r&�
template_namer�)rBr&rCr�rrrrD?s
z_IncludeBlock.__init__r'rbcCs.|dusJ�|�|j|j�}|j�||�dSrF)rir&r�r9r\)rBr'rb�includedrrrr\Dsz_IncludeBlock.find_named_blocksrdr]cCsb|jdusJ�|j�|j|j�}|�||j��|jj�|�Wd�dS1s*wYdSrF)	r'rir&r�r�r�r9rerX)rBrdr�rrrrXKs
"�z_IncludeBlock.generater�)rrrrmr�rDrr(rr�r\rXrrrrr�>s�
�
�r�c@sBeZdZdedededdfdd�Zdedfd	d
�Zdd
d�Z	dS)�_ApplyBlock�methodr�rerNcC�||_||_||_dSrF)r�r�re)rBr�r�rerrrrDSr�z_ApplyBlock.__init__r�cCr�rFr�rHrrrr�Xr�z_ApplyBlock.each_childrdr]cCs�d|j}|jd7_|�d||j�|���#|�d|j�|�d|j�|j�|�|�d|j�Wd�n1s?wY|�d|j�d|�d	�|j�dS)
Nz_tt_apply%dr�z	def %s():r�r�r�z_tt_append(_tt_utf8(�(z()))))�
apply_counterr�r�r�rerXr�)rBrd�method_namerrrrX[s

��z_ApplyBlock.generater��
rrrrmr�r�rDr
r�rXrrrrr�R�r�c@sBeZdZdedededdfdd�Zdeefdd	�Zddd
�Z	dS)�
_ControlBlock�	statementr�rerNcCr�rF)r�r�re)rBr�r�rerrrrDjr�z_ControlBlock.__init__cCr�rFr�rHrrrr�or�z_ControlBlock.each_childrdr]cCs\|�d|j|j�|���|j�|�|�d|j�Wd�dS1s'wYdS)N�%s:�pass)r�r�r�r�rerXr�rrrrXrs

"�z_ControlBlock.generater�r�rrrrr�ir�r�c@�,eZdZdededdfdd�Zdd	d
�ZdS)�_IntermediateControlBlockr�r�rNcC�||_||_dSrF�r�r��rBr�r�rrrrD{�
z"_IntermediateControlBlock.__init__rdr]cCs0|�d|j�|�d|j|j|��d�dS)Nr�r�r�)r�r�r��indent_sizer�rrrrXs"z"_IntermediateControlBlock.generater��rrrrmr�rDrXrrrrr�z�r�c@r�)�
_Statementr�r�rNcCr�rFr�r�rrrrD�r�z_Statement.__init__rdr]cCs|�|j|j�dSrF)r�r�r�r�rrrrX�r�z_Statement.generater�r�rrrrr��r�r�c	@s2eZdZd
dedededdfdd�Zddd�ZdS)�_ExpressionF�
expressionr��rawrNcCr�rF)r�r�r�)rBr�r�r�rrrrD�r�z_Expression.__init__rdr]cCsj|�d|j|j�|�d|j�|�d|j�|js,|jjdur,|�d|jj|j�|�d|j�dS)Nz_tt_tmp = %szEif isinstance(_tt_tmp, _tt_string_types): _tt_tmp = _tt_utf8(_tt_tmp)z&else: _tt_tmp = _tt_utf8(str(_tt_tmp))z_tt_tmp = _tt_utf8(%s(_tt_tmp))z_tt_append(_tt_tmp))r�r�r�r��current_templater*r�rrrrX�s�
�z_Expression.generate)Fr�)rrrrmr�rnrDrXrrrrr��sr�cs*eZdZdededdf�fdd�Z�ZS)�_Moduler�r�rNcst�jd||dd�dS)Nz_tt_modules.T�r�)r�rD)rBr�r�r�rrrD�sz_Module.__init__)rrrrmr�rDr�rrr�rr��s"r�c@s0eZdZdedededdfdd�Zdd
d�ZdS)
�_Text�valuer�r+rNcCr�rF)r�r�r+)rBr�r�r+rrrrD�r�z_Text.__init__rdr]cCs>|j}d|vr
t|j|�}|r|�dt�|�|j�dSdS)Nz<pre>z_tt_append(%r))r�r#r+r�rrQr�)rBrdr�rrrrX�s�z_Text.generater�r�rrrrr��sr�c	@s@eZdZdZ	ddedeededdfdd	�Zdefd
d�ZdS)
rhz�Raised for template syntax errors.

    ``ParseError`` instances have ``filename`` and ``lineno`` attributes
    indicating the position of the error.

    .. versionchanged:: 4.3
       Added ``filename`` and ``lineno`` attributes.
    Nr�message�filename�linenorcCr�rF�r�r�r�)rBr�r�r�rrrrD�s
zParseError.__init__cCsd|j|j|jfS)Nz%s at %s:%dr�rHrrr�__str__�r�zParseError.__str__rY)	rrrrlrmrr�rDr�rrrrrh�s
����
�	rhc
@s�eZdZdedeeefdeede	ddf
dd�Z
defd	d
�Zddd
�Z
de	deddfdd�Z	ddededeeddfdd�ZdS)r]r9rbr'r�rNcCs.||_||_||_||_d|_g|_d|_dSrY)r9rbr'r�r��
include_stack�_indent)rBr9rbr'r�rrrrD�s
z_CodeWriter.__init__cCr�rF�r�rHrrrr��r|z_CodeWriter.indent_sizercsG�fdd�d�}|�S)Nc�0eZdZd	�fdd�Zdeddf�fdd�ZdS)
z$_CodeWriter.indent.<locals>.Indenterrr]cs�jd7_�S)Nr�r��r.rHrr�	__enter__�sz._CodeWriter.indent.<locals>.Indenter.__enter__�argsNcs �jdksJ��jd8_dS)Nrr�r��r.r�rHrr�__exit__�sz-_CodeWriter.indent.<locals>.Indenter.__exit__�rr]�rrrr�rr�rrHrr�Indenter�sr�r)rBr�rrHrr��s	z_CodeWriter.indentr^r�cs0�j��j|f�|�_G�fdd�d�}|�S)Ncr�)
z,_CodeWriter.include.<locals>.IncludeTemplaterr]cs�SrFrr�rHrrr��r�z6_CodeWriter.include.<locals>.IncludeTemplate.__enter__r�Ncs�j��d�_dSrY)r��popr�r�rHrrr��r�z5_CodeWriter.include.<locals>.IncludeTemplate.__exit__r�r�rrHrr�IncludeTemplate�sr�)r��appendr�)rBr^r�r�rrHrr��sz_CodeWriter.include�line_numberr�cCsh|dur|j}d|jj|f}|jr%dd�|jD�}|dd�t|��7}td||||jd�dS)Nz	  # %s:%dcSsg|]\}}d|j|f�qS)z%s:%drG)�.0Ztmplr�rrr�
<listcomp>s�z*_CodeWriter.write_line.<locals>.<listcomp>z	 (via %s)z, z    )r9)r�r�r&r�r��reversed�printr9)rBr�r�r�Zline_commentrcrrrr��s�z_CodeWriter.write_line)rrrF)rrrrrrmr�rr(r$rDr�r�r�r�r�rrrrr]�s2�
���
�
�����r]c	@s�eZdZdedededdfdd�Zdd	ed
edeedefdd
�Zddeedefdd�Zdefdd�Z	defdd�Z
deeefdefdd�Z
defdd�Zdeddfdd�ZdS)r6r&rr+rNcCs"||_||_||_d|_d|_dS)Nr�r)r&rr+r��pos)rBr&rr+rrrrDs

z_TemplateReader.__init__r�needle�start�endcCsn|dksJ|��|j}||7}|dur|j�||�}n||7}||ks%J�|j�|||�}|dkr5||8}|S)Nr���)r�r�find)rBr�r�r�r��indexrrrr�sz_TemplateReader.find�countcCsX|durt|j�|j}|j|}|j|j�d|j|�7_|j|j|�}||_|S)Nr)r�rr�r�r�)rBr�Znewpos�srrr�consume#s
z_TemplateReader.consumecCst|j�|jSrF)r�rr�rHrrr�	remaining,�z_TemplateReader.remainingcCs|��SrF)r�rHrrr�__len__/r�z_TemplateReader.__len__�keycCs�t|t�r0t|�}|�|�\}}}|dur|j}n||j7}|dur'||j7}|jt|||�S|dkr9|j|S|j|j|SrY)r3�slicer��indicesr�r)rBr��sizer��stop�steprrr�__getitem__2s



z_TemplateReader.__getitem__cCs|j|jd�SrF)rr�rHrrrr�Br�z_TemplateReader.__str__�msgcCst||j|j��rF)rhr&r�)rBrrrr�raise_parse_errorEr�z!_TemplateReader.raise_parse_error)rNrF)rrrrmrDr�rr�r�r�r�r	r�rr�rrrrrr6
s 	r6r;cs<|��}dttt|�d���d��fdd�t|�D��S)Nz%%%dd  %%s
r�r,cs g|]\}}�|d|f�qS)r�r)r��ir���formatrrr�Ls z _format_code.<locals>.<listcomp>)�
splitlinesr��reprr��	enumerate)r;�linesrrrr?Isr?rCr^�in_block�in_loopcCs&tg�}	d}	|�d|�}|dks|d|��kr3|r#|�d|�|j�t|��|j|j	��|S||ddvr@|d7}q|d|��kr]||ddkr]||ddkr]|d7}q	|dkrs|�|�}|j�t||j|j	��|�d�}|j}|��r�|dd	kr�|�d�|j�t|||j	��q|d
kr�|�d�}	|	dkr�|�d�|�|	��
�}
|�d�q|d
kr�|�d�}	|	dkr�|�d�|�|	��
�}
|�d�|
s�|�d�|j�t|
|��q|dks�J|��|�d�}	|	dkr�|�d�|�|	��
�}
|�d�|
�s|�d�|
�d�\}}}
|
�
�}
hd�dhdhdhd�}|�
|�}|du�rX|�s>|�|�d|�d��||v�rN|�|�d|�d��|j�t|
|��q|dk�rg|�se|�d�|S|dv�r|d k�rrq|d!k�r�|
�
d"��
d#�}
|
�s�|�d$�t|
�}n|d%v�r�|
�s�|�d&�t|
|�}nl|d'k�r�|
�
d"��
d#�}
|
�s�|�d(�t|
||�}nP|d)k�r�|
�s�|�d*�t|
|�}n=|d+k�r�|
�
�}|d,k�r�d}||_q|d-k�r�|
�
�}t|d.�||_	q|d/k�rt|
|dd0�}n
|d1k�rt|
|�}|j�|�q|d2v�rn|d3v�r$t||||�}n|d4k�r1t|||d�}nt||||�}|d4k�rL|
�sE|�d5�t|
||�}n|d6k�ra|
�sY|�d7�t|
|||�}nt|
||�}|j�|�q|d8v�r�|�s�|�d9�|d:d;h��|j�t|
|��q|�d<|�q)=NTr�{r�r�z Missing {%% end %%} block for %s)r�%�#��!z{#z#}zMissing end comment #}z{{z}}zMissing end expression }}zEmpty expressionz{%z%}zMissing end block %}zEmpty block tag ({% %})r>�if�while�try�forrr)�else�elif�except�finallyz	 outside z blockz block cannot be attached to r�zExtra {% end %} block)
�extendsr��set�import�from�commentr*r+r��modulerr�"�'zextends missing file path)rrzimport missing statementr�zinclude missing file pathrzset missing statementr*�Noner+r,r�r�r)�applyr�rrrr)rrr"zapply missing method namer�zblock missing name)�break�continuez{} outside {} blockrrzunknown operator: %r)r�r�r�rrfr�r�r�r�r+�stripr��	partition�getr�rgr�r�r*r#r�r8r�r�r�r)rCr^r
rreZcurlyZconsZstart_bracer�r��contents�operator�space�suffixZintermediate_blocksZallowed_parentsr��fnrZ
block_bodyrrrr8Os��













�


�



























���r8)NN):rlrO�iorrVZos.pathr�r�r rpZtornadorZtornado.logrZtornado.utilrrrrTrr	r
rrr
rr�
TYPE_CHECKINGrrr4rr1rmr#r$r(r}r�r�r7r�r�rgr�r�r�r�r�r�r�r�r"rhr]r6r?r8rrrr�<module>sn8(
=	:<	������