
    YeIix                     ^   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                    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dS )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	          |||||||||	|
|          |            |                                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                 Q/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/mako/codegen.pycompiler"      sw    " 
!
#
#CC  G"	
 	
 	  " <<>>    c                       e Zd Zd ZdS )r   c                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        d S 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   s_      .,,.&<# 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dS )!r   zZA template visitor object which generates the
    full module source for a template.

    c                 8   || _         || _        || _        d g| _        t	          |t
          j        t
          j        f          | _        | j        rd|j	        z  }|
                                }t          |j        j                  dk    }t          |j                            dd                    }t          |j                            dd                    }d }	d }
|j        r|j        s|dgz  }n|                                 }	| j        j        }
d}|
|
j        
                                }|
j        j        s|dgz  }t          |
j                            dd                    }| j        j        p't          |
j                            dd                    | j        _        ndg}d	}d	x}}|d
g}nd d
g|z   D             }|                     |
p||||||           |	|	D ]}t3          |||           | j        s|                                  d S d S )Nz	render_%sr   bufferedFalsecached
**pageargsrender_bodyr   Fr   c                     g | ]}|S r,   r,   .0as     r!   
<listcomp>z2_GenerateRenderMethod.__init__.<locals>.<listcomp>   s    222!A222r#   )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   filteredr/   r1   defsrJ   s              r!   r(   z_GenerateRenderMethod.__init__j   sU    	!% 	(8):L'MNN; 	(.D0022D4+011A5HDO//
GDDEEH$/--h@@AAFDG} 'T%6 '&&&((Dm+G D"(AACC(/ +\N*Dg044XwGGHH,0M,E -&**='BBJ J)) %~"''Hx<;DD22	{T1222D""OtT48V	
 	
 	
  ? ?%gx>>>>{ 	)&&(((((	) 	)r#   c                 "   t          | j        j                  | j        j        | j        j        <   | j        j        | j        j        | j        j        | j        j        d}| j                            ddt          j
        |          d           d S )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   z+_GenerateRenderMethod.write_metadata_struct   s    7:L#8
 8
 34 .=$#}</	
 
 	 Jv&		
 	
 	
 	
 	
r#   c                     | j         d         S )N)r:   r'   s    r!   identifiersz!_GenerateRenderMethod.identifiers   s    $R((r#   c                 0	    g i g d j         _         G  fdd          } |            } j        j        D ]}|                    |            j         _        t                      }D ])}|                    |                                          }*t           j                   }||_
         j         j        r3 j         j        r' j                            d j         j        z              j         j        r: j                            dd                     j         j                              j                            d            j                            d            j                            d	            j                            d
            j                            d            j                            dt"          z              j                            dt%          j                    z              j                            d j         j        z              j                            d j         j        z              j                            d j         j        z              j                            d j         j        z              j         j        rMd} j         j        D ]$}||dz   z  } j                            |           %t/          j        |dddd          }nd}|                     j                  }	|j        }
|
                    |	j                  |_        |j
                            t8                     |r|j
                            |j                   | j         _         j                            dd |	j                                        D             z              j                            d           tA                    r !                               tA                    r1 "                                #                    d                    n$tA                    r "                               tI          |	j                                                  S )zxTraverse a template structure for module-level directives and
        generate the start of module-level code.

        Nc                   8    e Zd Z fdZfdZfdZfdZdS ):_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevelc                 2                         |           d S r&   )append)sr   inherits     r!   visitInheritTagzJ_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitInheritTag   s    t$$$$$r#   c                     ||j         <   d S r&   rO   )re   r   
namespacess     r!   visitNamespaceTagzL_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitNamespaceTag   s    (,
49%%%r#   c                      |j         _        d S r&   )r9   rJ   )re   r   r'   s     r!   visitPageTagzG_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitPageTag   s    (,%%%r#   c                 D    |j         r                    |           d S d S r&   )ismodulerd   )re   r   module_codes     r!   	visitCodezD_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitCode   s1    = -&&t,,,,,- -r#   N)r)   r*   r+   rg   rk   rm   rq   )rf   rp   rj   r'   s   r!   FindTopLevelrb      sy        % % % % %- - - - -- - - - -- - - - - - -r#   rr   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)sourcerW   posr   z_exports = %rc                     g | ]	}|j         
S r,   ri   )r6   ns     r!   r8   z8_GenerateRenderMethod.write_toplevel.<locals>.<listcomp>  s    FFF!qvFFFr#      r]   )%r9   rJ   r   nodesaccept_visitorrj   setuniondeclared_identifiers_Identifiersdeclaredr   r   r    	writeliner   joinMAGIC_NUMBERtimer   r   r   r   r   
PythonCodebranchtopleveldefsupdateTOPLEVEL_DECLAREDr_   valueswrite_blanksrA   write_module_codewrite_namespaceswrite_inheritlist)r'   rr   fry   module_identmodule_identifiersr   impimpcodemain_identifiersmitrf   rp   rj   s   `          @@@r!   rI   z$_GenerateRenderMethod.write_toplevel   s   
 
 $	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- LNN 	  	 AQ#- uu 	H 	HA'--a.D.D.F.FGGLL)$-88&2# M0	-	 L""%(EE   =' 	L"""99T]9:::=   	IJJJ>???HIII8999<===3lBCCC4ty{{BCCC2T]5NNOOO%(>>	
 	
 	
 	3dm6GGHHH#dm&CC	
 	
 	
 =  	C}, , ,sTz!&&s++++n3  GG G-44TY?? -*-)))+
 +
' 	#**+<=== 	M'..w/KLLL$6!FF/<CCEEFFFG	
 	
 	
 	!!!$$${ 	0"";///w<< 	.!!*---wr{++++__ 	.!!*---$188::;;;r#   c                    | j         r&|j        }|r| j                            d|z             | j                            |j                   | j                            d|dd                    |          ddd           |s|s|r| j                            d           | j        	                    | j
        j                            | j                             | j         r| j        j        r)d	|v r%| j        d
         j                            d           | j         s~t#          | j        j                  dk    st#          | j        j                  dk    rD| j                            dd                    d | j        j        D                       z             |                     | j        d           | j        j        D ]}|                    |            |                     | j        |||           | j                            d           | j                            d           |r"|                     ||||| j        d           dS dS )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   r]   pageargsr   z!__M_locals = __M_dict_builtin(%s)c                     g | ]	}|d |
S )=r,   r6   xs     r!   r8   z?_GenerateRenderMethod.write_render_callable.<locals>.<listcomp>B  s3        $%11aa(  r#   T)toplevelNrz   )r>   	decoratorr    r   start_sourcerW   rX   r   r:   rd   r9   r_   r   r   rG   argument_declaredaddrA   locally_assignedwrite_variable_declaresr{   r|   write_def_finishr   write_cache_decorator)	r'   r   rO   rC   r/   rP   r1   r   ry   s	            r!   rM   z+_GenerateRenderMethod.write_render_callable  s    ; 	I &&5	A   	!!$+...!TT388D>>>>2=		
 	
 	
  	=x 	=6 	=L""#;<<<$$M%,,TY77	
 	
 	
  	Hty1 	H|t7K7K!"%7;;JGGG{ 	 122Q664#566::L""3(( !%!1!C      	$$T%5$EEE 	# 	#AT""""di8VDDDt$$$!!!$$$ 	&&dD(D,<t '     	 	r#   c                 \    |D ](}| j                             |j        |j                   )dS )zewrite module-level template code, i.e. that which
        is enclosed in <%! %> tags in the template.starting_linenoN)r    write_indented_blocktextrW   )r'   rp   ry   s      r!   r   z'_GenerateRenderMethod.write_module_codeV  sC      	P 	PAL--afah-OOOO	P 	Pr#   c                 \    | j                             ddd|j        d         z  d           dS )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    rX   parsed_attributesr'   r   s     r!   r   z#_GenerateRenderMethod.write_inherit\  sD     	30F%f-/	
 	
 	
 	
 	
r#   c                      j                             dddddddd            j                             d           |                                D ]n}d|j        v rd	 j        _         j                             |j                   t          |j
                  rЉ j                             d
           g  j        j                            |          d	 _         G  fdd          } |            }|j
        D ]}|                    |            j                             dd                              z              j                             d           d _        d}nd}d|j        v rC j                             d|j        d|j                            dd          d|d           nrd|j        v rC j                             d|j        d|d|j                            dd          d           n& j                             d|j        d|d           t'          |j                            dd                    r" j                             d |j        z              j                             d!t)          |j                  z              j                             d"           pt          |          s j                             d#            j                             d           dS )$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dS )<_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitorc                 0    |                      |           d S r&   visitDefOrBasere   r   s     r!   visitDefTagzH_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitDefTag      ((.....r#   c                 0    |                      |           d S r&   r   r   s     r!   visitBlockTagzJ_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitBlockTag  r   r#   c                     |j         rt          j        	 di |j                            |d                               |j                   d S )N.Can't put anonymous blocks inside <%namespace>Fnested)r   )rH   r   CompileExceptionexception_kwargswrite_inline_defrd   r?   )re   r   exportr_   r'   s     r!   r   zK_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitDefOrBase  sq    , ","=!/# # #'"7# # 
 --dK-NNNdm44444r#   Nr)   r*   r+   r   r   r   )r   r_   r'   s   r!   NSDefVisitorr     sV        / / // / /5 5 5 5 5 5 5 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)inheritabler0   zcontext['self'].%s = nsz'context.namespaces[(__name__, %s)] = ns   pass)r    rX   r   r   rE   r9   has_ns_importsr   rW   rA   r{   r_   r   r>   r|   r   r   rO   rF   rD   reprr   )	r'   rj   r   r   visry   callable_namer   r_   s	   `      @@r!   r   z&_GenerateRenderMethod.write_namespacesg  sm   5909		
 		
 		
 	HIII%%'' J	) J	)D4?**/3,L%%dk2224: '&&'>???"m7>>tDD"5 5 5 5 5 5 5 5 5 5 5 5" #lnn * *A$$S))))&&}8H8H'IJJJ&&t,,,# 2 &///&&& 			.2266BBBB%
 
 
 
 T333&&& 			%.228VDDDD
 
 
 
 &&& yyy---1   DO''w??@@ P&&'@DI'NOOOL""9DOOK   L%%a((((: 	+L""6***t$$$$$r#   FNc                    d |j         D             }t                      }|                    |j                  }|                    d |j                                        D                       }|                    |j                  }|                    |j                  }| j	        j
        rd|v }|                    d           nd}||                    |          }|rt          | j	        dd          r| j                            d           d| j	        _        | j	        j                                        D ]M\  }}d	|j        v r?| j                            d
|dt)          j        d|j        d	                   d           N|r| j                            d           |D ]}||v r||         }	|	j        r7|	j        s|                     |	|           4|                     |	|d           M|	                                r|                     |	|           x|                     |	|d           || j	        j        v r!| j                            |d|d           t          | j	        dd          rf| j	        j        r5| j                            |d|dd|z  d|d|ddd|z  dd           | j                            |d|d|d           <| j	        j        r)| j                            d|d|ddd|z  d           q| j                            |d|d           | j                            d           dS )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.

        c                     i | ]
}|j         |S r,   r?   r6   cs     r!   
<dictcomp>zA_GenerateRenderMethod.write_variable_declares.<locals>.<dictcomp>  s    ???qz1???r#   c                     g | ]	}|j         
S r,   r   r   s     r!   r8   zA_GenerateRenderMethod.write_variable_declares.<locals>.<listcomp>  s    BBBAQZBBBr#   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~   
undeclaredclosuredefsr   
differencer   locally_declaredr9   r   discardintersectiongetattrr    r   has_importsrj   itemsrE   resplitrG   rH   write_def_declr   is_rootr   rX   )
r'   r_   r   limitcomp_identsto_writehas_loopidentnscomps
             r!   r   z-_GenerateRenderMethod.write_variable_declares  s   ( @?k.>???55 >>+"899 >>BB!8!?!?!A!ABBB
 
 &&{'DEE &&{'CDD=$ 	)HV$$$$H ,,U33H 	/?GG 	L""#4555(,DM%!]5;;== 	 		rr},,L*** "EEHZx1HIIII	    	LL""#JKKK 2	 2	E##"5)= 	N, N++D+>>>>--dK-MMMM||~~ N++D+>>>>--dK-MMMM$-222&&?DuueeeL    4=*:EBB }5 //$uueee-1E9"27%%?.FN  
 
 
 
 ..  %uueeeUUU4    }5 //"27%%?.FN     ..AFN    	>?????r#   c                 H   |j         }|                                }|                    d          }| j        sQt          | j        j                  dk    st          | j        j                  dk    r|                    dd           n|                    dd           | j        	                    d|dd
                    |          d	           | j        	                    d
|dd
                    |          d           | j        	                    d           dS )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   r_   r   r   insertr    r   r   )r'   r   r_   r?   	namedeclsnameargss         r!   r   z$_GenerateRenderMethod.write_def_declB  s%   =1133	000>>{ 	* 122Q664#566::OOA<====OOAy)))#((9:M:M:M:MNOOO&.hh0B0B0B0BC	
 	
 	
 	t$$$$$r#   c           	         |                                 }|j        }|r| j                            d|z             | j                            d|j        dd                    |          d           t          |j        j                  dk    }t          |j
                            dd                    }t          |j
                            d	d                    }| j                            d
d           |s|s|r| j                            d           |                    ||          }|                     |           | j                            |           |j        D ]}	|	                    |            | j                                         |                     ||||           | j                            d           |r#|                     ||j        |d|dd           dS dS )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   rA   rB   rC   rD   rE   rF   rX   r   r   r:   rd   r{   r|   popr   r   )
r'   r   r_   r   r   r   rP   r/   r1   ry   s
             r!   r   z&_GenerateRenderMethod.write_inline_defU  s,    1133	N	 	L""89D   	!]]]CHHY,?,?,?,?@	
 	
 	
 t',--1++J@@AAdo))(G<<===	
 	
 	

  	>x 	>6 	>L##$<===!((f(==$$[111$$[111 	# 	#AT""""!!###dHh???t$$$ 		&& '     		 		r#   Tc                    |s<|s:|s8| j                             d           |r| j                             ddd           |s|s|r|s|r| j                             dd           n| j                             dd           |r| j                             d           d}|r!|                     |j        j        |d          }| j                             d           |r#|s!|                     | j        j        |d          }|s|r| j                             d	|z             dS | j                             d
|z  d           dS dS )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   rX   create_filter_callablerB   rC   r9   r   )r'   r   r/   rP   r1   	callstackre   s          r!   r   z&_GenerateRenderMethod.write_def_finish  s     	 	x 	L"";/// '' CT    	Kx 	K6 	K 6 
 '' A    ''L  
  L&&'JKKK$A //$)1e  L""4(((  //M0!U   K6 K&&{Q77777''(81(<kJJJJJ?	K 	Kr#   c                      j                             d|d|           j                            dt	          |                    }i }	 j        j        0|	                     fd j        j        j        D                        |	                    fdj        D                        d|	v r%t          t          |	d                             |	d<    j                             d|d	d

                    |          d           d |D             }
                     ||                                           |rd|d|d	d

                    |
          dd
                    d |	                                D                       d|d}                      j        j        |d          } j                             d|z   d           dS  j                             d|d|d	d

                    |
          dd
                    d |	                                D                       d|ddd           dS )zhwrite a post-function decorator to replace a rendering
        callable with a cached version of itself.__M_z = 	cache_keyNc              3      K   | ]@}|                     d           r)|dk    |dd         j        j        j        |         fV  AdS cache_r	     N)
startswithr9   rJ   r   )r6   par'   s     r!   	<genexpr>z>_GenerateRenderMethod.write_cache_decorator.<locals>.<genexpr>  sj        ==** 02[/@/@ ABB.@DE/@/@/@/@ r#   c              3   |   K   | ]6}|                     d           r|dk    |dd         j        |         fV  7dS r  )r  r   )r6   r  node_or_pagetags     r!   r  z>_GenerateRenderMethod.write_cache_decorator.<locals>.<genexpr>  se       
 
}}X&&
 ,.+<+< V_6r:;+<+<+<+<
 
r#   timeoutr   r   r   r   c                 ^    g | ]*}d |v r"d|                     d           d         fdz  z  n|+S )r   z%s=%sr   rz   )r   r5   s     r!   r8   z?_GenerateRenderMethod.write_cache_decorator.<locals>.<listcomp>  sM     
 
 
FG#((GQ)A-..
 
 
r#   )r   r   z.context.get('local').cache._ctx_get_or_create(z, lambda:__M_z),  context, rt   c                 $    g | ]\  }}|d |dS r   rs   r,   r6   kvs      r!   r8   z?_GenerateRenderMethod.write_cache_decorator.<locals>.<listcomp>  )    KKK1aaa+KKKr#   z__M_defname=r   Fzreturn z9__M_writer(context.get('local').cache._ctx_get_or_create(z), context, c                 $    g | ]\  }}|d |dS r  r,   r  s      r!   r8   z?_GenerateRenderMethod.write_cache_decorator.<locals>.<listcomp>  r  r#   z))r   )r    r   r   rF   r   r9   rJ   r   intrD   r   r   undeclared_identifiersr   r  r   rX   )r'   r  rO   rC   r/   r_   r   r   cachekey
cache_args	pass_argsre   s   ``          r!   r   z+_GenerateRenderMethod.write_cache_decorator  s    	dd;<<<"488d
 
 
= ,    -/A     
 	 
 
 
 
%7
 
 
 	
 	
 	

 
""$'Z	-B(C(C$D$DJy!chhtnnnnEFFF
 
KO
 
 
	 	$$!88:: 	% 	
 	
 	

  $	 $	 HHDDHHY''''GGKK
8H8H8J8JKKK    DD  ++,a A L##IM488888L###
 HHDDHHY''''GGKK
8H8H8J8JKKK    DD     r#   c                 h   d }d|vrF|rD| j         j        r| j         j        j        j        |z   }| j         j        rd|vr| j         j        |z   }|D ]a}|dk    r	t          j        d|          }|r*|                    dd          \  }} ||          }	|	|z   }n ||          }|J |d|d}b|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                 v    t          j        d|           rd| z   S t          j                            | |           S )Nz
decode\..+zfilters.)r   matchr   DEFAULT_ESCAPESrF   ri   s    r!   locate_encodezC_GenerateRenderMethod.create_filter_callable.<locals>.locate_encode  s:    xt,, ?!D((.224>>>r#   ry   z(.+?)(\(.*\))r   rz   Nr   r   )r9   rJ   rB   rC   r   r   r#  group)
r'   rC   targetis_expressionr%  emr   fargsr   s
             r!   r  z,_GenerateRenderMethod.create_filter_callable	  s   
	? 	? 	? d?? @=( I=0<ADHD=0 @S__=84?D 	, 	,ACxx)1--A % wwq!}}u!M%((I!M!$$}}}!"FFF+FFr#   c                    | j                             |j                   t          |j                  sH| j        j        #t          | j        j        j        j                  st          | j        j	                  rH| 
                    |j        j        d|j        z  d          }| j                             d|z             d S | j                             d|j        z             d S )Nz%sTr  )r    r   rW   rA   escapesr9   rJ   rB   rC   r   r  escapes_coder   r   )r'   r   re   s      r!   visitExpressionz%_GenerateRenderMethod.visitExpression)  s    !!$+...	A %1-9>?? 2 4=011 2
 ++!&ty(8$ A L""#3a#788888L""#3di#?@@@@@r#   c                    j         rs| j                            d            j        rP| j                            d           | j                            d           | j                            d            d S d S | j                            j                   | j        j        r!j        dk    rt          | j                  }nj
        }| j                            |                                           fd}r>t          d D                       rt          fdD                       s
 |            r| j                            d           d S d S )Nr  zloop = __M_loop._exit()forc                      D ]<} t          | t          j                  rt          | t          j                  r dS  dS d S )NTFr;   r   CommentControlLine)r   childrens    r!   _search_for_control_linezH_GenerateRenderMethod.visitControlLine.<locals>._search_for_control_lineP  sW    ! ! !A!!Y%677 $ #Ay'<== $#tt 55! !r#   c              3   b   K   | ]*}t          |t          j        t          j        f          V  +d S r&   r3  r   s     r!   r  z9_GenerateRenderMethod.visitControlLine.<locals>.<genexpr>Z  sK         q9#4i6K"LMM     r#   c              3      K   | ]?}t          |t          j                                      |j                  p|j        V  @d S r&   )r;   r   r5  
is_ternarykeywordisend)r6   r   r   s     r!   r  z9_GenerateRenderMethod.visitControlLine.<locals>.<genexpr>^  s_        !!Y%:;;__QY//:17     r#   r   )r<  r    r   has_loop_contextr   rW   r9   r   r;  mangle_mako_loopr   get_childrenall)r'   r   r   r7  r6  s    `  @r!   visitControlLinez&_GenerateRenderMethod.visitControlLine:  s   : *	/L""4((($ -&&z222&&'@AAA&&t,,,,,- -
 L%%dk222}( !T\U-B-B'dl;;yL""4(((((**H! ! ! ! ! /  %    /     %    / ,+--/ &&v...../ /r#   c                     | j                             |j                   | j                             dt	          |j                  z             d S )Nr  )r    r   rW   r   r   contentr   s     r!   	visitTextz_GenerateRenderMethod.visitTextg  sF    !!$+.../$t|2D2DDEEEEEr#   c           
      >   t          |j        j                  dk    }|r| j                            dd           |j        D ]}|                    |            |rA| j                            ddd|                     |j        j        dd          z  d            d S d S )	Nr   z#__M_writer = context._push_writer()r   r  r  r  r  F)rA   rB   rC   r    rX   r{   r|   r  )r'   r   rP   ry   s       r!   visitTextTagz"_GenerateRenderMethod.visitTextTagk  s    t',--1 	L##5v    	# 	#AT"""" 		L##H --$)+?      		 		r#   c                    |j         s| j                            |j        |j                   | j        st          | j        j                  dk    rl| j        	                    d           | j        	                    dd
                    d |                                D                       z             d S d S d S d S )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   c                 ,    g | ]}t          |          S r,   )r   r   s     r!   r8   z3_GenerateRenderMethod.visitCode.<locals>.<listcomp>  s    MMMAQMMMr#   )ro   r    r   r   rW   r>   rA   r_   r   r   r   r   r   s     r!   rq   z_GenerateRenderMethod.visitCode~  s    } 	L--	4; .    ; 3t'7'H#I#IA#M#M
 &&F   &&G hhMM1J1J1L1LMMMNNO    	 	
 #M#Mr#   c                 (   | j                             |j                   |j                            d          }|r.| j                             d|j        d         d|d           d S | j                             d|j        d         z             d S )NrC   zruntime._include_file(context, r   z, _template_uri, r   z1runtime._include_file(context, %s, _template_uri))r    r   rW   rE   rF   r   r   )r'   r   rC   s      r!   visitIncludeTagz%_GenerateRenderMethod.visitIncludeTag  s    !!$+...""6** 		L""")&1114449    
 L""C)&13    r#   c                     d S r&   r,   r   s     r!   rk   z'_GenerateRenderMethod.visitNamespaceTag      r#   c                     d S r&   r,   r   s     r!   r   z!_GenerateRenderMethod.visitDefTag  rL  r#   c                 ~   |j         r$| j                            d|j        z             d S |                    d          }|dgz  }| j                            d|j        z             | j                            d|j        dd                    |          d	           | j                            d
           d S )Nz%s()Tr   r2   zOif 'parent' not in context._data or not hasattr(context._data['parent'], '%s'):zcontext['self'].r   r   r   ru   )rH   r    r   r?   r@   r   )r'   r   r   s      r!   r   z#_GenerateRenderMethod.visitBlockTag  s     	)L""6DM#9:::::44T4BBH&HL"">@DN   L""",0MMM388H;M;M;M;MN   L""4(((((r#   c                 0    |                      |           d S r&   visitCallTagr   s     r!   visitCallNamespaceTagz+_GenerateRenderMethod.visitCallNamespaceTag  s     	$r#   c                    	  j                             d           dg	 j                            |d                              |d                              d            j                                        G 	 fdd          } |            }|j        D ]}|                    |            j        	                                 |j
                                        } j                             d	d
                    |          z             d}|r j                             dd                                            j                                       |j        D ]}|                                 j        	                                                      ||ddd            j                             d dd
                    	          z  d             j                             dd            j                             |j                    j                             d                     g |j        d          z  ddd            d S )Nzdef ccall(caller):bodyTr   Fcallerc                   ,    e Zd Zd Zd Z fdZdS )6_GenerateRenderMethod.visitCallTag.<locals>.DefVisitorc                 0    |                      |           d S r&   r   r   s     r!   r   zB_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitDefTag        &&&&&r#   c                 0    |                      |           d S r&   r   r   s     r!   r   zD_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitBlockTag  rY  r#   c                                          |d           |j        s                    |j                   |j        j        v rj        |j        = d S d S )NFr   )r   rH   rd   r?   r   )re   r   body_identifierscallable_identifiersr   r'   s     r!   r   zE_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitDefOrBase  sm    %%d,@%OOO( 1MM$-000 =$4$@@@(4T]CCC A@r#   Nr   )r\  r]  r   r'   s   r!   
DefVisitorrW    se        ' ' '' ' 'D D D D D D D D D Dr#   r^  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_declaredr:   rd   r{   r|   r   rK   r@   r   rX   r   r   r   rW   r  
expression)
r'   r   r^  r   ry   bodyargsr/   r\  r]  r   s
   `      @@@r!   rQ  z"_GenerateRenderMethod.visitCallTag  s   3444#/66tD6II/66tE6JJ
 	%%h///$$%5666	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D  jll 	" 	"AS!!!!!!###>::<<(1C1CCDDD  	FL##$<fEEE$$%5666$$%5666 	# 	#AT""""!!###dHeUeLLLmsxx7G7G&H$OOO+ 	
 	
 	
 	!!$+...))"dotDDE4	
 	
 	
 	
 	
r#   )FN)T)FF)r)   r*   r+   __doc__r(   rN   propertyr_   rI   rM   r   r   r   r   r   r   r   r   r  r/  rA  rD  rF  rq   rJ  rk   r   r   rR  rQ  r,   r#   r!   r   r   c   s        
/) /) /)b
 
 
" ) ) X)k< k< k<Z7 7 7rP P P	
 	
 	
[% [% [%z|@ |@ |@ |@|% % %&, , ,^ ;?1K 1K 1K 1Kt Q Q Q Qf  @A A A"+/ +/ +/ZF F F  &  *      ) ) )     B
 B
 B
 B
 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dS )r   zCtracks the status of identifier names as template code is rendered.NFc                    |t          |t          j                  r,t                      | _        t          j                    | _        nt          |j                                      d |j	        
                                D                                           |j                                      |j                  | _        |r$| j                            |j                  | _        t          j        di |j        | _        n+t                      | _        t          j                    | _        || _        t                      | _        t                      | _        t                      | _        t                      | _        t          j                    | _	        || _        ||                    |            | j        j                            | j                  }|r*t)          j        dd                    |          z            d S )Nc                     g | ]	}|j         
S r,   ri   r   s     r!   r8   z)_Identifiers.__init__.<locals>.<listcomp>  s    HHHqAFHHHr#   z'Reserved words declared in template: %srs   r,   )r;   r   NamespaceTagr}   r   r   SetLikeDictr   r~   r   r   r   r   r   r9   r   r   r|   r   r   r   NameConflictErrorr   )r'   r9   r   parentr   illegal_namess         r!   r(   z_Identifiers.__init__  s    $	 677 L #$($4$6$6!!
 ((UHHF,>,E,E,G,GHHHIIU6233U6344	   K$(M$7$78I$J$JDM %)$4$K$Kv7J$K$K!!EEDM $ 0 2 2D  %%
 !$
 !$ "%  +--	%%%4AA!
 
  	.9))M**+  	 	r#   c                 *    t          | j        || fi |S )zUcreate a new Identifiers for a new Node, with
        this Identifiers as the parent.)r   r9   )r'   r   rL   s      r!   r   z_Identifiers.branchH  s      DM4@@@@@r#   c                 ~    t          | j                            | j                                                            S r&   )r}   r   r~   r   r   r^   s    r!   rQ   z_Identifiers.defsN  s0    4$**4+;<<CCEEFFFr#   c                 &   dt          | j                  dt          | j                  dt          | j                  dd | j                                        D             dd | j                                        D             d| j        d	S )
NzIdentifiers(declared=z, locally_declared=z, undeclared=z, topleveldefs=c                     g | ]	}|j         
S r,   ri   r   s     r!   r8   z)_Identifiers.__repr__.<locals>.<listcomp>[  s    <<<A<<<r#   z, closuredefs=c                     g | ]	}|j         
S r,   ri   r   s     r!   r8   z)_Identifiers.__repr__.<locals>.<listcomp>\  s    ;;;A;;;r#   z, argumentdeclared=r   )r   r   r   r   r   r   r   r   r^   s    r!   __repr__z_Identifiers.__repr__R  s      T]####T*++++T_%%%%<<!2!9!9!;!;<<<<<;;!1!8!8!:!:;;;;;&&&
	
r#   c                    |                                 D ]C}|dk    r;|| j                            | j                  vr| j                            |           D|                                D ]}| j                            |           dS )zlupdate 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_declaredz_Identifiers.check_declareda  s     0022 	+ 	+E	!!e4=3F3F%4 4 ' ' ##E***..00 	- 	-E!%%e,,,,	- 	-r#   c                     | j                             |           || j        v r| j                            |           d S d S r&   )r   r   r   remove)r'   r   s     r!   r_  z_Identifiers.add_declaredm  sI    %   DO##O""5))))) $#r#   c                 0    |                      |           d S r&   rt  r   s     r!   r/  z_Identifiers.visitExpressionr      D!!!!!r#   c                 0    |                      |           d S r&   rx  r   s     r!   rA  z_Identifiers.visitControlLineu  ry  r#   c                     |j         sH|                     |           | j                            |                                          | _        d S d S r&   )ro   rt  r   r~   r   r   s     r!   rq   z_Identifiers.visitCodex  sZ    } 	%%%$($9$?$?))++% %D!!!	 	r#   c                 Z    | j         |u r|j        D ]}|                    |            d S d S r&   )r   r{   r|   r'   r   ry   s      r!   rk   z_Identifiers.visitNamespaceTag  sK     9Z ' '  &&&& ' 'r#   c                     |                     |j                  }|||j        <   |1||ur/|j        s|j        r#t          j        d|j        z  fi |j        d S d S d S )Nz<%%def or %%block named '%s' already exists in this template.)rF   r?   rG   r   r   r   )r'   
collectionr   existings       r!   _check_name_existsz_Identifiers._check_name_exists  s    >>$-00$(
4=! $$ %"*"3 % -+-1];  '  	 ! $$$$r#   c                 "   |                                 r#|j        s|                     | j        |           n$|| j        ur|                     | j        |           |                                D ]C}|dk    r;|| j                            | j	                  vr| j
                            |           D|| j        u rP|                                D ]}| j                            |           |j        D ]}|                    |            d S d S Nr   )r   rH   r  r   r   r   r  r   r~   r   r   r   r   r   r{   r|   r'   r   r   ry   s       r!   r   z_Identifiers.visitDefTag  sA   <<>> 	<$"3 	<##D$5t<<<<""##D$4d;;;0022 	+ 	+E	!!e4=3F3F%4 4 ' ' ##E*** 492244 2 2&**51111Z ' '  &&&& ' 'r#   c                 p   || j         ur|j        st          | j         t          j                  r-t          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        |                                D ]C}|dk    r;|| j                            | j                  vr| j                            |           D|j        s;|                     | j        |           | j                            |j                   n$|| j         ur|                     | j        |           |                                D ]}| j                            |           |j        D ]}|                    |            d S )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   z_Identifiers.visitBlockTag  s   ty  ): $)Y%566  11yyy$)...2  +  
 	I-y/IJ   !11yyy#  +   0022 	+ 	+E	!!e4=3F3F%4 4 ' ' ##E***  	<##D$5t<<<O....""##D$4d;;;..00 	. 	.E"&&u---- 	# 	#AT""""	# 	#r#   c                     |                                 D ]C}|dk    r;|| j                            | j                  vr| j                            |           Dd S r  )r  r   r~   r   r   r   rs  s      r!   rF  z_Identifiers.visitTextTag  sq    0022 	+ 	+E	!!e4=3F3F%4 4 ' ' ##E***		+ 	+r#   c                 0    |                      |           d S r&   rx  r   s     r!   rJ  z_Identifiers.visitIncludeTag  ry  r#   c                     |                                 D ]}| j                            |           |                     |           d S r&   )r   r   r   rt  rs  s      r!   rm   z_Identifiers.visitPageTag  sQ    ..00 	. 	.E"&&u----D!!!!!r#   c                 0    |                      |           d S r&   rP  r   s     r!   rR  z"_Identifiers.visitCallNamespaceTag  s    $r#   c                    || j         u r|                                D ]C}|dk    r;|| j                            | j                  vr| j                            |           D|                                D ]}| j                            |           |j	        D ]}|
                    |            d S |                                D ]C}|dk    r;|| j                            | j                  vr| j                            |           Dd S r  )r   r  r   r~   r   r   r   r   r   r{   r|   r  s       r!   rQ  z_Identifiers.visitCallTag  sL   494466 / /I%%%t}7J7J)8 8 + + O''...2244 2 2&**51111Z ' '  &&&&' ' 4466 / /I%%%t}7J7J)8 8 + + O''...	/ /r#   )NNF)r)   r*   r+   rb  r(   r   rc  rQ   rq  rt  r_  r/  rA  rq   rk   r  r   r   rF  rJ  rm   rR  rQ  r,   r#   r!   r   r     sE       MMA A A AFA A A G G X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                    t                      }|                     |           |j        rd| j        d         _        t
                              | j                  }|rE|                    d|	                    d          z  d           d|	                    d          z  }n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
    Tr]   zloop = __M_loop._enter(%s)rz   r   zfor %s in loop:r   zCouldn't apply loop context: %s)LoopVariabler|   detectedr{   r=  	_FOR_LOOPr#  r   rX   r&  SyntaxError)r   r    loop_variabler#  r   s        r!   r>  r>    s     !NNM&&& *.
2'	** 	M,u{{1~~=  
 %u{{1~~5DD?$)KLLLyKr#   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )r  zQA node visitor which looks for the name 'loop' within undeclared
    identifiers.c                     d| _         d S )NF)r  r^   s    r!   r(   zLoopVariable.__init__  s    r#   c                     d|                                 v r	d| _        d S |                                D ]}|                    |            d S )Nr   T)r  r  r?  r|   r}  s      r!   _loop_reference_detectedz%LoopVariable._loop_reference_detected  s`    T002222 DMMM&&(( ' '  &&&&' 'r#   c                 0    |                      |           d S r&   r  r   s     r!   rA  zLoopVariable.visitControlLine       %%d+++++r#   c                 0    |                      |           d S r&   r  r   s     r!   rq   zLoopVariable.visitCode#  r  r#   c                 0    |                      |           d S r&   r  r   s     r!   r/  zLoopVariable.visitExpression&  r  r#   N)	r)   r*   r+   rb  r(   r  rA  rq   r/  r,   r#   r!   r  r    si           ' ' ', , ,, , ,, , , , ,r#   r  )rb  rY   r   r   makor   r   r   r   r   
mako.pygenr   r   r   r~   RESERVED_NAMES	frozensetr"   r   r   r   r  r>  r  r,   r#   r!   <module>r     s     				                                $ $ $ $ $ $ 
 !"23 V$**+<== 9;;% % % %P- - - - - - - -8[
 [
 [
 [
 [
 [
 [
 [
|k/ k/ k/ k/ k/ k/ k/ k/\ BJ& 	  ., , , , , , , , , ,r#   