
    +hx                     :   d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ d	Zd
dhZddhj                  e      Zddddddddd e       f
dZ G d d      Z G d d      Z G d d      Z ej"                  d      Zd Z G d d      Zy)zVprovides functionality for rendering a parsetree constructing into module
source code.    N)ast)
exceptions)filters)	parsetree)util)PythonPrinter
   	UNDEFINEDSTOP_RENDERINGcontextloopTFc                     t        j                         }t        |      }t        |t	        |||||||||	|
|      |        |j                         S )zYGenerate module source code given a parsetree node,
    uri, and optional source filename)r   FastEncodingBufferr   _GenerateRenderMethod_CompileContextgetvalue)nodeurifilenamedefault_filtersbuffer_filtersimportsfuture_importssource_encodinggenerate_magic_commentstrict_undefinedenable_loopreserved_namesbufprinters                 ?/var/www/html/venv/lib/python3.12/site-packages/mako/codegen.pycompiler"      sc    " 
!
!
#CC G"	
 	" <<>    c                       e Zd Zd Zy)r   c                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        y N)r   r   r   r   r   r   r   r   r   r   r   )selfr   r   r   r   r   r   r   r   r   r   r   s               r!   __init__z_CompileContext.__init__H   sY      .,,.&<# 0&,r#   N)__name__
__module____qualname__r(    r#   r!   r   r   G   s    -r#   r   c                       e Zd ZdZd Zd Zed        Zd Zd Z	d Z
d Zd	 ZddZd Zd Z	 ddZ	 	 ddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy
)r   zZA template visitor object which generates the
    full module source for a template.

    c                    || _         || _        || _        d g| _        t	        |t
        j                  t
        j                  f      | _        | j                  rd|j                  z  }|j                         }t        |j                  j                        dkD  }t        |j                  j!                  dd            }t        |j                  j!                  dd            }d }	d }
|j"                  r|j$                  s|dgz  }n| j'                         }	| j                  j(                  }
d}|
|
j*                  j                         }|
j*                  j,                  s|dgz  }t        |
j                  j!                  dd            }| j                  j.                  xs% t        |
j                  j!                  dd            | j                  _        ndg}d	}d	x}}|d
g}nd
g|z   D cg c]  }| }}| j1                  |
xs ||||||       |	|	D ]  }t3        |||        | j                  s| j5                          y y c c}w )Nz	render_%sr   bufferedFalsecached
**pageargsrender_bodyr   Fr   )r    compilerr   identifier_stack
isinstancer   DefTagBlockTagin_deffuncnameget_argument_expressionslenfilter_argsargseval
attributesgetis_blockis_anonymouswrite_toplevelpagetag	body_declkwargsr   write_render_callabler   write_metadata_struct)r'   r    r4   r   namer>   filteredr/   r1   defsrE   as               r!   r(   z_GenerateRenderMethod.__init__j   s%    	!% 	(8(8):L:L'MN;;.D002D4++001A5HDOO//
GDEH$//--h@AFDG}}T%6%6&&&(Dmm++G D"((AAC((//\N*Dg0044XwGH,0MM,E,E -&&**='BJ) %~"''Hx<;D ){T12!A2D2""OtT48V	
  ?%gx>? {{&&(  3s   0	I	c                    t        | j                  j                        | j                  j                  | j                  j                  <   | j                  j
                  | j                  j                  | j                  j                  | j                  j                  d}| j                  j                  ddt        j                  |      d       y )N)r   r   r   line_mapz"""__M_BEGIN_METADATAz__M_END_METADATA
""")maxr    
source_maplinenor4   r   r   r   
writelinesjsondumps)r'   structs     r!   rI   z+_GenerateRenderMethod.write_metadata_struct   s    7:LL##8
 3 34 ..==$$#}}<<//	
 	 JJv&		
r#   c                      | j                   d   S )N)r5   r'   s    r!   identifiersz!_GenerateRenderMethod.identifiers   s    $$R((r#   c                 8
    g i g d j                   _         G  fdd      } |       } j                  j                  D ]  }|j	                  |         j                   _        t               }D ]!  }|j                  |j                               }# t         j                         }||_
         j                   j                  rH j                   j                  r2 j                  j                  d j                   j                  z          j                   j                  rA j                  j                  ddj!                   j                   j                                j                  j                  d        j                  j                  d        j                  j                  d	        j                  j                  d
        j                  j                  d        j                  j                  dt"        z          j                  j                  dt%        j$                         z          j                  j                  d j                   j&                  z          j                  j                  d j                   j(                  z          j                  j                  d j                   j*                  z          j                  j                  d j                   j                  z          j                   j,                  r[d} j                   j,                  D ]%  }||dz   z  } j                  j                  |       ' t/        j0                  |dddd      }nd}|j3                   j                        }	|j4                  }
|
j                  |	j4                        |_        |j                  j7                  t8               |r%|j                  j7                  |j                         | j                   _         j                  j                  d|	j4                  j=                         D cg c]  }|j>                   c}z          j                  jA                  d       tC              r jE                         tC              r& jG                          jI                  d          ntC              r jG                         tK        |	j4                  j=                               S c c}w )zxTraverse a template structure for module-level directives and
        generate the start of module-level code.

        Nc                   6    e Zd Z fdZfdZfdZfdZy):_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevelc                 (    j                  |       y r&   )append)sr   inherits     r!   visitInheritTagzJ_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitInheritTag   s    t$r#   c                 $    ||j                   <   y r&   rJ   )ra   r   
namespacess     r!   visitNamespaceTagzL_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitNamespaceTag   s    (,
499%r#   c                 (    |j                   _        y r&   )r4   rE   )ra   r   r'   s     r!   visitPageTagzG_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitPageTag   s    (,%r#   c                 B    |j                   rj                  |       y y r&   )ismoduler`   )ra   r   module_codes     r!   	visitCodezD_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitCode   s    ==&&t, !r#   N)r)   r*   r+   rc   rg   ri   rm   )rb   rl   rf   r'   s   r!   FindTopLevelr^      s    %---r#   rn   z# -*- coding:%s -*-zfrom __future__ import , z(from mako import runtime, filters, cachezUNDEFINED = runtime.UNDEFINEDz'STOP_RENDERING = runtime.STOP_RENDERINGz__M_dict_builtin = dictz__M_locals_builtin = localsz_magic_number = %rz_modified_time = %rz_enable_loop = %rz_template_filename = %rz_template_uri = %rz_source_encoding = %r 
r   ztemplate defined imports)sourcerS   posr   z_exports = %r   rY   )&r4   rE   r   nodesaccept_visitorrf   setuniondeclared_identifiers_Identifiersdeclaredr   r   r    	writeliner   joinMAGIC_NUMBERtimer   r   r   r   r   
PythonCodebranchtopleveldefsupdateTOPLEVEL_DECLAREDr[   valuesrJ   write_blanksr<   write_module_codewrite_namespaceswrite_inheritlist)r'   rn   fnmodule_identmodule_identifiersr   impimpcodemain_identifiersmitrb   rl   rf   s   `          @@@r!   rD   z$_GenerateRenderMethod.write_toplevel   s   
 
 $	- 	- N 	 AQ	  $. u 	HA'--a.D.D.FGL	H *$--8&2# MM00--LL""%(E(EE ==''LL""99T]]99:= 	IJ>?HI89<=3lBC4tyy{BC2T]]5N5NNO%(>(>>	
 	3dmm6G6GGH#dmm&C&CC	
 ==  C}},, ,sTz!&&s+, nn3G G-44TYY? --*-))))+
' 	##**+<=''..w/K/KL$6!/<<CCEF!qvvFG	
 	!!!${"";/w<!!*-wr{+_!!*-$1188:;; Gs   T
c                 f   | j                   r,|j                  }|r| j                  j                  d|z         | j                  j	                  |j
                         | j                  j                  d|ddj                  |      ddd       |s|s|r| j                  j                  d       | j                  j                  | j                  j                  j                  | j                               | j                   r| j                  j                  r,d	|v r(| j                  d
   j                  j!                  d       | j                   st#        | j                  j$                        dkD  s"t#        | j                  j                        dkD  rT| j                  j                  ddj                  | j                  j                  D cg c]	  }|d| c}      z         | j'                  | j                  d       | j                  j(                  D ]  }	|	j+                  |         | j-                  | j                  |||       | j                  j                  d       | j                  j/                  d       |r"| j1                  ||||| j                  d       yyc c}w )znwrite a top-level render callable.

        this could be the main render() method or that of a top-level def.z@runtime._decorate_toplevel(%s)def (,):/__M_caller = context.caller_stack._push_frame()try:context._push_buffer()r2   rY   pageargsr   z!__M_locals = __M_dict_builtin(%s)=T)toplevelNrt   )r9   	decoratorr    r|   start_sourcerS   rT   r}   r5   r`   r4   r[   r   r   rB   argument_declaredaddr<   locally_assignedwrite_variable_declaresru   rv   write_def_finishr   write_cache_decorator)
r'   r   rJ   r>   r/   rK   r1   r   xr   s
             r!   rH   z+_GenerateRenderMethod.write_render_callable  s1    ;;I&&5	A 	!!$++.!388D>2=		
 x6LL""#;<$$MM%%,,TYY7	
 tyy11|t7K!!"%77;;JG{{  112Q64##556:LL""3(( "&!1!1!C!C $%a( 	$$T%5%5$E 	#AT"	# 	dii8VDt$!!!$&&dD(D,<,<t '  s   J.c                 t    |D ]3  }| j                   j                  |j                  |j                         5 y)zewrite module-level template code, i.e. that which
        is enclosed in <%! %> tags in the template.starting_linenoN)r    write_indented_blocktextrS   )r'   rl   r   s      r!   r   z'_GenerateRenderMethod.write_module_codeV  s4      	PALL--affahh-O	Pr#   c                 `    | j                   j                  ddd|j                  d   z  d       y)z:write the module-level inheritance-determination callable.z%def _mako_inherit(template, context):"_mako_generate_namespaces(context)z8return runtime._inherit_from(context, %s, _template_uri)fileN)r    rT   parsed_attributesr'   r   s     r!   r   z#_GenerateRenderMethod.write_inherit\  s5     	30F%%f-/	
r#   c                 x     j                   j                  dddddddd        j                   j                  d       |j                         D ]  }d|j                  v rd	 j
                  _         j                   j                  |j                         t        |j                        r҉ j                   j                  d
       g  j
                  j                  j                  |      d	 _         G  fdd      } |       }|j                  D ]  }|j                  |         j                   j                  ddj                        z          j                   j                  d       d _        d}nd}d|j                   v rJ j                   j                  d|j"                  d|j                   j%                  dd      d|d       nd|j                   v rJ j                   j                  d|j"                  d|d|j                   j%                  dd      d       n, j                   j                  d|j"                  d|d       t'        |j                  j%                  dd            r( j                   j                  d |j"                  z          j                   j                  d!t)        |j"                        z          j                   j+                  d"        t        |      s j                   j                  d#        j                   j                  d       y)$z5write the module-level namespace-generating callable.z'def _mako_get_namespace(context, name):r   z+return context.namespaces[(__name__, name)]except KeyError:r   Nz'def _mako_generate_namespaces(context):importTzdef make_namespace():c                   (    e Zd Zd Zd Z fdZy)<_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitorc                 &    | j                  |       y r&   visitDefOrBasera   r   s     r!   visitDefTagzH_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitDefTag      ((.r#   c                 &    | j                  |       y r&   r   r   s     r!   visitBlockTagzJ_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitBlockTag  r   r#   c                     |j                   r t        j                  	 di |j                  j	                  |d       j                  |j                         y )NFnested)z.Can't put anonymous blocks inside <%namespace>)rC   r   CompileExceptionexception_kwargswrite_inline_defr`   r:   )ra   r   exportr[   r'   s     r!   r   zK_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitDefOrBase  s[    ,,","="=!/# #'"7"7# 
 --dK-Ndmm4r#   Nr)   r*   r+   r   r   r   )r   r[   r'   s   r!   NSDefVisitorr     s    //5r#   r   return [%s]r   Fzmake_namespace()Noner   zns = runtime.TemplateNamespace(z3, context._clean_inheritance_tokens(), templateuri=z, callables=z,  calling_uri=_template_uri)modulezns = runtime.ModuleNamespace(z1, context._clean_inheritance_tokens(), callables=z$, calling_uri=_template_uri, module=)zns = runtime.Namespace(z, calling_uri=_template_uri)inheritabler0   zcontext['self'].%s = nsz'context.namespaces[(__name__, %s)] = ns   pass)r    rT   r|   r   r@   r4   has_ns_importsr   rS   r<   ru   r[   r   r9   rv   r}   r   rJ   rA   r?   reprr   )	r'   rf   r   r   visr   callable_namer   r[   s	   `      @@r!   r   z&_GenerateRenderMethod.write_namespacesg  s   5909		
 	HI%%' J	)D4??*/3,LL%%dkk24::&&'>?"mm77>>tD"5 5" #n *A$$S)*&&}8H'IJ&&t,# 2 &///&& 		..2266B%
 T333&& 		%..228VD
 && yy-1 DOO''w?@&&'@DII'NOLL""9DOK LL%%a(UJ	)V :LL""6*t$r#   Nc                 l   |j                   D ci c]  }|j                  | }}t               }|j                  |j                        }|j                  |j
                  j                         D cg c]  }|j                   c}      }|j                  |j                        }|j                  |j                        }| j                  j                  rd|v }|j                  d       nd}||j                  |      }|rt        | j                  dd      r| j                  j!                  d       d| j                  _        | j                  j$                  j'                         D ]W  \  }}	d|	j(                  v s| j                  j!                  d|d	t+        j,                  d
|	j(                  d         d       Y |r| j                  j!                  d       |D ]  }||v r}||   }
|
j.                  r4|
j0                  s| j3                  |
|       8| j5                  |
|d       M|
j7                         r| j3                  |
|       p| j5                  |
|d       || j                  j$                  v r"| j                  j!                  |d|d       t        | j                  dd      rr| j                  j8                  r6| j                  j;                  |d|dd|z  d|d|ddd|z  dd       "| j                  j!                  |d|d|d       H| j                  j8                  r*| j                  j;                  d|d|ddd|z  d       | j                  j!                  |d|d        | j                  j!                  d       yc c}w c c}w )a  write variable declarations at the top of a function.

        the variable declarations are in the form of callable
        definitions for defs and/or name lookup within the
        function's context argument. the names declared are based
        on the names that are referenced in the function body,
        which don't otherwise have any explicit assignment
        operation. names that are assigned within the body are
        assumed to be locally-scoped variables and are not
        separately declared.

        for def callable definitions, if the def is a top-level
        callable then a 'stub' callable is generated which wraps
        the current Context into a closure. if the def is not
        top-level, it is fully rendered as a local closure.

        r   FNr   z_import_ns = {}Tr   z_mako_get_namespace(context, z)._populate(_import_ns, z\s*,\s*r   z%loop = __M_loop = runtime.LoopStack()r   z  = _mako_get_namespace(context, z = _import_ns.get(z, UNDEFINED)zif %s is UNDEFINED:r   z = context[]r   z&raise NameError("'%s' is not defined")z, context.get(z, UNDEFINED))z = context.get(z__M_writer = context.writer())rL   r:   rw   rx   
undeclaredclosuredefsr   
differencer   locally_declaredr4   r   discardintersectiongetattrr    r|   has_importsrf   itemsr@   resplitrB   rC   write_def_declr   is_rootr   rT   )r'   r[   r   limitccomp_identsto_writehas_loopidentnscomps              r!   r   z-_GenerateRenderMethod.write_variable_declares  s@   ( /:.>.>?qzz1}??5 >>+"8"89 >>!,!8!8!?!?!ABAQZZB
 &&{'D'DE &&{'C'CD==$$)HV$H ,,U3H/?GLL""#45(,DMM%!]]55;;= 		rr}},LL** "HHZx1HI		 LL""#JK 2	E#"5)==,,++D+>--dK-M||~++D+>--dK-M$--222&&?DeL 4==*:EB}}55//$e-1E9"27?.FN  
 ..  %eU4 }}55//"27?.FN  ..AFNa2	h 	>?Q @ Cs   N,1N1c                 D   |j                   }|j                         }|j                  d      }| j                  sWt        | j                  j
                        dkD  s"t        | j                  j                        dkD  r|j                  dd       n|j                  dd       | j                  j                  d|ddj                  |      d	       | j                  j                  d
|ddj                  |      d       | j                  j                  d       y)z>write a locally-available callable referencing a top-level defTas_callr   zcontext._locals(__M_locals)r   r   r   r   r   zreturn render_r   N)r:   r;   r9   r<   r[   r   r   insertr    r|   r}   )r'   r   r[   r:   	namedeclsnameargss         r!   r   z$_GenerateRenderMethod.write_def_declB  s    ==113	000>{{  112Q64##556:OOA<=OOAy)#((9:MNO&.0BC	
 	t$r#   c           	         |j                         }|j                  }|r| j                  j                  d|z         | j                  j                  d|j                  ddj                  |      d       t        |j                  j                        dkD  }t        |j                  j                  dd            }t        |j                  j                  d	d            }| j                  j                  d
d       |s|s|r| j                  j                  d       |j                  ||      }| j                  |       | j                  j!                  |       |j"                  D ]  }	|	j%                  |         | j                  j'                          | j)                  ||||       | j                  j                  d       |r#| j+                  ||j                  |d|dd       yy)z?write a locally-available def callable inside an enclosing def.z&@runtime._decorate_inline(context, %s)r   r   r   r   r   r/   r0   r1   r   r   r   r   NFT)inliner   )r;   r   r    r|   r:   r}   r<   r=   r>   r?   r@   rA   rT   r   r   r5   r`   ru   rv   popr   r   )
r'   r   r[   r   r   r   rK   r/   r1   r   s
             r!   r   z&_GenerateRenderMethod.write_inline_defU  s    113	NN	LL""89D 	!]]CHHY,?@	
 t'',,-1++J@Adoo))(G<==	

 x6LL##$<=!((f(=$$[1$$[1 	#AT"	#!!#dHh?t$&& '  r#   c                    |s>|s<|s:| j                   j                  d       |r| j                   j                  ddd       |s|s|r|s|r| j                   j                  dd       n| j                   j                  dd       |r| j                   j                  d       d}|r'| j                  |j                  j
                  |d      }| j                   j                  d       |r)|s'| j                  | j                  j                  |d      }|s|r| j                   j                  d	|z         y| j                   j                  d
|z  d       yy)aJ  write the end section of a rendering function, either outermost or
        inline.

        this takes into account if the rendering function was filtered,
        buffered, etc.  and closes the corresponding try: block if any, and
        writes code to retrieve captured content, apply filters, send proper
        return value.	return ''finally:z!context.caller_stack._pop_frame()Nz__M_buf = context._pop_buffer()6__M_buf, __M_writer = context._pop_buffer_and_writer()__M_buf.getvalue()Fz	return %s__M_writer(%s))r    r|   rT   create_filter_callabler=   r>   r4   r   )r'   r   r/   rK   r1   	callstackra   s          r!   r   z&_GenerateRenderMethod.write_def_finish  s5    xLL"";/'' CT x66
 '' A ''L
 &&'JK$A//$$))1e LL""4(//MM00!U 6&&{Q7''(81(<kJ? $*r#   c                       j                   j                  d|d|       j                  j                  dt	        |            }i }	 j
                  j                  8|	j                   fd j
                  j                  j                  D               |	j                  fdj                  D               d|	v rt        t        |	d               |	d<    j                   j                  d|d	d
j                  |      d       |D 
cg c]#  }
d|
v rd|
j                  d      d   fdz  z  n|
% }}
 j                  ||j                                |rd|d|d	d
j                  |      ddj                  |	j                         D cg c]  \  }}|d|d c}}      d|d} j                   j
                  j                   |d      } j                   j#                  d|z   d       y j                   j#                  d|d|d	d
j                  |      ddj                  |	j                         D cg c]  \  }}|d|d c}}      d|ddd       yc c}
w c c}}w c c}}w )zhwrite a post-function decorator to replace a rendering
        callable with a cached version of itself.__M_z = 	cache_keyNc              3      K   | ]B  }|j                  d       r/|dk7  r*|dd j                  j                  j                  |   f D ywcache_r      N)
startswithr4   rE   r   ).0par'   s     r!   	<genexpr>z>_GenerateRenderMethod.write_cache_decorator.<locals>.<genexpr>  sL      ==*r[/@ AB..@@DEs   AAc              3   r   K   | ].  }|j                  d       r|dk7  r|dd j                  |   f 0 ywr   )r  r   )r  r  node_or_pagetags     r!   r  z>_GenerateRenderMethod.write_cache_decorator.<locals>.<genexpr>  sB      
}}X&2+< V_66r:;
s   47timeoutr   r   r   r   r   z%s=%sr   rt   )r   r   z.context.get('local').cache._ctx_get_or_create(z, lambda:__M_z),  context, rp   ro   z__M_defname=r   Fzreturn z9__M_writer(context.get('local').cache._ctx_get_or_create(z), context, z))r   )r    r|   r   rA   r   r4   rE   r   intr?   r}   r   r   undeclared_identifiersr   r   r   rT   )r'   r  rJ   r>   r/   r[   r   r   cachekey
cache_argsrM   	pass_argskvra   s   ``             r!   r   z+_GenerateRenderMethod.write_cache_decorator  sQ    	d;<"4488d
 
==  , --//AA 
 	 
%77
 	

 
"$'Z	-B(C$DJy!chhtnEF LP
FG#(GQ)A-.A
	 
 	$$!88: 	% 	

  HHY'GG8B8H8H8JK1a+K   ++,,aA LL##IM48LL##
 HHY'GG8B8H8H8JK1a+K  =
& L( Ls   (I/I4I:c                    d }d|vrx|rv| j                   j                  r-| j                   j                  j                  j                  |z   }| j                   j                  rd|vr| j                   j                  |z   }|D ]W  }|dk(  r	t        j                  d|      }|r#|j                  dd      \  }} ||      }	|	|z   }n ||      }|J |d|d}Y |S )zwrite a filter-applying expression based on the filters
        present in the given filter names, adjusting for the global
        'default' filter aliases as needed.c                 x    t        j                  d|       rd| z   S t        j                  j	                  | |       S )Nz
decode\..+zfilters.)r   matchr   DEFAULT_ESCAPESrA   re   s    r!   locate_encodezC_GenerateRenderMethod.create_filter_callable.<locals>.locate_encode  s4    xxt,!D((..224>>r#   r   z(.+?)(\(.*\))r   rt   r   r   )r4   rE   r=   r>   r   r   r  group)
r'   r>   targetis_expressionr  emr   fargsr   s
             r!   r   z,_GenerateRenderMethod.create_filter_callable	  s    
	? d?==((==00<<AADHD==00S_==884?D 	,ACx)1-A wwq!}u!%(I!!$}$}!"F+F	, r#   c                 >   | j                   j                  |j                         t        |j                        sh| j
                  j                  3t        | j
                  j                  j                  j                        st        | j
                  j                        rS| j                  |j                  j                  d|j                  z  d      }| j                   j                  d|z         y | j                   j                  d|j                  z         y )Nz%sTr   )r    r   rS   r<   escapesr4   rE   r=   r>   r   r   escapes_coder   r|   )r'   r   ra   s      r!   visitExpressionz%_GenerateRenderMethod.visitExpression)  s    !!$++.%%1--99>>?4==001++!!&&tyy(8$A LL""#3a#78LL""#3dii#?@r#   c                    j                   rz| j                  j                  d        j                  rR| j                  j                  d       | j                  j                  d       | j                  j                  d        y y | j                  j	                  j
                         | j                  j                  r&j                  dk(  rt        | j                        }nj                  }| j                  j                  |       j                         fd}r-t        d D              rt        fdD              s |       r| j                  j                  d       y y )Nr   zloop = __M_loop._exit()forc                      D ]:  } t        | t        j                        rt        | t        j                        r y y y )NTFr6   r   CommentControlLine)r   childrens    r!   _search_for_control_linezH_GenerateRenderMethod.visitControlLine.<locals>._search_for_control_lineP  s;    ! !A!!Y%6%67 #Ay'<'<=# !r#   c              3   p   K   | ].  }t        |t        j                  t        j                  f       0 y wr&   r!  )r  r   s     r!   r  z9_GenerateRenderMethod.visitControlLine.<locals>.<genexpr>Z  s0       q9#4#4i6K6K"LMs   46c              3      K   | ]G  }t        |t        j                        r+j                  |j                        xs |j
                   I y wr&   )r6   r   r#  
is_ternarykeywordisend)r  r   r   s     r!   r  z9_GenerateRenderMethod.visitControlLine.<locals>.<genexpr>^  sB      !!Y%:%:; __QYY/:177:s   AAr   )r*  r    r|   has_loop_contextr   rS   r4   r   r)  mangle_mako_loopr   get_childrenall)r'   r   r   r%  r$  s    `  @r!   visitControlLinez&_GenerateRenderMethod.visitControlLine:  s   ::LL""4($$&&z2&&'@A&&t, %
 LL%%dkk2}}((T\\U-B'dll;yyLL""4(((*H!  %   % 
 ,-&&v. .r#   c                     | j                   j                  |j                         | j                   j                  dt	        |j
                        z         y )Nr   )r    r   rS   r|   r   contentr   s     r!   	visitTextz_GenerateRenderMethod.visitTextg  s9    !!$++./$t||2DDEr#   c           
      Z   t        |j                  j                        dkD  }|r| j                  j	                  dd       |j
                  D ]  }|j                  |         |rG| j                  j	                  ddd| j                  |j                  j                  dd      z  d        y y )	Nr   z#__M_writer = context._push_writer()r   r   r   r   r   F)r<   r=   r>   r    rT   ru   rv   r   )r'   r   rK   r   s       r!   visitTextTagz"_GenerateRenderMethod.visitTextTagk  s    t'',,-1LL##5v  	#AT"	#LL##H --$$))+?  r#   c                    |j                   s| j                  j                  |j                  |j                         | j
                  st        | j                  j                        dkD  rn| j                  j                  d       | j                  j                  ddj                  |j                         D cg c]  }t        |       c}      z         y y y y c c}w )Nr   r   z0__M_locals_builtin_stored = __M_locals_builtin()z__M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key]) for __M_key in [%s] if __M_key in __M_locals_builtin_stored]))r   )rk   r    r   r   rS   r9   r<   r[   r   r|   r}   ry   r   )r'   r   r   s      r!   rm   z_GenerateRenderMethod.visitCode~  s    }}LL--		4;; .  ;;3t'7'7'H'H#IA#M
 &&F &&G hh1J1J1LMAQMNO $N; "  Ns   :Cc                 >   | j                   j                  |j                         |j                  j	                  d      }|r0| j                   j                  d|j                  d   d|d       y | j                   j                  d|j                  d   z         y )Nr>   zruntime._include_file(context, r   z, _template_uri, r   z1runtime._include_file(context, %s, _template_uri))r    r   rS   r@   rA   r|   r   )r'   r   r>   s      r!   visitIncludeTagz%_GenerateRenderMethod.visitIncludeTag  s    !!$++.""6*LL""))&149
 LL""C))&13r#   c                      y r&   r,   r   s     r!   rg   z'_GenerateRenderMethod.visitNamespaceTag      r#   c                      y r&   r,   r   s     r!   r   z!_GenerateRenderMethod.visitDefTag  r9  r#   c                    |j                   r)| j                  j                  d|j                  z         y |j	                  d      }|dgz  }| j                  j                  d|j                  z         | j                  j                  d|j                  ddj                  |      d	       | j                  j                  d
       y )Nz%s()Tr   r2   zOif 'parent' not in context._data or not hasattr(context._data['parent'], '%s'):zcontext['self'].r   r   r   rq   )rC   r    r|   r:   r;   r}   )r'   r   r   s      r!   r   z#_GenerateRenderMethod.visitBlockTag  s    LL""6DMM#9:44T4BH&HLL"">@DN LL"",0MM388H;MN LL""4(r#   c                 &    | j                  |       y r&   visitCallTagr   s     r!   visitCallNamespaceTagz+_GenerateRenderMethod.visitCallNamespaceTag  s     	$r#   c                    	  j                   j                  d       dg	 j                  j                  |d      j                  |d      j	                  d        j
                  j                          G 	 fdd      } |       }|j                  D ]  }|j                  |         j
                  j                          |j                  j                         } j                   j                  d	d
j                  |      z         d}|r j                   j                  dd        j                          j
                  j                         |j                  D ]  }|j                            j
                  j                           j                  ||ddd        j                   j                  d dd
j                  	      z  d         j                   j                  dd        j                   j!                  |j"                          j                   j                  d j%                  g |j&                  d      z  ddd        y )Nzdef ccall(caller):bodyTr   Fcallerc                   *    e Zd Zd Zd Z fdZy)6_GenerateRenderMethod.visitCallTag.<locals>.DefVisitorc                 &    | j                  |       y r&   r   r   s     r!   r   zB_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitDefTag        &r#   c                 &    | j                  |       y r&   r   r   s     r!   r   zD_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitBlockTag  rF  r#   c                     j                  |d       |j                  sj                  |j                         |j                  j                  v rj                  |j                  = y y )NFr   )r   rC   r`   r:   r   )ra   r   body_identifierscallable_identifiersr   r'   s     r!   r   zE_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitDefOrBase  s_    %%d,@%O((MM$--0 ==$4$@$@@(44T]]C Ar#   Nr   )rI  rJ  r   r'   s   r!   
DefVisitorrD    s    ''D Dr#   rK  zdef body(%s):r   r   r   )r   r   zccontext.caller_stack.nextcaller = runtime.Namespace('caller', context, callables=ccall(__M_caller))r   r   z&context.caller_stack.nextcaller = None)r    r|   r[   r   add_declaredr5   r`   ru   rv   r   rF   r;   r}   rT   r   r   r   rS   r   
expression)
r'   r   rK  r   r   bodyargsr/   rI  rJ  r   s
   `      @@@r!   r>  z"_GenerateRenderMethod.visitCallTag  s   34#//66tD6I/66tE6J
 	%%h/$$%56	D 	D  l 	"AS!	"!!#>>::<(1CCD LL##$<fE$$%56$$%56 	#AT"	#!!#dHeUeLmsxx7G&H$O+ 	
 	!!$++.))"dootDE4	
r#   )FN)T)FF)r)   r*   r+   __doc__r(   rI   propertyr[   rD   rH   r   r   r   r   r   r   r   r   r   r  r/  r2  r4  rm   r7  rg   r   r   r?  r>  r,   r#   r!   r   r   c   s    
/)b
" ) )k<Z7rP	
[%z|@|%&,^ ;?1Kt Qf@A"+/ZF&*) B
r#   r   c                       e Zd ZdZddZd Zed        Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)rz   zCtracks the status of identifier names as template code is rendered.Nc                 @   | t        |t        j                        r*t               | _        t        j                         | _        nt        |j                        j                  |j                  j                         D cg c]  }|j                   c}      j                  |j                        j                  |j                        | _        |r*| j                  j                  |j                        | _        t        j                  di |j                  | _        n(t               | _        t        j                         | _        || _        t               | _        t               | _        t               | _        t               | _        t        j                         | _	        || _        ||j%                  |        | j                  j&                  j)                  | j                        }|r't+        j,                  ddj/                  |      z        y c c}w )Nz'Reserved words declared in template: %sro   r,   )r6   r   NamespaceTagrw   r{   r   SetLikeDictr   rx   r   r   rJ   r   r   r   r4   r   r   rv   r   r   r   NameConflictErrorr}   )r'   r4   r   parentr   r   illegal_namess          r!   r(   z_Identifiers.__init__  s    $	 6 67 #$($4$4$6!
 (UF,>,>,E,E,GHqAFFHIU6223U6334	  $(MM$7$78I8I$JDM %)$4$4$Kv7J7J$K!EDM $ 0 0 2D  %
 !$
 !$ "%  ++-	%44AA!!
 ..9))M*+  c Is   Hc                 2    t        | j                  || fi |S )zUcreate a new Identifiers for a new Node, with
        this Identifiers as the parent.)rz   r4   )r'   r   rG   s      r!   r   z_Identifiers.branchH  s     DMM4@@@r#   c                 z    t        | j                  j                  | j                        j	                               S r&   )rw   r   rx   r   r   rZ   s    r!   rL   z_Identifiers.defsN  s-    4$$**4+;+;<CCEFFr#   c                    dt        | j                        dt        | j                        dt        | j                        d| j                  j                         D cg c]  }|j                   c}d| j                  j                         D cg c]  }|j                   c}d| j                  dS c c}w c c}w )NzIdentifiers(declared=z, locally_declared=z, undeclared=z, topleveldefs=z, closuredefs=z, argumentdeclared=r   )	r   r{   r   r   r   r   rJ   r   r   )r'   r   s     r!   __repr__z_Identifiers.__repr__R  s     T]]#T**+T__%!%!2!2!9!9!;<A<!%!1!1!8!8!:;A;&&
	
 =;s    B9B>c                     |j                         D ]K  }|dk7  s	|| j                  j                  | j                        vs1| j                  j                  |       M |j                         D ]  }| j                  j                  |        y)zlupdate the state of this Identifiers with the undeclared
        and declared identifiers of the given node.r   N)r	  r{   rx   r   r   r   ry   r'   r   r   s      r!   check_declaredz_Identifiers.check_declareda  s     002 	+E	!e4==3F3F%%4 ' ##E*		+
 ..0 	-E!!%%e,	-r#   c                     | j                   j                  |       || j                  v r| j                  j                  |       y y r&   )r{   r   r   remove)r'   r   s     r!   rL  z_Identifiers.add_declaredm  s7    % DOO#OO""5) $r#   c                 &    | j                  |       y r&   r^  r   s     r!   r  z_Identifiers.visitExpressionr      D!r#   c                 &    | j                  |       y r&   rb  r   s     r!   r/  z_Identifiers.visitControlLineu  rc  r#   c                     |j                   s@| j                  |       | j                  j                  |j	                               | _        y y r&   )rk   r^  r   rx   ry   r   s     r!   rm   z_Identifiers.visitCodex  sA    }}%$($9$9$?$?))+%D! r#   c                 f    | j                   |u r#|j                  D ]  }|j                  |         y y r&   )r   ru   rv   r'   r   r   s      r!   rg   z_Identifiers.visitNamespaceTag  s6     99ZZ '  &' r#   c                     |j                  |j                        }|||j                  <   |K||urF|j                  s|j                  r-t        j                  d|j                  z  fi |j
                  y y y )Nz<%%def or %%block named '%s' already exists in this template.)rA   r:   rB   r   r   r   )r'   
collectionr   existings       r!   _check_name_existsz_Identifiers._check_name_exists  s    >>$--0$(
4==! $("3"3--+-1]]; ''  #4 % !r#   c                 H   |j                         r)|j                  s| j                  | j                  |       n*|| j                  ur| j                  | j
                  |       |j                         D ]K  }|dk7  s	|| j                  j                  | j                        vs1| j                  j                  |       M || j                  u rS|j                         D ]  }| j                  j                  |        |j                  D ]  }|j                  |         y y Nr   )r   rC   rk  r   r   r   r	  r{   rx   r   r   r   ry   r   ru   rv   r'   r   r   r   s       r!   r   z_Identifiers.visitDefTag  s   <<>$"3"3##D$5$5t<"##D$4$4d;002 	+E	!e4==3F3F%%4 ' ##E*		+ 499224 2&&**512 ZZ '  &'	 r#   c                    || j                   ur|j                  st        | j                   t        j                        rEt        j                  d|j                  d| j                   j                  dfi |j                  t        | j                   t        j                  t        j                  f      r.t        j                  d|j                  dfi |j                  |j                         D ]K  }|dk7  s	|| j                  j                  | j                        vs1| j                  j!                  |       M |j                  sB| j#                  | j$                  |       | j                  j!                  |j&                         n*|| j                   ur| j#                  | j(                  |       |j+                         D ]  }| j,                  j!                  |        |j.                  D ]  }|j1                  |         y )NzNamed block 'z' not allowed inside of def ''z#' not allowed inside of <%call> tagr   )r   rC   r6   r   r7   r   r   rJ   r   CallTagCallNamespaceTagr	  r{   rx   r   r   r   rk  r   r:   r   ry   r   ru   rv   rn  s       r!   r   z_Identifiers.visitBlockTag  s   tyy ):):$))Y%5%56 11yy$))..2 ++ 
 		I--y/I/IJ !11yy# ++  002 	+E	!e4==3F3F%%4 ' ##E*		+   ##D$5$5t<OO."##D$4$4d;..0 	.E""&&u-	. 	#AT"	#r#   c                     |j                         D ]K  }|dk7  s	|| j                  j                  | j                        vs1| j                  j                  |       M y rm  )r	  r{   rx   r   r   r   r]  s      r!   r4  z_Identifiers.visitTextTag  sW    002 	+E	!e4==3F3F%%4 ' ##E*		+r#   c                 &    | j                  |       y r&   rb  r   s     r!   r7  z_Identifiers.visitIncludeTag  rc  r#   c                     |j                         D ]  }| j                  j                  |        | j                  |       y r&   )ry   r   r   r^  r]  s      r!   ri   z_Identifiers.visitPageTag  s<    ..0 	.E""&&u-	.D!r#   c                 &    | j                  |       y r&   r=  r   s     r!   r?  z"_Identifiers.visitCallNamespaceTag  s    $r#   c                 >   || j                   u r|j                         D ]K  }|dk7  s	|| j                  j                  | j                        vs1| j
                  j                  |       M |j                         D ]  }| j                  j                  |        |j                  D ]  }|j                  |         y |j                         D ]K  }|dk7  s	|| j                  j                  | j                        vs1| j
                  j                  |       M y rm  )r   r	  r{   rx   r   r   r   ry   r   ru   rv   rn  s       r!   r>  z_Identifiers.visitCallTag  s	   499446 /I%%t}}7J7J))8 + OO''.	/
 224 2&&**512ZZ '  &' 446 /I%%t}}7J7J))8 + OO''.	/r#   )NNF)r)   r*   r+   rO  r(   r   rP  rL   r[  r^  rL  r  r/  rm   rg   rk  r   r   r4  r7  ri   r?  r>  r,   r#   r!   rz   rz     st    MAFA G G

-*
""''(#B+""
 /r#   rz   z^for\s+((?:\(?)\s*(?:\(?)\s*[A-Za-z_][A-Za-z_0-9]*(?:\s*,\s*(?:[A-Za-z_][A-Za-z_0-9]*),??)*\s*(?:\)?)(?:\s*,\s*(?:(?:\(?)\s*[A-Za-z_][A-Za-z_0-9]*(?:\s*,\s*(?:[A-Za-z_][A-Za-z_0-9]*),??)*\s*(?:\)?)),??)*\s*(?:\)?))\s+in\s+(.*):c                 z   t               }| j                  |       |j                  rd| j                  d   _        t
        j                  | j                        }|r:|j                  d|j                  d      z  d       d|j                  d      z  }|S t        d| j                  z        | j                  }|S )	zconverts a for loop into a context manager wrapped around a for loop
    when access to the `loop` variable has been detected in the for loop body
    TrY   zloop = __M_loop._enter(%s)rt   r   zfor %s in loop:r   zCouldn't apply loop context: %s)LoopVariablerv   detectedru   r+  	_FOR_LOOPr  r   rT   r  SyntaxError)r   r    loop_variabler  r   s        r!   r,  r,    s     !NM&*.

2'		*,u{{1~=
 %u{{1~5D
 K ?$))KLLyyKr#   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)ry  zQA node visitor which looks for the name 'loop' within undeclared
    identifiers.c                     d| _         y )NF)rz  rZ   s    r!   r(   zLoopVariable.__init__  s	    r#   c                     d|j                         v rd| _        y |j                         D ]  }|j                  |         y )Nr   T)r	  rz  r-  rv   rg  s      r!   _loop_reference_detectedz%LoopVariable._loop_reference_detected  s@    T0022 DM&&( '  &'r#   c                 &    | j                  |       y r&   r  r   s     r!   r/  zLoopVariable.visitControlLine       %%d+r#   c                 &    | j                  |       y r&   r  r   s     r!   rm   zLoopVariable.visitCode#  r  r#   c                 &    | j                  |       y r&   r  r   s     r!   r  zLoopVariable.visitExpression&  r  r#   N)	r)   r*   r+   rO  r(   r  r/  rm   r  r,   r#   r!   ry  ry    s     ',,,r#   ry  )rO  rU   r   r   makor   r   r   r   r   
mako.pygenr   r~   r   rx   RESERVED_NAMES	frozensetr"   r   r   rz   r{  r,  ry  r,   r#   r!   <module>r     s     	       $ 
 !"23 V$**+<= ;%P- -8[
 [
|k/ k/\ BJJ&	., ,r#   