• File: codegen.cpython-37.opt-1.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/mako/__pycache__/codegen.cpython-37.opt-1.pyc
  • Date Modified: 06/27/2022 10:09 PM
  • File size: 32.09 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

C]@s
dZddlZddlZddlZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZd
Z
eddgZed
dgeZddddddddddefddZGdddeZGdddeZGdddeZedZddZGdddeZdS)zVprovides functionality for rendering a parsetree constructing into module
source code.N)ast)compat)
exceptions)filters)	parsetree)util)
PythonPrinter
Z	UNDEFINEDZSTOP_RENDERINGcontextloopTFc
CsZtjst|tjr||}t}
t|
}t|t	|||||||||	|
||||
S)z[Generate module source code given a parsetree node,
      uri, and optional source filename)rZpy3k
isinstanceZ	text_typeencoderZFastEncodingBufferr_GenerateRenderMethod_CompileContextgetvalue)nodeurifilenamedefault_filtersbuffer_filtersimportsfuture_importssource_encodinggenerate_magic_commentdisable_unicodestrict_undefinedenable_loopreserved_namesbufprinterr =/opt/alt/python37/lib/python3.7/site-packages/mako/codegen.pycompile s*
r"c@seZdZddZdS)rc

CsL||_||_||_||_||_||_||_||_|	|_|
|_	||_
||_dS)N)rrrrrrrrrrrr)
selfrrrrrrrrrrrrr r r!__init__Rsz_CompileContext.__init__N)__name__
__module____qualname__r$r r r r!rQsrc@seZdZdZddZddZeddZdd	Zd
dZ	dd
Z
ddZddZd7ddZ
ddZddZd8ddZd9ddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6ZdS):rz]A template visitor object which generates the
       full module source for a template.

    cCs||_||_||_dg|_t|tjtjf|_|jrd|j	}|
}t|jj
dk}t|jdd}t|jdd}d}	d}
|jr|js|dg7}n~|}	|jj}
d}|
dk	r|
j
}|
jjs|dg7}t|
jdd}|jjpt|
jdd|j_n
dg}d	}d	}}|dkr*d
g}nddd
g|D}||
pJ|||||||	dk	r~x|	D]}t|||qhW|js|dS)
Nz	render_%srbufferedFalsecachedz
**pageargsZrender_bodyrFr
cSsg|]}|qSr r ).0ar r r!
<listcomp>sz2_GenerateRenderMethod.__init__.<locals>.<listcomp>)rcompilerridentifier_stackrrDefTagZBlockTagin_deffuncnameget_argument_expressionslenfilter_argsargseval
attributesgetis_blockis_anonymouswrite_toplevelpagetag	body_declkwargsrwrite_render_callablerwrite_metadata_struct)r#rr.rnamer6filteredr(r*defsr=r r r!r$vsL







z_GenerateRenderMethod.__init__cCsRt|jj|jj|jj<|jj|jj|jj|jjd}|jddt	
|ddS)N)rrrZline_mapz"""Z__M_BEGIN_METADATAz__M_END_METADATA
""")maxrZ
source_maplinenor.rrr
writelinesjsondumps)r#structr r r!rAsz+_GenerateRenderMethod.write_metadata_structcCs
|jdS)N)r/)r#r r r!identifierssz!_GenerateRenderMethod.identifierscsgigdj_Gfdddt}|}xjjD]}||q>Wj_t}xD]}||	}qdWt
j}||_jjrjj
rjdjj
jjr҈jddjjfjdjdjd	jd
jdjdtjd
tjdjjjdjjjdjjjdjj
jjrd}x*jjD]}||d7}j|qWtj|ddddd}nd}|j}	|j}
|
|	j|_|jt|r|j|j	|j_jddd|	jDj dt!r^"t!r#$dnt!r#t%|	jS)zxTraverse a template structure for module-level directives and
        generate the start of module-level code.

        Ncs<eZdZfddZfddZfddZfddZd	S)
z:_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevelcs|dS)N)append)sr)inheritr r!visitInheritTagszJ_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitInheritTagcs||j<dS)N)rB)rNr)
namespacesr r!visitNamespaceTagszL_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitNamespaceTagcs|j_dS)N)r.r=)rNr)r#r r!visitPageTagszG_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitPageTagcs|jr|dS)N)ismodulerM)rNr)module_coder r!	visitCodeszD_GenerateRenderMethod.write_toplevel.<locals>.FindTopLevel.visitCodeN)r%r&r'rPrRrSrVr )rOrUrQr#r r!FindTopLevelsrWz# -*- coding:%s -*-zfrom __future__ import %sz, z(from mako import runtime, filters, cachezUNDEFINED = 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
rztemplate defined imports)sourcerFposrz
_exports = %rcSsg|]
}|jqSr )rB)r+nr r r!r-sz8_GenerateRenderMethod.write_toplevel.<locals>.<listcomp>rK)&r.r=objectrnodesaccept_visitorrQsetuniondeclared_identifiers_Identifiersdeclaredrrr	writelinerjoinMAGIC_NUMBERtimerrrrrZ
PythonCodebranchtopleveldefsupdateTOPLEVEL_DECLAREDrLvalueswrite_blanksr4write_module_codewrite_namespaces
write_inheritlist)r#rWfr\Zmodule_identZmodule_identifiersrZimpZimpcodeZmain_identifiersZmitr )rOrUrQr#r!r<s










z$_GenerateRenderMethod.write_toplevelc	Csh|jr |j}|r |jd||j|j|jd|d|fdd|sX|sX|rd|jd|j	|j
j|j
|jr|j
jrd|kr|jdjd	|jst|jjd
kst|jjd
kr|jdddd
|jjD|j|jddx|j
jD]}||qW||j
||||jd|jd|rd|j|||||jdddS)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)zdef %s(%s):,z/__M_caller = context.caller_stack._push_frame()ztry:zcontext._push_buffer()z
**pageargsrKZpageargsrz!__M_locals = __M_dict_builtin(%s)cSsg|]}d||fqS)z%s=%sr )r+xr r r!r-Osz?_GenerateRenderMethod.write_render_callable.<locals>.<listcomp>T)toplevelNr])r1	decoratorrrfstart_sourcerFrGrgr/rMr.rLrjrr:argument_declaredaddr4locally_assignedwrite_variable_declaresr_r`write_def_finishrowrite_cache_decorator)	r#rrBr6r(rCr*rxr\r r r!r@)sB
z+_GenerateRenderMethod.write_render_callablecCs&x |D]}|jj|j|jdqWdS)zewrite module-level template code, i.e. that which
        is enclosed in <%! %> tags in the template.)starting_linenoN)rwrite_indented_blocktextrF)r#rUr\r r r!rpbs
z'_GenerateRenderMethod.write_module_codecCs |jddd|jdddS)z:write the module-level inheritance-determination callable.z%def _mako_inherit(template, context):z"_mako_generate_namespaces(context)z8return runtime._inherit_from(context, %s, _template_uri)fileN)rrGparsed_attributes)r#rr r r!rrhs
z#_GenerateRenderMethod.write_inheritc
sjddddddddjdx|D]z}d|jkrJd	j_j|jt	|j
rjd
gjj|d	_
Gfdddt}|}x|j
D]}||qWjd
djdd_
d}nd}d|jkr jd|j|jdd|fnFd|jkrPjd|j||jddfnjd|j|ft|jddrjd|jjdt|jjdq2Wt	|sȈjdjddS)z5write the module-level namespace-generating callable.z'def _mako_get_namespace(context, name):ztry:z+return context.namespaces[(__name__, name)]zexcept KeyError:z"_mako_generate_namespaces(context)Nz'def _mako_generate_namespaces(context):importTzdef make_namespace():cs,eZdZddZddZfddZdS)z<_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitorcSs||dS)N)visitDefOrBase)rNrr r r!visitDefTagszH_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitDefTagcSs||dS)N)r)rNrr r r!
visitBlockTagszJ_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitBlockTagcs4|jrtjd|jj|dd|jdS)N.Can't put anonymous blocks inside <%namespace>F)nested)r)r;rCompileExceptionexception_kwargswrite_inline_defrMr2)rNr)exportrLr#r r!rszK_GenerateRenderMethod.write_namespaces.<locals>.NSDefVisitor.visitDefOrBaseN)r%r&r'rrrr )rrLr#r r!NSDefVisitorsrzreturn [%s]ruFzmake_namespace()Nonerzns = runtime.TemplateNamespace(%r, context._clean_inheritance_tokens(), templateuri=%s, callables=%s,  calling_uri=_template_uri)modulezyns = runtime.ModuleNamespace(%r, context._clean_inheritance_tokens(), callables=%s, calling_uri=_template_uri, module=%s)zhns = runtime.Namespace(%r, context._clean_inheritance_tokens(), callables=%s, calling_uri=_template_uri)Zinheritabler)zcontext['self'].%s = nsz'context.namespaces[(__name__, %s)] = nspass)rrGrfrnr8r.has_ns_importsryrFr4r_rLrjr1r^r`rgrrBr9r7reprro)r#rQrrvisr\Z
callable_namer )rrLr#r!rqssf


z&_GenerateRenderMethod.write_namespacesFNc
Csbtdd|jD}t}||j}|dd|jD}||j}||j	}|j
jrtd|k}|dnd}|dk	r|
|}|rt|j
ddr|jdd	|j
_xD|j
jD]4\}}d
|jkr|jd|td|jd
fqW|r|jd
xF|D]<}||kr||}	|	jrX|	jsF||	|n|j|	|d	dn(|	rp||	|n|j|	|d	dn||j
jkr|jd||fnt|j
ddr|j
jr|jd||fd|dd||fdd|ddn|jd|||fn@|j
jr8|jdd||fdd|dn|jd||fqW|jddS)awrite 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.

        cSsg|]}|j|fqSr )r2)r+cr r r!r-szA_GenerateRenderMethod.write_variable_declares.<locals>.<listcomp>cSsg|]
}|jqSr )r2)r+rr r r!r-srFNrz_import_ns = {}Trz:_mako_get_namespace(context, %r)._populate(_import_ns, %r)z\s*,\s*z%loop = __M_loop = runtime.LoopStack())rz%%s = _mako_get_namespace(context, %r)z"%s = _import_ns.get(%r, UNDEFINED)zif %s is UNDEFINED:ztry:z%s = context[%r]zexcept KeyError:z&raise NameError("'%s' is not defined")z3%s = _import_ns.get(%r, context.get(%r, UNDEFINED))z%s = context.get(%r, UNDEFINED)z__M_writer = context.writer())dictrDrarb
undeclaredclosuredefsrn
differencerzlocally_declaredr.rdiscardintersectiongetattrrrfZhas_importsrQitemsr8resplitr:r;write_def_declris_rootrrG)
r#rLrwlimitZcomp_identsZto_writeZhas_loopidentnscompr r r!r}s|







z-_GenerateRenderMethod.write_variable_declarescCs|j}|}|jdd}|jsNt|jjdks@t|jjdkrN|ddn|dd|j	d|d
|f|j	d|d
|f|j	d	d	S)
z>write a locally-available callable referencing a top-level defT)as_callrzcontext._locals(__M_locals)r
zdef %s(%s):ruzreturn render_%s(%s)N)r2r3r1r4rLr|rzinsertrrfrg)r#rrLr2	namedeclsnameargsr r r!rNsz$_GenerateRenderMethod.write_def_declc
	Cs |}|j}|r"|jd||jd|jd|ft|jjdk}t	|j
dd}t	|j
dd}|jdd	|s|s|r|jd
|j
||d}|||j|x|jD]}	|	|qW|j||||||jd|r|j||j|d
|dd
ddS)z?write a locally-available def callable inside an enclosing def.z&@runtime._decorate_inline(context, %s)zdef %s(%s):rurr(r)r*z/__M_caller = context.caller_stack._push_frame()ztry:zcontext._push_buffer())rNFT)inlinerw)r3rxrrfr2rgr4r5r6r7r8r9rGrjr}r/rMr_r`popr~r)
r#rrLrrrxrCr(r*r\r r r!ras@


z&_GenerateRenderMethod.write_inline_defTcCs|s,|s,|s,|jd|r,|jddd|s8|s8|r|s@|rP|jddn|jdd|rn|jdd}|r||jj|d}|jd|r|s||jj|d}|s|r|jd	|n|jd
|ddS)aJwrite 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.z	return ''zfinally:z!context.caller_stack._pop_frame()Nz__M_buf = context._pop_buffer()z6__M_buf, __M_writer = context._pop_buffer_and_writer()z__M_buf.getvalue()Fz	return %sz__M_writer(%s))rrfrGcreate_filter_callabler5r6r.r)r#rr(rCr*	callstackrNr r r!r~s2

z&_GenerateRenderMethod.write_def_finishcsZjd||fjdt|}i}	jjdk	rT|	fddjjjD|	fddjDd|	krtt	|	d|	d<jd|d	
|fd
d|D}
j||d|rd
||d	
|
d
dd|	
D|f}jj|d}jd|dn8jd||d	
|
d
dd|	
D|fdddS)zlwrite a post-function decorator to replace a rendering
            callable with a cached version of itself.z__M_%s = %s	cache_keyNc3s:|]2}|dr|dkr|ddjjj|fVqdS)cache_rN)
startswithr.r=r)r+pa)r#r r!	<genexpr>sz>_GenerateRenderMethod.write_cache_decorator.<locals>.<genexpr>c3s6|].}|dr|dkr|ddj|fVqdS)rrrN)rr)r+r)node_or_pagetagr r!rsZtimeoutzdef %s(%s):rucSs0g|](}d|kr(d|ddfdn|qS)=z%s=%srr])r)r+r,r r r!r-sz?_GenerateRenderMethod.write_cache_decorator.<locals>.<listcomp>)rwrz`context.get('local').cache._ctx_get_or_create(%s, lambda:__M_%s(%s),  context, %s__M_defname=%r)rXcSsg|]\}}d||fqS)z%s=%s, r )r+kvr r r!r-sFzreturn zk__M_writer(context.get('local').cache._ctx_get_or_create(%s, lambda:__M_%s(%s), context, %s__M_defname=%r))cSsg|]\}}d||fqS)z%s=%s, r )r+rrr r r!r-
sz	return '')rrfrr9rr.r=rlintr7rgr}undeclared_identifiersrrrrG)r#rrBr6r(rLrrwZcachekeyZ
cache_argsZ	pass_argsrNr )rr#r!rsP


z+_GenerateRenderMethod.write_cache_decoratorc
sfdd}d|krL|rLjjr0jjjj|}jjrLd|krLjj|}x\|D]T}|dkr`qRtd|}|r|dd\}}||}	|	|}n||}d||f}qRW|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.cs<td|rd|Sjjr*tj||Stj||SdS)Nz
decode\..+zfilters.)rmatchr.rrZNON_UNICODE_ESCAPESr9ZDEFAULT_ESCAPES)rB)r#r r!
locate_encodes
zC_GenerateRenderMethod.create_filter_callable.<locals>.locate_encoder\z
(.+?)(\(.*\))rr]z%s(%s))r.r=r5r6rrrgroup)
r#r6targetZ
is_expressionremrZfargsrtr )r#r!rs$

z,_GenerateRenderMethod.create_filter_callablecCs|j|jt|js@|jjdk	r4t|jjjjs@t|jj	rj|
|jjd|jd}|j
d|n|j
d|jdS)Nz%sTz__M_writer(%s))rryrFr4Zescapesr.r=r5r6rrZescapes_coderrf)r#rrNr r r!visitExpression7s
z%_GenerateRenderMethod.visitExpressioncsjr>|jdjr|jd|jd|jdn|jj|jjrljdkrlt	|j}nj
}|j|}|rt
dd|Drt
fdd|Dr|jddS)Nzfinally:zloop = __M_loop._exit()forcss |]}t|tjtjfVqdS)N)rrCommentControlLine)r+rr r r!r_sz9_GenerateRenderMethod.visitControlLine.<locals>.<genexpr>c3s,|]$}t|tjr|jp"|jVqdS)N)rrrZ
is_ternarykeywordisend)r+r)rr r!rcsr)rrrfhas_loop_contextryrFr.rrmangle_mako_looprget_childrenrall)r#rrZchildrenr )rr!visitControlLineIs(


z&_GenerateRenderMethod.visitControlLinecCs(|j|j|jdt|jdS)Nz__M_writer(%s))rryrFrfrZcontent)r#rr r r!	visitTextjsz_GenerateRenderMethod.visitTextc
Csht|jjdk}|r"|jddx|jD]}||q*W|rd|jddd||jjddddS)	Nrz#__M_writer = context._push_writer()ztry:zfinally:z6__M_buf, __M_writer = context._pop_buffer_and_writer()z__M_writer(%s)z__M_buf.getvalue()F)r4r5r6rrGr_r`r)r#rrCr\r r r!visitTextTagnsz"_GenerateRenderMethod.visitTextTagcCsd|js`|jj|j|jd|js`t|jjdkr`|j	d|j	dd
dd|DdS)N)rrz0__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]))rucSsg|]}t|qSr )r)r+rvr r r!r-sz3_GenerateRenderMethod.visitCode.<locals>.<listcomp>)rTrrrrFr1r4rLr|rfrgrc)r#rr r r!rVsz_GenerateRenderMethod.visitCodecCsT|j|j|jd}|r:|jd|jd|fn|jd|jddS)Nr6z5runtime._include_file(context, %s, _template_uri, %s)rz1runtime._include_file(context, %s, _template_uri))rryrFr8r9rfr)r#rr6r r r!visitIncludeTagsz%_GenerateRenderMethod.visitIncludeTagcCsdS)Nr )r#rr r r!rRsz'_GenerateRenderMethod.visitNamespaceTagcCsdS)Nr )r#rr r r!rsz!_GenerateRenderMethod.visitDefTagcCsn|jr|jd|jnP|jdd}|dg7}|jd|j|jd|jd|f|jddS)	Nz%s()T)rz
**pageargszOif 'parent' not in context._data or not hasattr(context._data['parent'], '%s'):zcontext['self'].%s(%s)rurY)r;rrfr2r3rg)r#rrr r r!rs

z#_GenerateRenderMethod.visitBlockTagcCs||dS)N)visitCallTag)r#rr r r!visitCallNamespaceTagsz+_GenerateRenderMethod.visitCallNamespaceTagcsjjddgjj|ddj|dddjGfdddt}|}x|jD]}|	|qnWj
|j}jd	d

|d}|rjddjx|jD]}|	qWj
j||dddd
jddd

djddj|jjdg|jdddddS)Nzdef ccall(caller):ZbodyT)rFZcallercs.eZdZddZddZfddZdS)z6_GenerateRenderMethod.visitCallTag.<locals>.DefVisitorcSs||dS)N)r)rNrr r r!rszB_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitDefTagcSs||dS)N)r)rNrr r r!rszD_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitBlockTagcs<j|dd|js"|j|jjkr8j|j=dS)NF)r)rr;rMr2r)rNr)body_identifierscallable_identifiersrr#r r!rs
zE_GenerateRenderMethod.visitCallTag.<locals>.DefVisitor.visitDefOrBaseN)r%r&r'rrrr )rrrr#r r!
DefVisitorsrz
def body(%s):ruzcontext._push_buffer()ztry:)rzreturn [%s]zccontext.caller_stack.nextcaller = runtime.Namespace('caller', context, callables=ccall(__M_caller))z__M_writer(%s)zfinally:z&context.caller_stack.nextcaller = None)rrfrLrjadd_declaredr/rMr^r_r`rr>r3rgrGr}r~ryrFrZ
expression)r#rrrr\Zbodyargsr(r )rrrr#r!rsB




z"_GenerateRenderMethod.visitCallTag)FN)T)FF)r%r&r'__doc__r$rApropertyrLr<r@rprrrqr}rrr~rrrrrrrVrrRrrrrr r r r!ros61m9]
~/
9
K"!rc@seZdZdZd(ddZddZedd	Zd
dZdd
Z	ddZ
ddZddZddZ
ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'ZdS))rdzCtracks the status of identifier names as template code is rendered.NFcCs|dk	rt|tjr(t|_t|_qt|jdd|j	
D|j|j|_|rn|j|j
|_tjf|j|_nt|_t|_||_t|_
t|_t|_t|_t|_	||_|dk	r|||jj|j}|rtdd|dS)NcSsg|]
}|jqSr )rB)r+rr r r!r-sz)_Identifiers.__init__.<locals>.<listcomp>z'Reserved words declared in template: %sz, )rrZNamespaceTagrarerZSetLikeDictrkrbrrnrrzrr.r|rr`rrrZNameConflictErrorrg)r#r.rparentrZ
illegal_namesr r r!r$s8




z_Identifiers.__init__cKst|j||f|S)zWcreate a new Identifiers for a new Node, with
          this Identifiers as the parent.)rdr.)r#rr?r r r!rjKsz_Identifiers.branchcCst|j|jS)N)rarkrbrrn)r#r r r!rDQsz_Identifiers.defscCsHdt|jt|jt|jdd|jDdd|jD|jfS)NzrIdentifiers(declared=%r, locally_declared=%r, undeclared=%r, topleveldefs=%r, closuredefs=%r, argumentdeclared=%r)cSsg|]
}|jqSr )rB)r+rr r r!r-^sz)_Identifiers.__repr__.<locals>.<listcomp>cSsg|]
}|jqSr )rB)r+rr r r!r-_s)rsrerrrkrnrrz)r#r r r!__repr__Usz_Identifiers.__repr__cCsZx6|D]*}|dkr
||j|jkr
|j|q
Wx|D]}|j|qBWdS)zpupdate the state of this Identifiers with the undeclared
            and declared identifiers of the given node.r
N)rrerbrrr{rc)r#rrr r r!check_declaredds
z_Identifiers.check_declaredcCs&|j|||jkr"|j|dS)N)rer{rremove)r#rr r r!rps
z_Identifiers.add_declaredcCs||dS)N)r)r#rr r r!rusz_Identifiers.visitExpressioncCs||dS)N)r)r#rr r r!rxsz_Identifiers.visitControlLinecCs&|js"|||j||_dS)N)rTrr|rbrc)r#rr r r!rV{s
z_Identifiers.visitCodecCs(|j|kr$x|jD]}||qWdS)N)rr_r`)r#rr\r r r!rRs
z_Identifiers.visitNamespaceTagcCsL||j}|||j<|dk	rH||k	rH|js2|jrHtjd|jf|jdS)Nz<%%def or %%block named '%s' already exists in this template.)r9r2r:rrr)r#Z
collectionrZexistingr r r!_check_name_existss
z_Identifiers._check_name_existscCs|r|js||j|n||jk	r6||j|x6|D]*}|dkr@||j|j	kr@|j
|q@W||jkrx|D]}|j
|qWx|jD]}||qWdS)Nr
)rr;rrkrrrrerbrrr{rcrzr_r`)r#rrr\r r r!rs


z_Identifiers.visitDefTagcCs||jk	rj|jsjt|jtjr>tjd|j|jjff|jn,t|jtj	tj
frjtjd|jff|jx6|D]*}|dkrt||j
|jkrt|j|qtW|js||j||j|jn||jk	r||j|x|D]}|j|qWx|jD]}||qWdS)Nz/Named block '%s' not allowed inside of def '%s'z3Named block '%s' not allowed inside of <%%call> tagr
)rr;rrr0rrrBrZCallTagZCallNamespaceTagrrerbrrr{rrkr2rrcrzr_r`)r#rrr\r r r!rs2



z_Identifiers.visitBlockTagcCs<x6|D]*}|dkr
||j|jkr
|j|q
WdS)Nr
)rrerbrrr{)r#rrr r r!rs
z_Identifiers.visitTextTagcCs||dS)N)r)r#rr r r!rsz_Identifiers.visitIncludeTagcCs,x|D]}|j|q
W||dS)N)rcrzr{r)r#rrr r r!rSsz_Identifiers.visitPageTagcCs||dS)N)r)r#rr r r!rsz"_Identifiers.visitCallNamespaceTagcCs||jkr|x6|D]*}|dkr||j|jkr|j|qWx|D]}|j|qLWxR|j	D]}|
|qhWn8x6|D]*}|dkr||j|jkr|j|qWdS)Nr
)rrrerbrrr{rcrzr_r`)r#rrr\r r r!rs


z_Identifiers.visitCallTag)NNF)r%r&r'rr$rjrrDrrrrrrVrRrrrrrrSrrr r r r!rds&
C"rdzi^for\s+((?:\(?)\s*[A-Za-z_][A-Za-z_0-9]*(?:\s*,\s*(?:[A-Za-z_][A-Za-z0-9_]*),??)*\s*(?:\)?))\s+in\s+(.*):cCsrt}|||jrhd|jd_t|j}|rX|d|	ddd|	d}qnt
d|jn|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
    TrKzloop = __M_loop._enter(%s)r]ztry:zfor %s in loop:rzCouldn't apply loop context: %s)LoopVariabler`detectedr_r	_FOR_LOOPrrrGrSyntaxError)rrZ
loop_variablerrr r r!rs
rc@s8eZdZdZddZddZddZdd	Zd
dZdS)
rzQA node visitor which looks for the name 'loop' within undeclared
    identifiers.cCs
d|_dS)NF)r)r#r r r!r$szLoopVariable.__init__cCs4d|krd|_nx|D]}||qWdS)NrT)rrrr`)r#rr\r r r!_loop_reference_detectedsz%LoopVariable._loop_reference_detectedcCs||dS)N)r)r#rr r r!rszLoopVariable.visitControlLinecCs||dS)N)r)r#rr r r!rV"szLoopVariable.visitCodecCs||dS)N)r)r#rr r r!r%szLoopVariable.visitExpressionN)	r%r&r'rr$rrrVrr r r r!rsr)rrHrriZmakorrrrrrZ
mako.pygenrrhrarmrbZRESERVED_NAMES	frozensetr"r^rrrdrrrr r r r!<module>sN$p