
    h;                         S r SSKrSSKJr  SSKrSSKrSSKrSSKrSSK	r	SSK
Jr  SSKJr  SSKJrJrJr  SSKJrJrJrJrJrJrJrJr  SSKr\R6                  (       a  SSKJrJr  S	r " S
 S5      r\" 5       r S\!S\!S\!4S jr" " S S5      r# " S S5      r$ " S S\$5      r% " S S\$5      r& " S S5      r' " S S\'5      r( " S S\'5      r) " S S\'5      r* " S  S!\'5      r+ " S" S#\'5      r, " S$ S%\'5      r- " S& S'\'5      r. " S( S)\'5      r/ " S* S+\'5      r0 " S, S-\'5      r1 " S. S/\15      r2 " S0 S1\'5      r3 " S2 S3\45      r5 " S4 S55      r6 " S6 S75      r7S8\!S\!4S9 jr8  S?S:\7S;\#S<\\!   S=\\!   S\)4
S> jjr9g)@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 ``{# ... #}``.


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                       \ rS rSrSrg)_UnsetMarker    N)__name__
__module____qualname____firstlineno____static_attributes__r       cC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\tornado/template.pyr   r      s    r   r   modetextreturnc                     U S:X  a  U$ U S:X  a2  [         R                  " SSU5      n[         R                  " SSU5      nU$ U S:X  a  [         R                  " SSU5      $ [        S	U -  5      e)
ar  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*)
onelinez(\s+)zinvalid whitespace mode %s)resub	Exception)r   r    s     r   filter_whitespacer+      sm     u}		vvk3-vvmT40		vvhT**4t;<<r   c                       \ rS rSrSrSS\\S4S\\\4   S\S\	S   S	\\
\4   S
\	\\\4      S\	\   SS4S jjrS\S\4S jrS\	S   S\4S jrS\	S   S\S   4S jrSrg)Template   zA 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
whitespacer!   c                    [         R                  " U5      U l        U[        La  Ub  [	        S5      eU(       a  SOSnUcV  U(       a  UR
                  (       a  UR
                  nO1UR                  S5      (       d  UR                  S5      (       a  SnOSnUc   e[        US5        [        U[        5      (       d  XPl
        O$U(       a  UR                  U l
        O[        U l
        U(       a  UR                  O0 U l        [        U[         R                  " U5      U5      n[        U [        Xp5      5      U l        U R#                  U5      U l        X0l         [)        [         R*                  " U R$                  5      SU R                  R-                  S	S
5      -  SSS9U l        g! [         aG    [1        U R$                  5      R3                  5       n[4        R6                  " SU R                  U5        e f = f)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_whitespacer$   r#   z.htmlz.js z%s.generated.py._execT)dont_inheritz%s code:
%s)r   
native_strr0   _UNSETr*   r5   endswithr+   
isinstancer   r4   _DEFAULT_AUTOESCAPE	namespace_TemplateReader_File_parsefile_generate_pythoncoder1   compile
to_unicodereplacecompiled_format_coderstripr   error)	selfr/   r0   r1   r3   r4   r5   readerformatted_codes	            r   __init__Template.__init__  s   6 %%d+	f,% TUU%8eJ&++#..
 ==))T]]5-A-A!)J!&J%%%*b)*l33(O$//DO1DO-3)) v'8'8'I:V$v 45	))&1		
 $!!$)),!DII$5$5c3$??!	DM  	)$))4;;=NMM.$))^D	s   AF' 'AG8kwargsc                 T  ^  [         R                  [         R                  [         R                  [         R                  [         R                  [         R
                  [        [         R                  [        [        4T R                  R                  SS5      [        U 4S jS9S.nUR                  T R                  5        UR                  U5        [        T R                   U5        ["        R$                  " [&        / [        4   US   5      n[(        R*                  " 5         U" 5       $ )z0Generate this template with the given arguments.r8   r9   c                    > TR                   $ N)rG   )r0   rO   s    r   <lambda>#Template.generate.<locals>.<lambda>`  s	    TYYr   )
get_source)r   r   
url_escapejson_encodesqueezelinkifydatetime_tt_utf8_tt_string_typesr   
__loader___tt_execute)r   r   r[   r\   r]   r^   r_   utf8r   bytesr0   rJ   r   updaterA   r   rK   typingcastr   	linecache
clearcache)rO   rT   rA   executes   `   r   generateTemplate.generateQ  s     ))"// ++!--~~~~ !-u 5 		))#s3$0FG
	 	( y)++hr5y19]3KL 	yr   c                 V   [        5       n 0 nU R                  U5      nUR                  5         U H  nUR                  X5        M     [	        X#XS   R
                  5      nUS   R                  U5        UR                  5       UR                  5         $ ! UR                  5         f = fNr   )	r   _get_ancestorsreversefind_named_blocks_CodeWritertemplaterl   getvalueclose)rO   r1   buffernamed_blocks	ancestorsancestorwriters          r   rF   Template._generate_pythonl  s    	L++F3I%**6@ & v|?T?TUFaL!!&)??$LLNFLLNs   A9B B(rC   c                 L   U R                   /nU R                   R                  R                   Hr  n[        U[        5      (       d  M  U(       d  [        S5      eUR                  UR                  U R                  5      nUR                  UR                  U5      5        Mt     U$ )Nz1{% extends %} block found, but no template loader)
rE   bodychunksr?   _ExtendsBlock
ParseErrorloadr0   extendrp   )rO   r1   ry   chunkrt   s        r   rp   Template._get_ancestors{  s    YYK	YY^^**E%//$N  ";;uzz499=  !8!8!@A + r   )r4   rG   rK   rE   r1   r0   rA   )r   r   r   r   __doc__r=   r
   strre   r   boolr   rR   r	   rl   rF   r   rp   r   r   r   r   r-   r-      s     )-9?9?$(IsEz*I I &	I
 #4#56I U3#456I SMI 
IV  6x'= # 
Xl%; 
W 
r   r-   c            	           \ rS rSrSr\SS4S\\   S\\\\	4      S\\   SS4S jjr
SS	 jrSS
\S\\   S\4S jjrSS
\S\\   S\4S jjrS
\S\4S jrSrg)r2   i  zBase 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.
Nr4   rA   r5   r!   c                 ~    Xl         U=(       d    0 U l        X0l        0 U l        [        R
                  " 5       U l        g)a0  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)r4   rA   r5   	templates	threadingRLocklock)rO   r4   rA   r5   s       r   rR   BaseLoader.__init__  s0    * %"b$ OO%	r   c                 ^    U R                      0 U l        SSS5        g! , (       d  f       g= f)z'Resets the cache of compiled templates.N)r   r   rO   s    r   resetBaseLoader.reset  s    YYDN YYs   
,r0   parent_pathc                     [        5       e)z@Converts a possibly-relative path to absolute (used internally).NotImplementedErrorrO   r0   r   s      r   resolve_pathBaseLoader.resolve_path  s    !##r   c                     U R                  XS9nU R                     XR                  ;  a  U R                  U5      U R                  U'   U R                  U   sSSS5        $ ! , (       d  f       g= f)zLoads a template.)r   N)r   r   r   _create_templater   s      r   r   BaseLoader.load  sU       ?YY>>)'+'<'<T'Bt$>>$' YYs   <A""
A0c                     [        5       erW   r   rO   r0   s     r   r   BaseLoader._create_template      !##r   )r4   r   rA   r   r5   )r!   NrW   )r   r   r   r   r   r@   r   r   r   r	   rR   r   r   r-   r   r   r   r   r   r   r2   r2     s     %8.2$(	&SM& DcN+& SM	&
 
&@ 
$ $8C= $C $( (8C= (H ($S $X $r   r2   c                   n   ^  \ rS rSrSrS\S\SS4U 4S jjrSS\S	\\   S\4S
 jjr	S\S\
4S jrSrU =r$ )Loaderi  z:A template loader that loads from a single root directory.root_directoryrT   r!   Nc                 n   > [         TU ]  " S0 UD6  [        R                  R	                  U5      U l        g Nr   )superrR   ospathabspathroot)rO   r   rT   	__class__s      r   rR   Loader.__init__  s'    "6"GGOON3	r   r0   r   c                 V   U(       Ga   UR                  S5      (       Gd	  UR                  S5      (       d  UR                  S5      (       d  [        R                  R                  U R                  U5      n[        R                  R                  [        R                  R                  U5      5      n[        R                  R                  [        R                  R                  XA5      5      nUR                  U R                  5      (       a  U[        U R                  5      S-   S  nU$ )N</   )
startswithr   r   joinr   dirnamer   len)rO   r0   r   current_pathfile_dirrelative_paths         r   r   Loader.resolve_path  s    **3//**3//OOC((77<<		;?Lwwrww|'DEHGGOOBGGLL,HIM''		22$S^a%7%9:r   c                     [         R                  R                  U R                  U5      n[	        US5       n[        UR                  5       XS9nUsS S S 5        $ ! , (       d  f       g = f)Nrbr0   r1   )r   r   r   r   openr-   read)rO   r0   r   frt   s        r   r   Loader._create_template  sG    ww||DIIt,$tAH s   A
A))r   rW   )r   r   r   r   r   r   r	   rR   r   r   r-   r   r   __classcell__r   s   @r   r   r     sV    D4s 4c 4d 4 8C= C S X  r   r   c                   x   ^  \ rS rSrSrS\\\4   S\SS4U 4S jjrSS\S	\	\   S\4S
 jjr
S\S\4S jrSrU =r$ )
DictLoaderi  z/A template loader that loads from a dictionary.dictrT   r!   Nc                 2   > [         TU ]  " S0 UD6  Xl        g r   )r   rR   r   )rO   r   rT   r   s      r   rR   DictLoader.__init__  s    "6"	r   r0   r   c                    U(       a  UR                  S5      (       dl  UR                  S5      (       dV  UR                  S5      (       d@  [        R                  " U5      n[        R                  " [        R                  " X15      5      nU$ )Nr   r   )r   	posixpathr   normpathr   )rO   r0   r   r   s       r   r   DictLoader.resolve_path  sd    **3//**3//OOC(( ((5H%%innX&DEDr   c                 0    [        U R                  U   XS9$ )Nr   )r-   r   r   s     r   r   DictLoader._create_template  s    		$d@@r   )r   rW   )r   r   r   r   r   r   r   r	   rR   r   r   r-   r   r   r   r   s   @r   r   r     sb    9T#s(^ s t 	 	8C= 	C 	AS AX A Ar   r   c                   X    \ rS rSrS\S    4S jrSS jrS\\   S\	\
S4   SS4S	 jrS
rg)_Nodei  r!   c                     gr   r   r   s    r   
each_child_Node.each_child  s    r   Nc                     [        5       erW   r   rO   r{   s     r   rl   _Node.generate  r   r   r1   rx   _NamedBlockc                 T    U R                  5        H  nUR                  X5        M     g rW   )r   rr   )rO   r1   rx   childs       r   rr   _Node.find_named_blocks  s#     __&E##F9 'r   r   r{   rs   r!   N)r   r   r   r   r   r   rl   r   r2   r   r   rr   r   r   r   r   r   r     sD    HW- $:z*::>sM?Q:R:	:r   r   c                   H    \ rS rSrS\SSSS4S jrSS jrS\S	   4S
 jrSr	g)rC   i  rt   r~   
_ChunkListr!   Nc                 *    Xl         X l        SU l        g ro   )rt   r~   line)rO   rt   r~   s      r   rR   _File.__init__  s     		r   c                 n   UR                  SU R                  5        UR                  5          UR                  SU R                  5        UR                  SU R                  5        U R                  R	                  U5        UR                  SU R                  5        S S S 5        g ! , (       d  f       g = f)Nzdef _tt_execute():_tt_buffer = []_tt_append = _tt_buffer.append$return _tt_utf8('').join(_tt_buffer))
write_liner   indentr~   rl   r   s     r   rl   _File.generate  s{    .		:]]_/;>		JIIv&DdiiP	 __s   A0B&&
B4r   c                     U R                   4$ rW   r~   r   s    r   r   _File.each_child      		|r   )r~   r   rt   r   )
r   r   r   r   r-   rR   rl   r   r   r   r   r   r   rC   rC     s3      $ 
QHW- r   rC   c                   J    \ rS rSrS\\   SS4S jrS
S jrS\S   4S jr	S	r
g)r   i  r   r!   Nc                     Xl         g rW   r   )rO   r   s     r   rR   _ChunkList.__init__  s    r   c                 L    U R                    H  nUR                  U5        M     g rW   )r   rl   )rO   r{   r   s      r   rl   _ChunkList.generate  s    [[ENN6" !r   r   c                     U R                   $ rW   r   r   s    r   r   _ChunkList.each_child  s    {{r   r   r   )r   r   r   r   r   r   rR   rl   r   r   r   r   r   r   r   r     s/    tE{ t #HW- r   r   c            
       v    \ rS rSrS\S\S\S\SS4
S jrS\	S	   4S
 jr
SS jrS\\   S\\S 4   SS4S jrSrg)r   i#  r0   r~   rt   r   r!   Nc                 4    Xl         X l        X0l        X@l        g rW   )r0   r~   rt   r   )rO   r0   r~   rt   r   s        r   rR   _NamedBlock.__init__$  s    		 	r   r   c                     U R                   4$ rW   r   r   s    r   r   _NamedBlock.each_child*  r   r   c                     UR                   U R                     nUR                  UR                  U R                  5         UR
                  R                  U5        S S S 5        g ! , (       d  f       g = frW   )rx   r0   includert   r   r~   rl   )rO   r{   blocks      r   rl   _NamedBlock.generate-  sJ    ##DII.^^ENNDII6JJ' 766s    A%%
A3r1   rx   c                 L    XU R                   '   [        R                  XU5        g rW   )r0   r   rr   )rO   r1   rx   s      r   rr   _NamedBlock.find_named_blocks2  s      #'TYYl;r   )r~   r   r0   rt   r   )r   r   r   r   r   r   r-   intrR   r   r   rl   r   r2   r   rr   r   r   r   r   r   r   #  sm    S    QU HW- (
<z*<:>sM?Q:R<	<r   r   c                   &    \ rS rSrS\SS4S jrSrg)r   i9  r0   r!   Nc                     Xl         g rW   r0   r   s     r   rR   _ExtendsBlock.__init__:  s    	r   r  )r   r   r   r   r   rR   r   r   r   r   r   r   9  s    S T r   r   c                   ^    \ rS rSrS\SSS\SS4S jrS	\\   S
\	\\
4   SS4S jrSS jrSrg)_IncludeBlocki>  r0   rP   rB   r   r!   Nc                 >    Xl         UR                   U l        X0l        g rW   )r0   template_namer   )rO   r0   rP   r   s       r   rR   _IncludeBlock.__init__?  s    	#[[	r   r1   rx   c                     Uc   eUR                  U R                  U R                  5      nUR                  R	                  X5        g rW   )r   r0   r  rE   rr   )rO   r1   rx   includeds       r   rr   _IncludeBlock.find_named_blocksD  s<     !!!;;tyy$*<*<=''=r   c                 6   UR                   c   eUR                   R                  U R                  U R                  5      nUR	                  X R
                  5         UR                  R                  R                  U5        S S S 5        g ! , (       d  f       g = frW   )	r1   r   r0   r  r   r   rE   r~   rl   )rO   r{   r	  s      r   rl   _IncludeBlock.generateK  sf    }}(((==%%dii1C1CD^^Hii0MM''/ 100s   &B


B)r   r0   r  r   )r   r   r   r   r   r   rR   r   r2   r   r   rr   rl   r   r   r   r   r  r  >  sU    S *; 3 4 
>z*>:>sK?O:P>	>0r   r  c                   L    \ rS rSrS\S\S\SS4S jrS\S   4S	 jr	SS
 jr
Srg)_ApplyBlockiR  methodr   r~   r!   Nc                 (    Xl         X l        X0l        g rW   )r  r   r~   )rO   r  r   r~   s       r   rR   _ApplyBlock.__init__S  s    		r   r   c                     U R                   4$ rW   r   r   s    r   r   _ApplyBlock.each_childX  r   r   c                    SUR                   -  nU=R                   S-  sl         UR                  SU-  U R                  5        UR                  5          UR                  SU R                  5        UR                  SU R                  5        U R                  R                  U5        UR                  SU R                  5        S S S 5        UR                  SU R                   SU S	3U R                  5        g ! , (       d  f       N<= f)
Nz_tt_apply%dr   z	def %s():r   r   r   z_tt_append(_tt_utf8((z()))))apply_counterr   r   r   r~   rl   r  )rO   r{   method_names      r   rl   _ApplyBlock.generate[  s    #f&:&::!+3TYY?]]_/;>		JIIv&DdiiP	 
 	"4;;-qUCTYY	
 _s   A0C::
D)r~   r   r  r   r   r   r   r   r   r   r   rR   r   r   rl   r   r   r   r   r  r  R  s9    s # U t 
HW- 
r   r  c                   L    \ rS rSrS\S\S\SS4S jrS\\   4S jr	SS	 jr
S
rg)_ControlBlockii  	statementr   r~   r!   Nc                 (    Xl         X l        X0l        g rW   )r  r   r~   )rO   r  r   r~   s       r   rR   _ControlBlock.__init__j  s    "		r   c                     U R                   4$ rW   r   r   s    r   r   _ControlBlock.each_childo  r   r   c                    UR                  SU R                  -  U R                  5        UR                  5          U R                  R                  U5        UR                  SU R                  5        S S S 5        g ! , (       d  f       g = f)N%s:pass)r   r  r   r   r~   rl   r   s     r   rl   _ControlBlock.generater  sX    %$..0$))<]]_IIv&fdii0 __s   8A;;
B	)r~   r   r  r   r  r   r   r   r  r  i  s8    # S  $ 
HUO 1r   r  c                   4    \ rS rSrS\S\SS4S jrS	S jrSrg)
_IntermediateControlBlockiz  r  r   r!   Nc                     Xl         X l        g rW   r  r   rO   r  r   s      r   rR   "_IntermediateControlBlock.__init__{      "	r   c                     UR                  SU R                  5        UR                  SU R                  -  U R                  UR                  5       S-
  5        g )Nr#  r"  r   )r   r   r  indent_sizer   s     r   rl   "_IntermediateControlBlock.generate  sD    &$)),%$..0$))V=O=O=QTU=UVr   r   r  r   	r   r   r   r   r   r   rR   rl   r   r   r   r   r&  r&  z  s"    # S T Wr   r&  c                   4    \ rS rSrS\S\SS4S jrS	S jrSrg)

_Statementi  r  r   r!   Nc                     Xl         X l        g rW   r(  r)  s      r   rR   _Statement.__init__  r+  r   c                 P    UR                  U R                  U R                  5        g rW   )r   r  r   r   s     r   rl   _Statement.generate  s    $..$))4r   r/  r   r0  r   r   r   r2  r2    s!    # S T 5r   r2  c            	       <    \ rS rSrS
S\S\S\SS4S jjrSS jrS	r	g)_Expressioni  
expressionr   rawr!   Nc                 (    Xl         X l        X0l        g rW   r9  r   r:  )rO   r9  r   r:  s       r   rR   _Expression.__init__  s    $	r   c                    UR                  SU R                  -  U R                  5        UR                  SU R                  5        UR                  SU R                  5        U R                  (       dJ  UR                  R
                  b3  UR                  SUR                  R
                  -  U R                  5        UR                  SU R                  5        g )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   r9  r   r:  current_templater4   r   s     r   rl   _Expression.generate  s    .4??:DIIFVII	
 	BDIINxxF33>>J 1F4K4K4V4VV		 	/;r   r<  )Fr   )
r   r   r   r   r   r   r   rR   rl   r   r   r   r   r8  r8    s(    3 c   
<r   r8  c                   8   ^  \ rS rSrS\S\SS4U 4S jjrSrU =r$ )_Modulei  r9  r   r!   Nc                 *   > [         TU ]  SU-   USS9  g )Nz_tt_modules.Tr:  )r   rR   )rO   r9  r   r   s      r   rR   _Module.__init__  s    *4dEr   r   )	r   r   r   r   r   r   rR   r   r   r   s   @r   rB  rB    s'    F3 Fc Fd F Fr   rB  c                   8    \ rS rSrS\S\S\SS4S jrS
S jrS	rg)_Texti  valuer   r5   r!   Nc                 (    Xl         X l        X0l        g rW   )rH  r   r5   )rO   rH  r   r5   s       r   rR   _Text.__init__  s    
	$r   c                     U R                   nSU;  a  [        U R                  U5      nU(       a4  UR                  S[        R
                  " U5      -  U R                  5        g g )Nz<pre>z_tt_append(%r))rH  r+   r5   r   r   rd   r   )rO   r{   rH  s      r   rl   _Text.generate  sP    

 %%doou=E.U1CCTYYO r   )r   rH  r5   r   r0  r   r   r   rG  rG    s)    %c % %# %$ %
	Pr   rG  c            	       L    \ rS rSrSr SS\S\\   S\SS4S jjrS\4S	 jr	S
r
g)r   i  zRaised 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.
Nmessagefilenamelinenor!   c                 (    Xl         X l        X0l        g rW   rN  rO  rP  )rO   rN  rO  rP  s       r   rR   ParseError.__init__  s      !r   c                 N    SU R                   U R                  U R                  4-  $ )Nz%s at %s:%drR  r   s    r   __str__ParseError.__str__  s     dmmT[[IIIr   )rO  rP  rN  ro   )r   r   r   r   r   r   r   r   rR   rU  r   r   r   r   r   r     sE     KL&.smDG	J Jr   r   c            
           \ rS rSrS\S\\\4   S\\	   S\
SS4
S jrS\4S	 jrSS jrS\
S\SS
4S jr SS\S\S\\   SS4S jjrSrg)rs   i  rE   rx   r1   r?  r!   Nc                 ^    Xl         X l        X0l        X@l        SU l        / U l        SU l        g ro   )rE   rx   r1   r?  r  include_stack_indent)rO   rE   rx   r1   r?  s        r   rR   _CodeWriter.__init__  s1     	( 0r   c                     U R                   $ rW   rZ  r   s    r   r-  _CodeWriter.indent_size  s    ||r   r   c                 ,   ^   " U 4S jS5      nU" 5       $ )Nc                   >   > \ rS rSrSU 4S jjrS\SS4U 4S jjrSrg)	$_CodeWriter.indent.<locals>.Indenteri  r!   c                 2   > T=R                   S-  sl         T$ )Nr   r]  r9   rO   s    r   	__enter__._CodeWriter.indent.<locals>.Indenter.__enter__  s    !r   argsNc                 T   > TR                   S:  d   eT=R                   S-  sl         g )Nr   r   r]  r9   rf  rO   s     r   __exit__-_CodeWriter.indent.<locals>.Indenter.__exit__  s#    ||a'''!r   r   r!   rs   r   r   r   r   rd  r	   ri  r   r   s   r   Indenterra    s     "3 "4 " "r   rm  r   )rO   rm  s   ` r   r   _CodeWriter.indent  s    	" 	" zr   rt   r   c                    ^  T R                   R                  T R                  U45        UT l         " U 4S jS5      nU" 5       $ )Nc                   >   > \ rS rSrSU 4S jjrS\SS4U 4S jjrSrg)	,_CodeWriter.include.<locals>.IncludeTemplatei  r!   c                    > T$ rW   r   rc  s    r   rd  6_CodeWriter.include.<locals>.IncludeTemplate.__enter__  s    r   rf  Nc                 J   > TR                   R                  5       S   Tl        g ro   )rY  popr?  rh  s     r   ri  5_CodeWriter.include.<locals>.IncludeTemplate.__exit__  s    (,(:(:(>(>(@(C%r   )r?  rk  rl  r   s   r   IncludeTemplaterq    s$    D3 D4 D Dr   rw  )rY  appendr?  )rO   rt   r   rw  s   `   r   r   _CodeWriter.include  sA    !!4#8#8$"?@ (	D 	D   r   line_numberr   c                 ^   Uc  U R                   nSU R                  R                  U4-  nU R                  (       aO  U R                   VVs/ s H  u  pVSUR                  U4-  PM     nnnUSSR	                  [        U5      5      -  -  n[        SU-  U-   U-   U R                  S9  g s  snnf )Nz	  # %s:%dz%s:%dz	 (via %s)z, z    )rE   )rZ  r?  r0   rY  r   reversedprintrE   )rO   r   rz  r   line_commenttmplrP  ry   s           r   r   _CodeWriter.write_line  s     >\\F"d&;&;&@&@+%NNDHDVDVDV.4499f--DV   K$))HY4G*HHHLfvo$|3$))D	s   B))rZ  r  r?  rE   rY  r1   rx   )r!   r   rW   )r   r   r   r   r   r   r   r   r   r2   r-   rR   r   r-  r   r   r   r   r   r   r   rs   rs     s     3+, $	
 # 
S 
! ! !8H ! DHEE&)E3;C=E	E Er   rs   c            	           \ rS rSrS\S\S\SS4S jrSS\S	\S
\\   S\4S jjrSS\\   S\4S jjr	S\4S jr
S\4S jrS\\\4   S\4S jrS\4S jrS\SS4S jrSrg)rB   i  r0   r    r5   r!   Nc                 D    Xl         X l        X0l        SU l        SU l        g )Nr   r   )r0   r    r5   r   pos)rO   r0   r    r5   s       r   rR   _TemplateReader.__init__  s    		$	r   needlestartendc                     US:  d   U5       eU R                   nX$-  nUc  U R                  R                  X5      nO'X4-  nX2:  d   eU R                  R                  XU5      nUS:w  a  XT-  nU$ )Nr   )r  r    find)rO   r  r  r  r  indexs         r   r  _TemplateReader.find  sr    z 5 zhh;IINN61EJC<<IINN6#6EB;LEr   countc                     Uc"  [        U R                  5      U R                  -
  nU R                  U-   nU =R                  U R                  R	                  SU R                  U5      -  sl        U R                  U R                  U nX l        U$ )Nr&   )r   r    r  r   r  )rO   r  newposss       r   consume_TemplateReader.consume#  sl    =		NTXX-EE!		TYY__T488V<<	IIdhh(r   c                 F    [        U R                  5      U R                  -
  $ rW   )r   r    r  r   s    r   	remaining_TemplateReader.remaining,  s    499~((r   c                 "    U R                  5       $ rW   )r  r   s    r   __len___TemplateReader.__len__/  s    ~~r   keyc                 \   [        U[        5      (       ag  [        U 5      nUR                  U5      u  p4nUc  U R                  nOX0R                  -  nUb  X@R                  -  nU R
                  [        X4U5         $ US:  a  U R
                  U   $ U R
                  U R                  U-      $ ro   )r?   slicer   indicesr  r    )rO   r  sizer  stopsteps         r   __getitem___TemplateReader.__getitem__2  s    c5!!t9D #D 1E}! 99U55661W99S>!99TXX^,,r   c                 4    U R                   U R                  S  $ rW   )r    r  r   s    r   rU  _TemplateReader.__str__B  s    yy$$r   msgc                 B    [        XR                  U R                  5      erW   )r   r0   r   )rO   r  s     r   raise_parse_error!_TemplateReader.raise_parse_errorE  s    ii33r   )r   r0   r  r    r5   )r   NrW   )r   r   r   r   r   rR   r   r   r  r  r  r  r
   r  r  rU  r  r   r   r   r   rB   rB     s    S    3 s Xc] c Xc] c )3 )   -uS%Z0 -S - % %4S 4T 4r   rB   rG   c           	          U R                  5       nS[        [        [        U5      S-   5      5      -  nSR                  [	        U5       VVs/ s H  u  p4X#S-   U4-  PM     snn5      $ s  snnf )Nz%%%dd  %%s
r   r7   )
splitlinesr   reprr   	enumerate)rG   linesformatir   s        r   rL   rL   I  s_    OOEc$s5zA~"677F77Ie<LM<LyF!eT]*<LMNNMs   A*
rP   rt   in_blockin_loopc                 ^   [        / 5      n Sn U R                  SU5      nUS:X  d  US-   U R                  5       :X  ae  U(       a  U R                  SU-  5        UR                  R                  [        U R                  5       U R                  U R                  5      5        U$ XS-      S;  a  US-  nM  US-   U R                  5       :  a  XS-      S:X  a  XS-      S:X  a  US-  nM   US:  aJ  U R                  U5      nUR                  R                  [        X`R                  U R                  5      5        U R                  S5      nU R                  nU R                  5       (       aL  U S   S	:X  aC  U R                  S5        UR                  R                  [        XxU R                  5      5        GM  US
:X  a[  U R                  S5      n	U	S:X  a  U R                  S5        U R                  U	5      R                  5       n
U R                  S5        GM  US:X  a  U R                  S5      n	U	S:X  a  U R                  S5        U R                  U	5      R                  5       n
U R                  S5        U
(       d  U R                  S5        UR                  R                  [        X5      5        GM  US:X  d   U5       eU R                  S5      n	U	S:X  a  U R                  S5        U R                  U	5      R                  5       n
U R                  S5        U
(       d  U R                  S5        U
R                  S5      u  pnUR                  5       n1 SkS1S1S1S.nUR                  U5      nUba  U(       d  U R                  U SU S35        X/;  a  U R                  U SU S35        UR                  R                  [        X5      5        GM  US:X  a  U(       d  U R                  S5        U$ US;   Ga  US :X  a  GM  US!:X  aE  UR                  S"5      R                  S#5      nU(       d  U R                  S$5        [        U5      nGOUS%;   a$  U(       d  U R                  S&5        [!        X5      nOUS':X  aE  UR                  S"5      R                  S#5      nU(       d  U R                  S(5        [#        XU5      nOUS):X  a$  U(       d  U R                  S*5        [!        X5      nOvUS+:X  a"  UR                  5       nUS,:X  a  S nUUl        GM  US-:X  a&  UR                  5       n['        US.5        UU l	        GM;  US/:X  a  [        XSS09nOUS1:X  a  [)        X5      nUR                  R                  W5        GM{  US2;   a  US3;   a  [+        XX5      nO US4:X  a  [+        XUS 5      nO[+        XX5      nUS4:X  a%  U(       d  U R                  S55        [-        XU5      nO8US6:X  a&  U(       d  U R                  S75        [/        UUX5      nO[1        XU5      nUR                  R                  U5        GM5  US8;   aQ  U(       d#  U R                  S9R3                  US:S;15      5        UR                  R                  [!        X5      5        GM  U R                  S<U-  5        GM  )=NTr   {r  r   z Missing {%% end %%} block for %s)r  %#   !z{#z#}zMissing end comment #}z{{z}}zMissing end expression }}zEmpty expressionz{%z%}zMissing end block %}zEmpty block tag ({% %})r%   >   iffortrywhiler  r  )elseelifexceptfinallyz	 outside z blockz block cannot be attached to r  zExtra {% end %} block)
extendsr   setimportfromcommentr4   r5   r:  moduler  r  "'zextends missing file path)r  r  zimport missing statementr   zinclude missing file pathr  zset missing statementr4   Noner5   r7   r:  rD  r  )applyr   r  r  r  r  )r  r  r  zapply missing method namer   zblock missing name)breakcontinuez{} outside {} blockr  r  zunknown operator: %r)r   r  r  r  r   rx  rG  r  r   r5   stripr8  	partitiongetr&  r   r2  r  r4   r+   rB  rD   r  r   r  r  )rP   rt   r  r  r~   curlyconsstart_bracer   r  contentsoperatorspacesuffixintermediate_blocksallowed_parentsr   fnr   
block_bodys                       r   rD   rD   O  s)    b>D
KKU+E{eai6+;+;+==,,:XE ""&..*FKK9J9JK  ai 7

 	F,,..19%,19%,
 19>>%(DKKuT;;8I8IJKnnQ'{{ &)s"2NN1KKu[8I8IJK $++d#Cby(()AB~~c*002HNN1 $++d#Cby(()DE~~c*002HNN1(();<KK{8:; d"/K/"kk$"9$$%;<>>#&,,.q$$%>?"*"4"4S"9 2Fgw	
 .11(;&((H:Y>Ov)VW.((j =hZvN KK8HI (()@AK 
 
 9$9$c*005,,-HI%f-//,,-GH"82Y&c*005,,-HI%fd;U",,-DE"60\)\\^<B&(#\)||~!$+$(!U"#Fd;X%-KKu%HH++#FhI
W$ $FhE
#FhH
7",,-HI#F*=W$,,-AB#FJG%hjAKKu%..(()00E7;KL KKz(9: $$%;h%FG r   )NN):r   r_   ior   ri   os.pathr   r   r(   r   tornador   tornado.logr   tornado.utilr   r   r   rg   r	   r
   r   r   r   r   r   r   TYPE_CHECKINGr   r   r@   r   r=   r   r+   r-   r2   r   r   r   rC   r   r   r   r  r  r  r&  r2  r8  rB  rG  r*   r   rs   rB   rL   rD   r   r   r   <module>r     s   un      	    : : O O O 	,$ 	 	 
=C =s =s =2I IX:$ :$zZ 8A A,: :E $	 	<% <,E 
0E 0(
% 
.1E 1"W W5 5<% <.Fk F
PE P$J J.7E 7Et94 94xOs Os O #!	FHFHFH smFH c]	FH
 FHr   