
    gx                     <   S 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  SSKJr  SSKJ	r	  SSK
Jr  S	rS
S1rSS1R                  \5      rSSSSSSSSS\" 5       4
S jr " S S5      r " S S5      r " S S5      r\R"                  " S5      rS r " S S5      rg)zVprovides functionality for rendering a parsetree constructing into module
source code.    N)ast)
exceptions)filters)	parsetree)util)PythonPrinter
   	UNDEFINEDSTOP_RENDERINGcontextloopTFc                     [         R                  " 5       n[        U5      n[        U[	        UUUUUUUUU	U
U5      U 5        UR                  5       $ )zUGenerate 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                 T/Users/Alptekin/Desktop/izin_takip/venv/lib/python3.13/site-packages/mako/codegen.pycompiler"      sc    " 
!
!
#CC G"	
 	" <<>    c                       \ rS rSrS rSrg)r   G   c                     Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        Xl
        g 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___CompileContext.__init__H   sC      .,,.&<# 0&,r#   )r   r   r   r   r   r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno__r)   __static_attributes__ r#   r!   r   r   G   s    -r#   r   c                       \ rS rSrSrS rS r\S 5       rS r	S r
S rS	 rS
 rSS jrS rS r SS jr  S S jrS rS rS rS rS rS rS rS rS rS rS rS rSrg)!r   c   zRA template visitor object which generates the
full module source for a template.

c                    Xl         X l        X0l        S /U l        [	        U[
        R                  [
        R                  45      U l        U R                  (       a  SUR                  -  nUR                  5       n[        UR                  R                  5      S:  n[        UR                  R!                  SS5      5      n[        UR                  R!                  SS5      5      nS n	S n
UR"                  (       a  UR$                  (       d  US/-  nOU R'                  5       n	U R                  R(                  n
SnU
b  U
R*                  R                  5       nU
R*                  R,                  (       d  US/-  n[        U
R                  R!                  SS5      5      nU R                  R.                  =(       d%    [        U
R                  R!                  SS5      5      U R                  l        OS/nS	nS	=pvUc  S
/nOS
/U-    Vs/ s H  oPM     nnU R1                  U
=(       d    UXEXvU5        U	b  U	 H  n[3        XU5        M     U R                  (       d  U R5                  5         g g s  snf )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    r9   r   namerC   filteredr4   r6   defsrJ   as               r!   r)   _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) %~"''H<;D ){T121!A1D2""OtTV	
 %g>  {{&&(  3s   I,c                    [        U R                  R                  5      U R                  R                  U R                  R                  '   U R                  R
                  U R                  R                  U R                  R                  U R                  R                  S.nU R                  R                  SS[        R                  " U5      S5        g )N)r   r   r   line_mapz"""__M_BEGIN_METADATAz__M_END_METADATA
""")maxr    
source_maplinenor9   r   r   r   
writelinesjsondumps)r(   structs     r!   rN   +_GenerateRenderMethod.write_metadata_struct   s    7:LL##8
 3 34 ..==$$#}}<<//	
 	 JJv&		
r#   c                      U R                   S   $ )N)r:   r(   s    r!   identifiers!_GenerateRenderMethod.identifiers   s    $$R((r#   c                 
  ^ ^^^ / m0 m/ mST R                   l         " UUUU 4S jS5      nU" 5       nT R                  R                   H  nUR	                  U5        M     TT R                   l        [        5       nT H"  nUR                  UR                  5       5      nM$     [        T R                   5      nXEl
        T R                   R                  (       aM  T R                   R                  (       a2  T R                  R                  ST R                   R                  -  5        T R                   R                  (       aB  T R                  R                  SSR!                  T R                   R                  5      < 35        T R                  R                  S5        T R                  R                  S5        T R                  R                  S	5        T R                  R                  S
5        T R                  R                  S5        T R                  R                  S["        -  5        T R                  R                  S[$        R$                  " 5       -  5        T R                  R                  ST R                   R&                  -  5        T R                  R                  ST R                   R(                  -  5        T R                  R                  ST R                   R*                  -  5        T R                  R                  ST R                   R                  -  5        T R                   R,                  (       aZ  SnT R                   R,                   H%  nXgS-   -  nT R                  R                  U5        M'     [.        R0                  " USSSSS9nOSnUR3                  T R                  5      n	UR4                  n
U
R                  U	R4                  5      Ul        UR                  R7                  [8        5        U(       a%  UR                  R7                  UR                  5        UT R                   l        T R                  R                  SU	R4                  R=                  5        Vs/ s H  o3R>                  PM     sn-  5        T R                  RA                  S5        [C        T5      (       a  T RE                  T5        [C        T5      (       a&  T RG                  T5        T RI                  TS   5        O![C        T5      (       a  T RG                  T5        [K        U	R4                  R=                  5       5      $ s  snf )zhTraverse a template structure for module-level directives and
generate the start of module-level code.

Nc                   F   > \ rS rSrU 4S jrU4S jrU4S jrU4S jrSrg):_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel   c                 (   > TR                  U5        g r'   )append)sr   inherits     r!   visitInheritTagJ_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitInheritTag   s    t$r#   c                 $   > UTUR                   '   g r'   rO   )rj   r   
namespacess     r!   visitNamespaceTagL_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitNamespaceTag   s    (,
499%r#   c                 (   > UTR                   l        g r'   )r9   rJ   )rj   r   r(   s     r!   visitPageTagG_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitPageTag   s    (,%r#   c                 L   > UR                   (       a  TR                  U5        g g r'   )ismoduleri   )rj   r   module_codes     r!   	visitCodeD_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitCode   s    ==&&t, !r#   r0   N)	r+   r,   r-   r.   rl   rq   rt   ry   r/   )rk   rx   rp   r(   s   r!   FindTopLevelrf      s    %--- -r#   r{   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)sourcerY   posr   z_exports = %r   r`   )&r9   rJ   r   nodesaccept_visitorrp   setuniondeclared_identifiers_Identifiersdeclaredr   r   r    	writeliner   joinMAGIC_NUMBERtimer   r   r   r   r   
PythonCodebranchtopleveldefsupdateTOPLEVEL_DECLAREDrb   valuesrO   write_blanksrA   write_module_codewrite_namespaceswrite_inheritlist)r(   r{   fnmodule_identmodule_identifiersr   impimpcodemain_identifiersmitrk   rx   rp   s   `          @@@r!   rI   $_GenerateRenderMethod.write_toplevel   s   
 
 $	- 	- NAQ ! $. uA'--a.D.D.FGL  *$--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}},,Tz!&&s+ - nn3G G-44TYY? --*-))))+
' 	##**+<=''..w/K/KL$6!/<<CCEFE!vvEFG	
 	!!!${"";/w<<!!*-wr{+__!!*-$1188:;; Gs   2U
c                    U R                   (       a1  UR                  nU(       a  U R                  R                  SU-  5        U R                  R	                  UR
                  5        U R                  R                  SU< SSR                  U5      < S3SS5        U(       d  U(       d  U(       a  U R                  R                  S5        U R                  R                  U R                  R                  R                  U R                  5      5        U R                   (       a  U R                  R                  (       a.  S	U;   a(  U R                  S
   R                  R!                  S5        U R                   (       d  [#        U R                  R$                  5      S:  d#  [#        U R                  R                  5      S:  aY  U R                  R                  SSR                  U R                  R                   Vs/ s H  nU< SU< 3PM     sn5      -  5        U R'                  U R                  SS9  U R                  R(                   H  n	U	R+                  U 5        M     U R-                  U R                  XEU5        U R                  R                  S5        U R                  R/                  S5        U(       a  U R1                  XX4U R                  SS9  ggs  snf )zfwrite 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()r7   r`   pageargsr   z!__M_locals = __M_dict_builtin(%s)=T)toplevelNr   )r>   	decoratorr    r   start_sourcerY   rZ   r   r:   ri   r9   rb   r   r   rG   argument_declaredaddrA   locally_assignedwrite_variable_declaresr   r   write_def_finishr   write_cache_decorator)
r(   r   rO   rC   r4   rP   r6   r   xr   s
             r!   rM   +_GenerateRenderMethod.write_render_callable  s+    ;;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!CA $%a(!C 	$$T%5%5$EAT" ! 	diiVDt$!!!$&&DD,<,<t '  s   ?Kc                 r    U H1  nU R                   R                  UR                  UR                  S9  M3     g)z]write module-level template code, i.e. that which
is enclosed in <%! %> tags in the template.starting_linenoN)r    write_indented_blocktextrY   )r(   rx   r   s      r!   r   '_GenerateRenderMethod.write_module_codeV  s-     ALL--affahh-O r#   c                 `    U R                   R                  SSSUR                  S   -  S5        g)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    rZ   parsed_attributesr(   r   s     r!   r   #_GenerateRenderMethod.write_inherit\  s5     	30F%%f-/	
r#   c                   ^ ^^ T R                   R                  SSSSSSSS5        T R                   R                  S5        UR                  5        GH  nSUR                  ;   a  S	T R
                  l        T R                   R                  UR                  5        [        UR                  5      (       a  T R                   R                  S
5        / mT R
                  R                  R                  U5      mS	T l         " UUU 4S jS5      nU" 5       nUR                   H  nUR                  U5        M     T R                   R                  SSR                  T5      -  5        T R                   R                  S5        ST l        SnOSnSUR                   ;   aM  T R                   R                  SUR"                  < SUR                   R%                  SS5      < SU< S35        OSUR                   ;   aM  T R                   R                  SUR"                  < SU< SUR                   R%                  SS5      < S35        O.T R                   R                  SUR"                  < SU< S35        ['        UR                  R%                  SS5      5      (       a(  T R                   R                  S UR"                  -  5        T R                   R                  S![)        UR"                  5      -  5        T R                   R+                  S"5        GM     [        U5      (       d  T R                   R                  S#5        T R                   R                  S5        g)$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                   2   > \ rS rSrS rS rU UU4S jrSrg)<_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitori  c                 &    U R                  U5        g r'   visitDefOrBaserj   r   s     r!   visitDefTagH_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitDefTag      ((.r#   c                 &    U R                  U5        g r'   r   r   s     r!   visitBlockTagJ_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitBlockTag  r   r#   c                    > UR                   (       a!  [        R                  "  S0 UR                  D6eTR	                  UTSS9  TR                  UR                  5        g )NFnested)z.Can't put anonymous blocks inside <%namespace>)rH   r   CompileExceptionexception_kwargswrite_inline_defri   r?   )rj   r   exportrb   r(   s     r!   r   K_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitDefOrBase  s[    ,,","="=!/# #'"7"7# 
 --dK-Ndmm4r#   r0   Nr+   r,   r-   r.   r   r   r   r/   )r   rb   r(   s   r!   NSDefVisitorr     s    //5 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)inheritabler5   zcontext['self'].%s = nsz'context.namespaces[(__name__, %s)] = ns   pass)r    rZ   r   r   rE   r9   has_ns_importsr   rY   rA   r   rb   r   r>   r   r   r   rO   rF   rD   reprr   )	r(   rp   r   r   visr   callable_namer   rb   s	   `      @@r!   r   &_GenerateRenderMethod.write_namespacesg  s   5909		
 	HI%%'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 (V :LL""6*t$r#   Nc                    UR                    Vs0 s H  oDR                  U_M     nn[        5       nUR                  UR                  5      nUR                  UR
                  R                  5        Vs/ s H  oDR                  PM     sn5      nUR                  UR                  5      nUR                  UR                  5      nU R                  R                  (       a  SU;   nUR                  S5        OSnUb  UR                  U5      nU(       a  [        U R                  SS5      (       a  U R                  R!                  S5        SU R                  l        U R                  R$                  R'                  5        H]  u  pSU	R(                  ;   d  M  U R                  R!                  SU< S	[*        R,                  " S
U	R(                  S   5      < S35        M_     U(       a  U R                  R!                  S5        U GH  nX;   a  XX   n
U
R.                  (       a6  U
R0                  (       d  U R3                  X5        MB  U R5                  XSS9  MT  U
R7                  5       (       a  U R3                  X5        M|  U R5                  XSS9  M  XR                  R$                  ;   a%  U R                  R!                  U< SU< S35        M  [        U R                  SS5      (       a  U R                  R8                  (       a;  U R                  R;                  U< SU< S3SU-  SU< SU< S3SSU-  SS5        GM>  U R                  R!                  U< SU< SU< S35        GMh  U R                  R8                  (       a-  U R                  R;                  SU< SU< S3SSU-  S5        GM  U R                  R!                  U< SU< S35        GM     U R                  R!                  S5        gs  snf s  snf )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())rQ   r?   r   r   
undeclaredclosuredefsr   
differencer   locally_declaredr9   r   discardintersectiongetattrr    r   has_importsrp   itemsrE   resplitrG   rH   write_def_declr   is_rootr   rZ   )r(   rb   r   limitccomp_identsto_writehas_loopidentnscomps              r!   r   -_GenerateRenderMethod.write_variable_declares  s3   ( /:.>.>?.>zz1}.>?5 >>+"8"89 >>!,!8!8!?!?!AB!AAZZ!AB
 &&{'D'DE &&{'C'CD==$$)HV$H ,,U3H/?GGLL""#45(,DMM%!]]55;;=	r}},LL** "HHZx1HI	 > LL""#JKE#")==,,++D>--d-M||~~++D>--d-M--222&&?DeL 4==*:EBB}}55//$e-1E9"27?.FN  
 ..  %eU4 }}55//"27?.FN  ..AFNa h 	>?Q @ Cs   O93O>c                 T   UR                   nUR                  5       nUR                  SS9nU R                  (       dY  [        U R                  R
                  5      S:  d#  [        U R                  R                  5      S:  a  UR                  SS5        OUR                  SS5        U R                  R                  SU< SSR                  U5      < S	35        U R                  R                  S
U< SSR                  U5      < S35        U R                  R                  S5        g)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@   r>   rA   rb   r   r   insertr    r   r   )r(   r   rb   r?   	namedeclsnameargss         r!   r   $_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           
      
   UR                  5       nUR                  nU(       a  U R                  R                  SU-  5        U R                  R                  SUR                  < SSR                  U5      < S35        [        UR                  R                  5      S:  n[        UR                  R                  SS5      5      n[        UR                  R                  S	S5      5      nU R                  R                  S
S5        U(       d  U(       d  U(       a  U R                  R                  S5        UR                  XS9nU R                  U5        U R                  R!                  U5        UR"                   H  n	U	R%                  U 5        M     U R                  R'                  5         U R)                  XXh5        U R                  R                  S5        U(       a   U R+                  UUR                  USUSSS9  gg)z?write a locally-available def callable inside an enclosing def.z&@runtime._decorate_inline(context, %s)r   r   r   r   r   r4   r5   r6   r   r   r   r   NFT)inliner   )r@   r   r    r   r?   r   rA   rB   rC   rD   rE   rF   rZ   r   r   r:   ri   r   r   popr   r   )
r(   r   rb   r   r  r   rP   r4   r6   r   s
             r!   r   &_GenerateRenderMethod.write_inline_defU  s    113	NN	LL""89D 	!]]CHHY,?@	
 t'',,-1++J@Adoo))(G<==	

 x6LL##$<=!(((=$$[1$$[1AT" !!#dh?t$&& '  r#   c                 D   U(       dM  U(       dF  U(       d?  U R                   R                  S5        U(       a  U R                   R                  SSS5        U(       d  U(       d  U(       Ga6  U(       d  U(       a  U R                   R                  SS5        OU R                   R                  SS5        U(       a  U R                   R                  S5        SnU(       a'  U R                  UR                  R
                  US5      nU R                   R                  S5        U(       a.  U(       d'  U R                  U R                  R                  US5      nU(       d  U(       a  U R                   R                  S	U-  5        gU R                   R                  S
U-  S5        gg)a"  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   rZ   create_filter_callablerB   rC   r9   r   )r(   r   r4   rP   r6   	callstackrj   s          r!   r   &_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                 D  ^ ^ T R                   R                  SU< SU< 35        TR                  R                  S[	        U5      5      n0 n	T R
                  R                  b9  U	R                  U 4S jT R
                  R                  R                   5       5        U	R                  U4S jTR                   5       5        SU	;   a  [        [        U	S   5      5      U	S'   T R                   R                  SU< S	S
R                  U5      < S35        U V
s/ s H&  n
SU
;   a  SU
R                  S5      S   4S-  -  OU
PM(     nn
T R                  UUTR                  5       S9  U(       a  SU< SU< S	S
R                  U5      < SSR                  U	R                  5        VVs/ s H  u  pU< SU< S3PM     snn5      < SU< S3nT R                  T R
                  R                   US5      nT R                   R#                  SU-   S5        gT R                   R#                  SU< SU< S	S
R                  U5      < SSR                  U	R                  5        VVs/ s H  u  pU< SU< S3PM     snn5      < SU< S3SS5        gs  sn
f s  snnf s  snnf )z`write a post-function decorator to replace a rendering
callable with a cached version of itself.__M_z = 	cache_keyNc              3      >#    U  HM  nUR                  S 5      (       d  M  US:w  d  M#  USS TR                  R                  R                  U   4v   MO     g7fcache_r     N)
startswithr9   rJ   r   ).0par(   s     r!   	<genexpr>>_GenerateRenderMethod.write_cache_decorator.<locals>.<genexpr>  sU      AB==* F/1[/@ FAB..@@DEAs   AA/Ac              3      >#    U  H9  nUR                  S 5      (       d  M  US:w  d  M#  USS TR                  U   4v   M;     g7fr  )r  r   )r  r  node_or_pagetags     r!   r  r    sI      
7}}X& <+-+< <RV_66r:;7s   AAAtimeoutr   r   r   r   r   z%s=%sr   r   )r   r   z.context.get('local').cache._ctx_get_or_create(z, lambda:__M_z),  context, r}   r|   z__M_defname=r   Fzreturn z9__M_writer(context.get('local').cache._ctx_get_or_create(z), context, z))r  )r    r   r   rF   r   r9   rJ   r   intrD   r   r   r   undeclared_identifiersr   r  r   rZ   )r(   r   rO   rC   r4   rb   r  r   cachekey
cache_argsrR   	pass_argskvrj   s   ``             r!   r   +_GenerateRenderMethod.write_cache_decorator  s[    	d;<"4488d
 
==  , --//AA 
 	 
%77
 	

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

  HHY'GG8B8H8H8JK8Ja+8JK   ++,,aA LL##IM48LL##
 HHY'GG8B8H8H8JK8Ja+8JK  =
& L( Ls   -J(J$Jc                    S nSU;  a  U(       a  U R                   R                  (       a-  U R                   R                  R                  R                  U-   nU R                   R                  (       a  SU;  a  U R                   R                  U-   nU Ha  nUS:X  a  M  [
        R                  " SU5      nU(       a!  UR                  SS5      u  pxU" U5      n	X-   nOU" U5      nUc   eU< SU< S3nMc     U$ )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                     [         R                  " SU 5      (       a  SU -   $ [        R                  R	                  X 5      $ )Nz
decode\..+zfilters.)r   matchr   DEFAULT_ESCAPESrF   ro   s    r!   locate_encodeC_GenerateRenderMethod.create_filter_callable.<locals>.locate_encode  s5    xxt,,!D((..224>>r#   r   z(.+?)(\(.*\))r   r   r   r   )r9   rJ   rB   rC   r   r   r,  group)
r(   rC   targetis_expressionr.  emr   fargsr   s
             r!   r  ,_GenerateRenderMethod.create_filter_callable	  s    
	? d?==((==00<<AADHD==00S_==884?DACx)1-A wwq!}!%(I!!$}$}!"F+F  r#   c                 ^   U R                   R                  UR                  5        [        UR                  5      (       ds  U R
                  R                  b8  [        U R
                  R                  R                  R                  5      (       d$  [        U R
                  R                  5      (       aS  U R                  UR                  R                  SUR                  -  S5      nU R                   R                  SU-  5        g U R                   R                  SUR                  -  5        g )Nz%sTr  )r    r   rY   rA   escapesr9   rJ   rB   rC   r   r  escapes_coder   r   )r(   r   rj   s      r!   visitExpression%_GenerateRenderMethod.visitExpression)  s    !!$++.%%1--99>>??4==0011++!!&&tyy(8$A LL""#3a#78LL""#3dii#?@r#   c                 0  ^^ TR                   (       a  U R                  R                  S 5        TR                  (       aR  U R                  R                  S5        U R                  R                  S5        U R                  R                  S 5        g g U R                  R	                  TR
                  5        U R                  R                  (       a'  TR                  S:X  a  [        TU R                  5      nOTR                  nU R                  R                  U5        TR                  5       mU4S jnT(       a=  [        S T 5       5      (       a  [        U4S jT 5       5      (       d  U" 5       (       a  U R                  R                  S5        g g )Nr  zloop = __M_loop._exit()forc                     > T HE  n [        U [        R                  5      (       a  M$  [        U [        R                  5      (       a    g  g   g )NTFr;   r   CommentControlLine)r   childrens    r!   _search_for_control_lineH_GenerateRenderMethod.visitControlLine.<locals>._search_for_control_lineP  s<    !A!!Y%6%677 #Ay'<'<==#  "r#   c              3   v   #    U  H/  n[        U[        R                  [        R                  45      v   M1     g 7fr'   r?  )r  r   s     r!   r  9_GenerateRenderMethod.visitControlLine.<locals>.<genexpr>Z  s2      % q9#4#4i6K6K"LMM%s   79c              3      >#    U  HT  n[        U[        R                  5      (       d  M$  TR                  UR                  5      =(       d    UR
                  v   MV     g 7fr'   )r;   r   rA  
is_ternarykeywordisend)r  r   r   s     r!   r  rF  ^  sC      %!!Y%:%:; ;T__QYY/:177:%s
   #A5Ar   )rJ  r    r   has_loop_contextr   rY   r9   r   rI  mangle_mako_loopr   get_childrenall)r(   r   r   rC  rB  s    `  @r!   visitControlLine&_GenerateRenderMethod.visitControlLine:  s,   ::LL""4($$&&z2&&'@A&&t, %
 LL%%dkk2}}((T\\U-B'dll;yyLL""4(((*H!  %    %  
 ,--&&v. .r#   c                     U R                   R                  UR                  5        U R                   R                  S[	        UR
                  5      -  5        g )Nr  )r    r   rY   r   r   contentr   s     r!   	visitText_GenerateRenderMethod.visitTextg  s9    !!$++./$t||2DDEr#   c           
      r   [        UR                  R                  5      S:  nU(       a  U R                  R	                  SS5        UR
                   H  nUR                  U 5        M     U(       aG  U R                  R	                  SSSU R                  UR                  R                  SS5      -  S 5        g g )	Nr   z#__M_writer = context._push_writer()r   r  r  r  r  F)rA   rB   rC   r    rZ   r   r   r  )r(   r   rP   r   s       r!   visitTextTag"_GenerateRenderMethod.visitTextTagk  s    t'',,-1LL##5v AT" LL##H --$$))+?  r#   c                    UR                   (       d  U R                  R                  UR                  UR                  S9  U R
                  (       d  [        U R                  R                  5      S:  aq  U R                  R                  S5        U R                  R                  SSR                  UR                  5        Vs/ s H  n[        U5      PM     sn5      -  5        g g g g s  snf )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   )rw   r    r   r   rY   r>   rA   rb   r   r   r   r   r   )r(   r   r   s      r!   ry   _GenerateRenderMethod.visitCode~  s    }}LL--		4;; .  ;;3t'7'7'H'H#IA#M
 &&F &&G hh1J1J1LM1LAQ1LMNO $N; "  Ns   C(c                 L   U R                   R                  UR                  5        UR                  R	                  S5      nU(       a2  U R                   R                  SUR                  S   < SU< S35        g U R                   R                  SUR                  S   -  5        g )NrC   zruntime._include_file(context, r   z, _template_uri, r   z1runtime._include_file(context, %s, _template_uri))r    r   rY   rE   rF   r   r   )r(   r   rC   s      r!   visitIncludeTag%_GenerateRenderMethod.visitIncludeTag  s    !!$++.""6*LL""))&149
 LL""C))&13r#   c                     g r'   r0   r   s     r!   rq   '_GenerateRenderMethod.visitNamespaceTag      r#   c                     g r'   r0   r   s     r!   r   !_GenerateRenderMethod.visitDefTag  r_  r#   c                    UR                   (       a)  U R                  R                  SUR                  -  5        g UR	                  SS9nUS/-  nU R                  R                  SUR                  -  5        U R                  R                  SUR                  < SSR                  U5      < S	35        U R                  R                  S
5        g )Nz%s()Tr   r7   zOif 'parent' not in context._data or not hasattr(context._data['parent'], '%s'):zcontext['self'].r   r   r   r~   )rH   r    r   r?   r@   r   )r(   r   r  s      r!   r   #_GenerateRenderMethod.visitBlockTag  s    LL""6DMM#9:44T4BH&HLL"">@DN LL"",0MM388H;MN LL""4(r#   c                 &    U R                  U5        g r'   visitCallTagr   s     r!   visitCallNamespaceTag+_GenerateRenderMethod.visitCallNamespaceTag  s     	$r#   c                   ^ ^^^	 T R                   R                  S5        S/m	T R                  R                  USS9mTR                  USS9mTR	                  S5        T R
                  R                  T5         " UUU	U 4S jS5      nU" 5       nUR                   H  nUR                  U5        M     T R
                  R                  5         UR                  R                  5       nT R                   R                  S	S
R                  U5      -  5        SnU(       a  T R                   R                  SS5        T R                  T5        T R
                  R                  T5        UR                   H  nUR                  T 5        M     T R
                  R                  5         T R                  XSSSS9  T R                   R                  S SS
R                  T	5      -  S 5        T R                   R                  SS5        T R                   R!                  UR"                  5        T R                   R                  ST R%                  / UR&                  S5      -  SSS 5        g )Nzdef ccall(caller):bodyTr   Fcallerc                   4   > \ rS rSrS rS rU UUU4S jrSrg)6_GenerateRenderMethod.visitCallTag.<locals>.DefVisitori  c                 &    U R                  U5        g r'   r   r   s     r!   r   B_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitDefTag        &r#   c                 &    U R                  U5        g r'   r   r   s     r!   r   D_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitBlockTag  rp  r#   c                    > TR                  UTSS9  UR                  (       d  TR                  UR                  5        UR                  TR                  ;   a  TR                  UR                  	 g g )NFr   )r   rH   ri   r?   r   )rj   r   body_identifierscallable_identifiersr   r(   s     r!   r   E_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitDefOrBase  s_    %%d,@%O((MM$--0 ==$4$@$@@(44T]]C Ar#   r0   Nr   )rt  ru  r   r(   s   r!   
DefVisitorrm    s    ''D Dr#   rw  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   rb   r   add_declaredr:   ri   r   r   r  rK   r@   r   rZ   r   r   r   rY   r  
expression)
r(   r   rw  r   r   bodyargsr4   rt  ru  r   s
   `      @@@r!   rf  "_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" !!#deUeLmsxx7G&H$O+ 	
 	!!$++.))"dootDE4	
r#   )r9   r:   r>   r   r    )FN)T)FF) r+   r,   r-   r.   __doc__r)   rN   propertyrb   rI   rM   r   r   r   r   r   r   r   r   r  r:  rO  rS  rV  ry   r[  rq   r   r   rg  rf  r/   r0   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                       \ rS rSrSrSS jrS r\S 5       rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rSrg)r   i  zCtracks the status of identifier names as template code is rendered.Nc                 l   UGb.  [        U[        R                  5      (       a+  [        5       U l        [
        R                  " 5       U l        GO[        UR                  5      R                  UR                  R                  5        Vs/ s H  oUR                  PM     sn5      R                  UR                  5      R                  UR                  5      U l        U(       a*  U R                  R                  UR                  5      U l        [
        R                  " S0 UR                  D6U l        O)[        5       U l        [
        R                  " 5       U l        Xl        [        5       U l        [        5       U l        [        5       U l        [        5       U l        [
        R                  " 5       U l	        X l        Ub  UR%                  U 5        U R                  R&                  R)                  U R                  5      nU(       a(  [*        R,                  " SSR/                  U5      -  5      eg s  snf )Nz'Reserved words declared in template: %sr|   r0   )r;   r   NamespaceTagr   r   r   SetLikeDictr   r   r   r   rO   r   r   r   r9   r   r   r   r   r   r   NameConflictErrorr   )r(   r9   r   parentr   r   illegal_namess          r!   r)   _Identifiers.__init__  s    $	 6 677 #$($4$4$6!
 (UF,>,>,E,E,GH,GqFF,G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   	H1c                 0    [        U R                  X40 UD6$ )zMcreate a new Identifiers for a new Node, with
this Identifiers as the parent.)r   r9   )r(   r   rL   s      r!   r   _Identifiers.branchH  s     DMM4@@@r#   c                 z    [        U R                  R                  U R                  5      R	                  5       5      $ r'   )r   r   r   r   r   ra   s    r!   rQ   _Identifiers.defsN  s-    4$$**4+;+;<CCEFFr#   c                    S[        U R                  5      < S[        U R                  5      < S[        U R                  5      < SU R                  R                  5        Vs/ s H  oR                  PM     sn< SU R                  R                  5        Vs/ s H  oR                  PM     sn< SU R                  < S3$ s  snf s  snf )NzIdentifiers(declared=z, locally_declared=z, undeclared=z, topleveldefs=z, closuredefs=z, argumentdeclared=r   )	r   r   r   r   r   r   rO   r   r   )r(   r   s     r!   __repr___Identifiers.__repr__R  s     T]]#T**+T__%!%!2!2!9!9!;<!;A!;<!%!1!1!8!8!:;!:A!:;&&
	
 =;s   #CCc                 0   UR                  5        HP  nUS:w  d  M  X R                  R                  U R                  5      ;  d  M5  U R                  R                  U5        MR     UR                  5        H  nU R                  R                  U5        M      g)zdupdate the state of this Identifiers with the undeclared
and declared identifiers of the given node.r   N)r#  r   r   r   r   r   r   r(   r   r   s      r!   check_declared_Identifiers.check_declareda  s{     002E	!e==3F3F%%4 ' ##E*	 3
 ..0E!!%%e, 1r#   c                     U R                   R                  U5        XR                  ;   a  U R                  R                  U5        g g r'   )r   r   r   remove)r(   r   s     r!   rx  _Identifiers.add_declaredm  s5    % OO#OO""5) $r#   c                 &    U R                  U5        g r'   r  r   s     r!   r:  _Identifiers.visitExpressionr      D!r#   c                 &    U R                  U5        g r'   r  r   s     r!   rO  _Identifiers.visitControlLineu  r  r#   c                     UR                   (       d@  U R                  U5        U R                  R                  UR	                  5       5      U l        g g r'   )rw   r  r   r   r   r   s     r!   ry   _Identifiers.visitCodex  sA    }}%$($9$9$?$?))+%D! r#   c                 l    U R                   UL a%  UR                   H  nUR                  U 5        M     g g r'   )r   r   r   r(   r   r   s      r!   rq   _Identifiers.visitNamespaceTag  s1     99ZZ  &   r#   c                    UR                  UR                  5      nX!UR                  '   UbV  X2LaQ  UR                  (       d  UR                  (       a.  [        R                  " SUR                  -  40 UR
                  D6eg g g )Nz<%%def or %%block named '%s' already exists in this template.)rF   r?   rG   r   r   r   )r(   
collectionr   existings       r!   _check_name_exists_Identifiers._check_name_exists  s~    >>$--0$(4==! $("3"3--+-1]]; ''  #4 % !r#   c                 p   UR                  5       (       a.  UR                  (       d  U R                  U R                  U5        O*XR                  La  U R                  U R
                  U5        UR                  5        HP  nUS:w  d  M  X R                  R                  U R                  5      ;  d  M5  U R                  R                  U5        MR     XR                  L aW  UR                  5        H  nU R                  R                  U5        M      UR                   H  nUR                  U 5        M     g g Nr   )r   rH   r  r   r   r   r#  r   r   r   r   r   r   r   r   r   r(   r   r   r   s       r!   r   _Identifiers.visitDefTag  s    <<>>$"3"3##D$5$5t<"##D$4$4d;002E	!e==3F3F%%4 ' ##E*	 3 99224&&**51 5 ZZ  &  	 r#   c                 d   XR                   La  UR                  (       d  [        U R                   [        R                  5      (       aH  [
        R                  " SUR                  < SU R                   R                  < S340 UR                  D6e[        U R                   [        R                  [        R                  45      (       a0  [
        R                  " SUR                  < S340 UR                  D6eUR                  5        HP  nUS:w  d  M  X R                  R                  U R                  5      ;  d  M5  U R                  R!                  U5        MR     UR                  (       dB  U R#                  U R$                  U5        U R                  R!                  UR&                  5        O*XR                   La  U R#                  U R(                  U5        UR+                  5        H  nU R,                  R!                  U5        M      UR.                   H  nUR1                  U 5        M     g )NzNamed block 'z' not allowed inside of def ''z#' not allowed inside of <%call> tagr   )r   rH   r;   r   r<   r   r   rO   r   CallTagCallNamespaceTagr#  r   r   r   r   r   r  r   r?   r   r   r   r   r   r  s       r!   r   _Identifiers.visitBlockTag  s   yy ):):$))Y%5%566 11yy$))..2 ++ 
 		I--y/I/IJ  !11yy# ++  002E	!e==3F3F%%4 ' ##E*	 3   ##D$5$5t<OO."##D$4$4d;..0E""&&u- 1AT" r#   c                     UR                  5        HP  nUS:w  d  M  X R                  R                  U R                  5      ;  d  M5  U R                  R                  U5        MR     g r  )r#  r   r   r   r   r   r  s      r!   rV  _Identifiers.visitTextTag  sP    002E	!e==3F3F%%4 ' ##E*	 3r#   c                 &    U R                  U5        g r'   r  r   s     r!   r[  _Identifiers.visitIncludeTag  r  r#   c                     UR                  5        H  nU R                  R                  U5        M      U R                  U5        g r'   )r   r   r   r  r  s      r!   rt   _Identifiers.visitPageTag  s7    ..0E""&&u- 1D!r#   c                 &    U R                  U5        g r'   re  r   s     r!   rg  "_Identifiers.visitCallNamespaceTag  s    $r#   c                 ^   XR                   L a  UR                  5        HP  nUS:w  d  M  X R                  R                  U R                  5      ;  d  M5  U R
                  R                  U5        MR     UR                  5        H  nU R                  R                  U5        M      UR                   H  nUR                  U 5        M     g UR                  5        HP  nUS:w  d  M  X R                  R                  U R                  5      ;  d  M5  U R
                  R                  U5        MR     g r  )r   r#  r   r   r   r   r   r   r   r   r   r  s       r!   rf  _Identifiers.visitCallTag  s    99446I%%}}7J7J))8 + OO''.	 7
 224&&**51 5ZZ  &   446I%%}}7J7J))8 + OO''.	 7r#   )	r   r   r9   r   r   r   r   r   r   )NNF)r+   r,   r-   r.   r|  r)   r   r}  rQ   r  r  rx  r:  rO  ry   rq   r  r   r   rV  r[  rt   rg  rf  r/   r0   r#   r!   r   r     st    MAFA G G

-*
""''(#B+""
 /r#   r   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                    [        5       nU R                  U5        UR                  (       a  SU R                  S   l        [
        R                  U R                  5      nU(       a:  UR                  SUR                  S5      -  S5        SUR                  S5      -  nU$ [        SU R                  -  5      eU R                  nU$ )	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
Tr`   zloop = __M_loop._enter(%s)r   r   zfor %s in loop:r   zCouldn't apply loop context: %s)LoopVariabler   detectedr   rK  	_FOR_LOOPr,  r   rZ   r0  SyntaxError)r   r    loop_variabler,  r   s        r!   rL  rL    s     !NM&*.

2'		*,u{{1~=
 %u{{1~5D
 K ?$))KLLyyKr#   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r  i  zMA node visitor which looks for the name 'loop' within undeclared
identifiers.c                     SU l         g )NFr  ra   s    r!   r)   LoopVariable.__init__  s	    r#   c                     SUR                  5       ;   a  SU l        g UR                  5        H  nUR                  U 5        M     g )Nr   T)r#  r  rM  r   r  s      r!   _loop_reference_detected%LoopVariable._loop_reference_detected  s;    T0022 DM&&(  & )r#   c                 &    U R                  U5        g r'   r  r   s     r!   rO  LoopVariable.visitControlLine       %%d+r#   c                 &    U R                  U5        g r'   r  r   s     r!   ry   LoopVariable.visitCode#  r  r#   c                 &    U R                  U5        g r'   r  r   s     r!   r:  LoopVariable.visitExpression&  r  r#   r  N)r+   r,   r-   r.   r|  r)   r  rO  ry   r:  r/   r0   r#   r!   r  r    s     ',,,r#   r  )r|  r[   r   r   makor   r   r   r   r   
mako.pygenr   r   r   r   RESERVED_NAMES	frozensetr"   r   r   r   r  rL  r  r0   r#   r!   <module>r     s     	       $ 
 !"23 V$**+<= ;%P- -8[
 [
|k/ k/\ JJ&	., ,r#   