BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib64/python3.6/site-packages/tornado/__pycache__/template.cpython-36.opt-1.pyc
3

	��f'��@sHdZddlZddlmZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZmZmZddlmZmZmZmZmZmZmZmZddlZejr�ddlmZmZd	ZGd
d�d�Ze�Z e!e!e!d�d
d�Z"Gdd�de#�Z$Gdd�de#�Z%Gdd�de%�Z&Gdd�de%�Z'Gdd�de#�Z(Gdd�de(�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(�Z0Gd)d*�d*e(�Z1Gd+d,�d,e(�Z2Gd-d.�d.e2�Z3Gd/d0�d0e(�Z4Gd1d2�d2e5�Z6Gd3d4�d4e#�Z7Gd5d6�d6e#�Z8e!e!d7�d8d9�Z9d=e8e$e!e!e*d:�d;d<�Z:dS)>a�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 ``{# ... #}``.

These tags may be escaped as ``{{!``, ``{%!``, and ``{#!``
if you need to include a literal ``{{``, ``{%``, or ``{#`` in the output.


``{% 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� /usr/lib64/python3.6/template.pyr�sr)�mode�text�returncCsZ|dkr|S|dkr4tjdd|�}tjdd|�}|S|dkrJtjdd|�Std	|��d
S)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 %sN)�re�sub�	Exception)rrrrr�filter_whitespace�s
r#c	@s�eZdZdZddeedfeeefedeee	feee	fedd�dd�Z
eed�d	d
�Ze
ded�dd
�Ze
dedd�dd�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�
BaseLoader)�template_string�name�loader�compress_whitespace�
autoescape�
whitespacerc	CsFtj|�|_|tk	r0|dk	r$td��|r,dnd}|dkrh|rJ|jrJ|j}n|jd�s^|jd�rdd}nd}t|d�t|t	�s�||_
n|r�|j
|_
nt|_
|r�|jni|_t
|tj|�|�}t|t||��|_|j|�|_||_y,ttj|j�d|jjd	d
�ddd
�|_Wn6tk
�r@t|j�j�}tjd|j|��YnXdS)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__s@




zTemplate.__init__)�kwargsrcs�tjtjtjtjtjtjttjtt	f�j
jdd�t�fdd�d�d�}|j
�j�|j
|�t�j|�tjtgt	f|d�}tj�|�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)rrrHrIrJrKrL�utf8r�bytesr'r=r�updater5rr>�typing�castr
�	linecache�
clearcache)rBrEr5Zexecuter)rBr�generatePs"
zTemplate.generate)r(rcCspt�}zZi}|j|�}|j�x|D]}|j||�q$Wt||||dj�}|dj|�|j�S|j�XdS)Nr)	r�_get_ancestors�reverse�find_named_blocks�_CodeWriter�templaterU�getvalue�close)rBr(�buffer�named_blocks�	ancestorsZancestor�writerrrrr:ks

zTemplate._generate_pythonr7cCsV|jg}xH|jjjD]:}t|t�r|s.td��|j|j|j�}|j|j	|��qW|S)Nz1{% extends %} block found, but no template loader)
r9�body�chunksr3�
_ExtendsBlock�
ParseError�loadr'�extendrV)rBr(r_�chunkrZrrrrVzs
zTemplate._get_ancestors)rrr�__doc__r1r	�strrO�boolrrDrrUrr:rrVrrrrr$�s(Cr$c@szeZdZdZeddfeeeefedd�dd�Zdd�dd�Z	deeed	�d
d�Z
deeed	�dd
�Zeed�dd�Z
dS)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.
    N)r*r5r+rcCs*||_|pi|_||_i|_tj�|_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__)rc	Cs|j�i|_WdQRXdS)z'Resets the cache of compiled templates.N)rnrk)rBrrr�reset�szBaseLoader.reset)r'�parent_pathrcCs
t��dS)z@Converts a possibly-relative path to absolute (used internally).N)�NotImplementedError)rBr'rprrr�resolve_path�szBaseLoader.resolve_pathc
CsD|j||d�}|j�&||jkr0|j|�|j|<|j|SQRXdS)zLoads a template.)rpN)rrrnrk�_create_template)rBr'rprrrre�s

zBaseLoader.load)r'rcCs
t��dS)N)rq)rBr'rrrrs�szBaseLoader._create_template)N)N)rrrrhr4rirrrDrorrr$rersrrrrr%�sr%csNeZdZdZeedd��fdd�Zdeeed�dd�Zeed	�d
d�Z	�Z
S)
�Loaderz?A template loader that loads from a single root directory.
    N)�root_directoryrErcs$tt|�jf|�tjj|�|_dS)N)�superrtrD�os�path�abspath�root)rBrurE)�	__class__rrrD�szLoader.__init__)r'rprcCs�|r�|jd�r�|jd�r�|jd�r�tjj|j|�}tjjtjj|��}tjjtjj||��}|j|j�r�|t|j�dd�}|S)N�<�/�)�
startswithrwrx�joinrz�dirnamery�len)rBr'rpZcurrent_path�file_dirZ
relative_pathrrrrr�szLoader.resolve_path)r'rcCs<tjj|j|�}t|d��}t|j�||d�}|SQRXdS)N�rb)r'r()rwrxr�rz�openr$�read)rBr'rx�frZrrrrs�szLoader._create_template)N)rrrrhrirrDrrr$rs�
__classcell__rr)r{rrt�srtcsVeZdZdZeeefedd��fdd�Zdeeed�dd�Zee	d	�d
d�Z
�ZS)
�
DictLoaderz/A template loader that loads from a dictionary.N)�dictrErcstt|�jf|�||_dS)N)rvr�rDr�)rBr�rE)r{rrrD�szDictLoader.__init__)r'rprcCsH|rD|jd�rD|jd�rD|jd�rDtj|�}tjtj||��}|S)Nr|r})r�	posixpathr��normpathr�)rBr'rpr�rrrrr�s
zDictLoader.resolve_path)r'rcCst|j|||d�S)N)r'r()r$r�)rBr'rrrrs�szDictLoader._create_template)N)rrrrhrrirrDrrr$rsr�rr)r{rr��sr�c@sLeZdZedd�dd�Zddd�dd�Zeeee	d	fdd
�dd�Z
dS)
�_Node)rcCsfS)Nr)rBrrr�
each_child�sz_Node.each_childrYN)r`rcCs
t��dS)N)rq)rBr`rrrrU�sz_Node.generate�_NamedBlock)r(r^rcCs"x|j�D]}|j||�q
WdS)N)r�rX)rBr(r^ZchildrrrrX�sz_Node.find_named_blocks)rrrr
r�rUrr%rrirXrrrrr��sr�c@s@eZdZeddd�dd�Zddd�dd	�Zed
d�dd
�ZdS)r7�
_ChunkListN)rZrarcCs||_||_d|_dS)Nr)rZra�line)rBrZrarrrrDsz_File.__init__rY)r`rc
Cs\|jd|j�|j��<|jd|j�|jd|j�|jj|�|jd|j�WdQRXdS)Nzdef _tt_execute():z_tt_buffer = []z_tt_append = _tt_buffer.appendz$return _tt_utf8('').join(_tt_buffer))�
write_liner��indentrarU)rBr`rrrrUs
z_File.generater�)rcCs|jfS)N)ra)rBrrrr�sz_File.each_child)rrrr$rDrUr
r�rrrrr7sr7c@sBeZdZeedd�dd�Zddd�dd�Zed	d
�dd�ZdS)
r�N)rbrcCs
||_dS)N)rb)rBrbrrrrDsz_ChunkList.__init__rY)r`rcCsx|jD]}|j|�qWdS)N)rbrU)rBr`rgrrrrUsz_ChunkList.generater�)rcCs|jS)N)rb)rBrrrr�sz_ChunkList.each_child)	rrrrr�rDrUr
r�rrrrr�sr�c@sbeZdZeeeedd�dd�Zedd�dd�Z	d	dd
�dd�Z
eee
edfdd
�dd�ZdS)r�N)r'rarZr�rcCs||_||_||_||_dS)N)r'rarZr�)rBr'rarZr�rrrrD$sz_NamedBlock.__init__r�)rcCs|jfS)N)ra)rBrrrr�*sz_NamedBlock.each_childrY)r`rc	Cs8|j|j}|j|j|j��|jj|�WdQRXdS)N)r^r'�includerZr�rarU)rBr`�blockrrrrU-sz_NamedBlock.generate)r(r^rcCs|||j<tj|||�dS)N)r'r�rX)rBr(r^rrrrX2s
z_NamedBlock.find_named_blocks)rrrrir�r$�intrDr
r�rUrr%rrXrrrrr�#s
r�c@seZdZedd�dd�ZdS)rcN)r'rcCs
||_dS)N)r')rBr'rrrrD:sz_ExtendsBlock.__init__)rrrrirDrrrrrc9srcc@sNeZdZededd�dd�Zeeeee	fdd�dd�Z
d	dd
�dd�ZdS)
�
_IncludeBlockr6N)r'rCr�rcCs||_|j|_||_dS)N)r'�
template_namer�)rBr'rCr�rrrrD?sz_IncludeBlock.__init__)r(r^rcCs"|j|j|j�}|jj||�dS)N)rer'r�r9rX)rBr(r^�includedrrrrXDsz_IncludeBlock.find_named_blocksrY)r`rc	Cs>|jj|j|j�}|j||j��|jjj|�WdQRXdS)N)	r(rer'r�r�r�r9rarU)rBr`r�rrrrUKsz_IncludeBlock.generate)rrrrir�rDrr%rr�rXrUrrrrr�>sr�c@sBeZdZeeedd�dd�Zedd�dd�Zd	dd
�dd�Z	dS)
�_ApplyBlockN)�methodr�rarcCs||_||_||_dS)N)r�r�ra)rBr�r�rarrrrDSsz_ApplyBlock.__init__r�)rcCs|jfS)N)ra)rBrrrr�Xsz_ApplyBlock.each_childrY)r`rcCs�d|j}|jd7_|jd||j�|j��<|jd|j�|jd|j�|jj|�|jd|j�WdQRX|jd|j|f|j�dS)Nz_tt_apply%dr~z	def %s():z_tt_buffer = []z_tt_append = _tt_buffer.appendz$return _tt_utf8('').join(_tt_buffer)z_tt_append(_tt_utf8(%s(%s()))))�
apply_counterr�r�r�rarUr�)rBr`Zmethod_namerrrrU[s

z_ApplyBlock.generate)
rrrrir�r�rDr
r�rUrrrrr�Rsr�c@sBeZdZeeedd�dd�Zeed�dd�Zddd	�d
d�Z	dS)�
_ControlBlockN)�	statementr�rarcCs||_||_||_dS)N)r�r�ra)rBr�r�rarrrrDjsz_ControlBlock.__init__)rcCs|jfS)N)ra)rBrrrr�osz_ControlBlock.each_childrY)r`rc
CsF|jd|j|j�|j�� |jj|�|jd|j�WdQRXdS)Nz%s:�pass)r�r�r�r�rarU)rBr`rrrrUrs
z_ControlBlock.generate)
rrrrir�r�rDr
r�rUrrrrr�isr�c@s.eZdZeedd�dd�Zddd�dd�ZdS)	�_IntermediateControlBlockN)r�r�rcCs||_||_dS)N)r�r�)rBr�r�rrrrD{sz"_IntermediateControlBlock.__init__rY)r`rcCs0|jd|j�|jd|j|j|j�d�dS)Nr�z%s:r~)r�r�r��indent_size)rBr`rrrrUsz"_IntermediateControlBlock.generate)rrrrir�rDrUrrrrr�zsr�c@s.eZdZeedd�dd�Zddd�dd�ZdS)	�
_StatementN)r�r�rcCs||_||_dS)N)r�r�)rBr�r�rrrrD�sz_Statement.__init__rY)r`rcCs|j|j|j�dS)N)r�r�r�)rBr`rrrrU�sz_Statement.generate)rrrrir�rDrUrrrrr��sr�c@s2eZdZd
eeedd�dd�Zddd�dd	�ZdS)�_ExpressionFN)�
expressionr��rawrcCs||_||_||_dS)N)r�r�r�)rBr�r�r�rrrrD�sz_Expression.__init__rY)r`rcCsl|jd|j|j�|jd|j�|jd|j�|jrZ|jjdk	rZ|jd|jj|j�|jd|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*)rBr`rrrrU�s
z_Expression.generate)F)rrrrir�rjrDrUrrrrr��sr�cs&eZdZeedd��fdd�Z�ZS)�_ModuleN)r�r�rcstt|�jd||dd�dS)Nz_tt_modules.T)r�)rvr�rD)rBr�r�)r{rrrD�sz_Module.__init__)rrrrir�rDr�rr)r{rr��sr�c@s0eZdZeeedd�dd�Zddd�dd�ZdS)	�_TextN)�valuer�r+rcCs||_||_||_dS)N)r�r�r+)rBr�r�r+rrrrD�sz_Text.__init__rY)r`rcCs:|j}d|krt|j|�}|r6|jdtj|�|j�dS)Nz<pre>z_tt_append(%r))r�r#r+r�rrNr�)rBr`r�rrrrU�s
z_Text.generate)rrrrir�rDrUrrrrr��sr�c@s4eZdZdZd
eeedd�dd�Zed�dd	�ZdS)rdz�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�linenorcCs||_||_||_dS)N)r�r�r�)rBr�r�r�rrrrD�szParseError.__init__)rcCsd|j|j|jfS)Nz%s at %s:%d)r�r�r�)rBrrr�__str__�szParseError.__str__)Nr)rrrrhrir�rDr�rrrrrd�srdc@sreZdZeeeefeee	dd�dd�Z
ed�dd�Zdd�d	d
�Z
e	edd�dd
�Zdeeedd�dd�ZdS)rYN)r9r^r(r�rcCs.||_||_||_||_d|_g|_d|_dS)Nr)r9r^r(r�r��
include_stack�_indent)rBr9r^r(r�rrrrD�sz_CodeWriter.__init__)rcCs|jS)N)r�)rBrrrr��sz_CodeWriter.indent_sizercsG�fdd�dt�}|�S)Ncs2eZdZdd��fdd�Zedd��fdd�ZdS)	z$_CodeWriter.indent.<locals>.IndenterrY)rcs�jd7_�S)Nr~)r�)r.)rBrr�	__enter__�sz._CodeWriter.indent.<locals>.Indenter.__enter__N)�argsrcs�jd8_dS)Nr~)r�)r.r�)rBrr�__exit__�sz-_CodeWriter.indent.<locals>.Indenter.__exit__)rrrr�rr�r)rBrr�Indenter�sr�)�object)rBr�r)rBrr��s	z_CodeWriter.indent)rZr�rcs2�jj�j|f�|�_G�fdd�dt�}|�S)Ncs2eZdZdd��fdd�Zedd��fdd�ZdS)	z,_CodeWriter.include.<locals>.IncludeTemplaterY)rcs�S)Nr)r.)rBrrr��sz6_CodeWriter.include.<locals>.IncludeTemplate.__enter__N)r�rcs�jj�d�_dS)Nr)r��popr�)r.r�)rBrrr��sz5_CodeWriter.include.<locals>.IncludeTemplate.__exit__)rrrr�rr�r)rBrr�IncludeTemplate�sr�)r��appendr�r�)rBrZr�r�r)rBrr��sz_CodeWriter.include)r��line_numberr�rcCsh|dkr|j}d|jj|f}|jrJdd�|jD�}|ddjt|��7}td||||jd�dS)Nz	  # %s:%dcSsg|]\}}d|j|f�qS)z%s:%d)r')�.0Ztmplr�rrr�
<listcomp>sz*_CodeWriter.write_line.<locals>.<listcomp>z	 (via %s)z, z    )r9)r�r�r'r�r��reversed�printr9)rBr�r�r�Zline_commentr_rrrr��sz_CodeWriter.write_line)N)rrrrrrir�rr%r$rDr�r�r�r�r�rrrrrY�s
	
rYc@s�eZdZeeedd�dd�Zdeeeed�dd�Zdeed	�d
d�Zed�d
d�Zed�dd�Z	e
eefed�dd�Zed�dd�Z
edd�dd�ZdS)r6N)r'rr+rcCs"||_||_||_d|_d|_dS)Nr~r)r'rr+r��pos)rBr'rr+rrrrD
s
z_TemplateReader.__init__r)�needle�start�endrcCsR|j}||7}|dkr&|jj||�}n||7}|jj|||�}|dkrN||8}|S)Nr~���)r�r�find)rBr�r�r�r��indexrrrr�sz_TemplateReader.find)�countrcCsX|dkrt|j�|j}|j|}|j|jjd|j|�7_|j|j|�}||_|S)Nr)r�rr�r�r�)rBr�Znewpos�srrr�consumes
z_TemplateReader.consume)rcCst|j�|jS)N)r�rr�)rBrrr�	remaining(sz_TemplateReader.remainingcCs|j�S)N)r�)rBrrr�__len__+sz_TemplateReader.__len__)�keyrcCs�t|t�r`t|�}|j|�\}}}|dkr2|j}n
||j7}|dk	rN||j7}|jt|||�S|dkrr|j|S|j|j|SdS)Nr)r3�slicer��indicesr�r)rBr��sizer��stop�steprrr�__getitem__.s



z_TemplateReader.__getitem__cCs|j|jd�S)N)rr�)rBrrrr�>sz_TemplateReader.__str__)�msgrcCst||j|j��dS)N)rdr'r�)rBr�rrr�raise_parse_errorAsz!_TemplateReader.raise_parse_error)rN)N)rrrrirDr�r�r�r�r�r	r�r�r�r�rrrrr6	s	r6)r;rcs<|j�}dttt|�d���dj�fdd�t|�D��S)Nz%%%dd  %%s
r~r,cs g|]\}}�|d|f�qS)r~r)r��ir�)�formatrrr�Hsz _format_code.<locals>.<listcomp>)�
splitlinesr��reprr��	enumerate)r;�linesr)r�rr?Esr?)rCrZ�in_block�in_looprcCsPtg�}�x@d}x�|jd|�}|d8ks6|d|j�krh|rH|jd|�|jjt|j�|j|j	��|S||dd9kr�|d7}q|d|j�kr�||ddkr�||ddkr�|d7}qPqW|dkr�|j|�}|jjt||j|j	��|jd�}|j}|j��r6|ddk�r6|jd�|jjt|||j	��q|d	k�rx|jd
�}	|	d:k�r^|jd�|j|	�j
�}
|jd�q|dk�r�|jd
�}	|	d;k�r�|jd�|j|	�j
�}
|jd�|
�s�|jd�|jjt|
|��q|jd�}	|	d<k�r�|jd�|j|	�j
�}
|jd�|
�s"|jd�|
jd�\}}}
|
j
�}
t
ddddg�t
dg�t
dg�t
dg�d�}|j|�}|dk	�r�|�s�|jd||f�||k�r�|jd||f�|jjt|
|��qq|dk�r�|�s�|jd�|S|d=k�r@|d"k�r�q|dk�r.|
j
d'�j
d(�}
|
�s"|jd)�t|
�}�n|d>k�rT|
�sH|jd*�t|
|�}n�|dk�r�|
j
d'�j
d(�}
|
�s~|jd+�t|
||�}n�|dk�r�|
�s�|jd,�t|
|�}n~|d#k�r�|
j
�}|d-k�r�d}||_qnT|d$k�r|
j
�}t|d.�||_	qn.|d%k�rt|
|d/d0�}n|d&k�r0t|
|�}|jj|�qq|d?k�r�|d@k�rdt||||�}n(|d1k�r~t|||d�}nt||||�}|d1k�r�|
�s�|jd3�t|
||�}n6|d2k�r�|
�s�|jd4�t|
|||�}nt|
||�}|jj|�qq|dAk�r:|�s$|jd|t
ddg�f�|jjt|
|��qq|jd7|�qWdS)BNr�{r~z Missing {%% end %%} block for %s�%�#��!z{#z#}zMissing end comment #}z{{z}}zMissing end expression }}zEmpty expressionz%}zMissing end block %}zEmpty block tag ({% %})r�if�for�while�try)�else�elif�except�finallyz%s outside %s blockz'%s block cannot be attached to %s blockr�zExtra {% end %} block�extendsr��set�import�from�commentr*r+r��module�"�'zextends missing file pathzimport missing statementzinclude missing file pathzset missing statement�Noner,T)r��applyr�zapply missing method namezblock missing name�break�continuezunknown operator: %rr�)r�r�r�r�r�r�)
r�r�r�r�r�r�r*r+r�r�)r�r�)r�r�r�r�r�r�)r�r�)r�r�)r�r�r�r�rbr�r�r�r�r+�stripr��	partitionr��getr�rcr�r�r*r#r�r8r�r�r�)rCrZr�r�raZcurlyZconsZstart_bracer�r��contents�operatorZspace�suffixZintermediate_blocksZallowed_parentsr��fnrZ
block_bodyrrrr8Ks$
















































r8)NN);rhrL�iorrSZos.pathrwr�r rlZtornadorZtornado.logrZtornado.utilrrrrQrr	r
rrr
rrZ
TYPE_CHECKINGrrr4rr1rir#r�r$r%rtr�r�r7r�r�rcr�r�r�r�r�r�r�r�r"rdrYr6r?r8rrrr�<module>�sV(
=	8<