%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/jinja2/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/jinja2/__pycache__/compiler.cpython-35.pyc



KP�g���@sdZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZmZmZdd
lmZmZmZmZmZmZddd
dddddddddddddiZeed�rdZndZdd�Ze e!e�dd��Zdd d!d"�Z"d#d$�Z#d%d&�Z$Gd'd(�d(e%�Z&Gd)d*�d*e%�Z'Gd+d,�d,e(�Z)Gd-d.�d.e
�Z*Gd/d0�d0e
�Z+Gd1d2�d2e
�Z,Gd3d4�d4e-�Z.Gd5d6�d6e
�Z/dS)7z�
    jinja2.compiler
    ~~~~~~~~~~~~~~~

    Compiles nodes into python code.

    :copyright: (c) 2010 by the Jinja Team.
    :license: BSD, see LICENSE for more details.
�)�chain)�deepcopy)�	iskeyword)�nodes)�EvalContext)�NodeVisitor)�TemplateAssertionError)�Markup�concat�escape)�
range_type�	text_type�string_types�	iteritems�NativeStringIO�imap�eqz==�nez!=�gt�>Zgteqz>=�lt�<Zlteqz<=�inZnotinznot inr�itemscsd��fdd�}|S)N�*csdS)N�r)�xr�1/usr/lib/python3/dist-packages/jinja2/compiler.py�f-sz&unoptimize_before_dead_code.<locals>.fr)rr)rr�unoptimize_before_dead_code+sr�__closure__NFcCsct|tj�std��|j|||||�}|j|�|dkr_|jj�SdS)z+Generate the python source for a node tree.z Can't compile non template nodesN)�
isinstancerZTemplate�	TypeErrorZcode_generator_class�visit�stream�getvalue)�node�environment�name�filenamer$�
defer_init�	generatorrrr�generate7s
r,cCs�|dks$|tks$|tkr(dSt|ttttttft	�rQdSt|t
ttt
f�r�x|D]}t|�ssdSqsWdSt|t�r�x:t|�D],\}}t|�s�dSt|�s�dSq�WdSdS)z)Does the node have a safe representation?NTF)�NotImplemented�Ellipsisr!�bool�int�float�complexrr	r�tuple�list�set�	frozenset�
has_safe_repr�dictr)�value�item�keyrrrr7Cs$$
r7cCsJt|�}y"x|D]}|j|�qWWntk
rBYnX|jS)z�Check if the names passed are accessed undeclared.  The return value
    is a set of all the undeclared names from the sequence of names found.
    )�UndeclaredNameVisitorr#�VisitorExit�
undeclared)r�names�visitorr&rrr�find_undeclaredYs

rAc@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Identifiersz+Tracks the status of identifiers in frames.cCs@t�|_t�|_t�|_t�|_t�|_dS)N)r5�declared�outer_undeclaredr>�declared_locally�declared_parameter)�selfrrr�__init__is
zIdentifiers.__init__cCs$|jj|�|jj|�dS)z$Register a special name like `loop`.N)r>�discardrC�add)rGr(rrr�add_special|szIdentifiers.add_specialcCs/||jks||jkr"dS||jkS)z6Check if a name is declared in this or an outer scope.T)rErFrC)rGr(rrr�is_declared�szIdentifiers.is_declaredcCs
t|�S)N)r)rGrrr�copy�szIdentifiers.copyN)�__name__�
__module__�__qualname__�__doc__rHrKrLrMrrrrrBfs
rBc@sjeZdZdZddd�Zdd�Zdd�Zfd	d
�Zdd�Zd
d�Z	eZ
dS)�Framez&Holds compile time information for us.NcCs�||_t�|_d|_d|_|o3|j|_d|_|rQ|jpTd|_t�|_	||_
|dk	r�|jjj|jj|jj
B|j	B�|jjj|jj|jj�|j|_dS)NF)�eval_ctxrB�identifiers�toplevel�	rootlevel�require_output_check�buffer�blockr5�assigned_names�parentrC�updaterFrDr>)rGrSr[rrrrH�s"						zFrame.__init__cCsZtj|j�}|jj|j�tj|jj�|_|jjj|jj�|S)z!Create a copy of the current one.)�object�__new__�	__class__�__dict__r\rT)rG�rvrrrrM�s
z
Frame.copycCs1t|j�}x|D]}|j|�qWdS)z�Walk the node and check for identifiers.  If the scope is hard (eg:
        enforce on a python level) overrides from outer scopes are tracked
        differently.
        N)�FrameIdentifierVisitorrTr#)rGrr@r&rrr�inspect�s
z
Frame.inspectcsB|j��j�jB�j�jB@t�fdd�|D��BS)z�Find all the shadowed names.  extra is an iterable of variables
        that may be defined with `add_special` which may occour scoped.
        c3s$|]}�j|�r|VqdS)N)rL)�.0r)�irr�	<genexpr>�sz&Frame.find_shadowed.<locals>.<genexpr>)rTrCrDrErFr5)rG�extrar)rer�
find_shadowed�s	
zFrame.find_shadowedcCst|j|�S)zReturn an inner frame.)rRrS)rGrrr�inner�szFrame.innercCs|j�}d|_|S)z�Return a soft frame.  A soft frame may not be modified as
        standalone thing as it shares the resources with the frame it
        was created of, but it's not a rootlevel frame any longer.
        F)rMrV)rGrarrr�soft�s	z
Frame.soft)rNrOrPrQrHrMrcrhrirj�__copy__rrrrrR�s+			rRc@seZdZdZdS)r=z?Exception used by the `UndeclaredNameVisitor` to signal a stop.N)rNrOrPrQrrrrr=�sr=c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�DependencyFinderVisitorz.A visitor that collects filter and test calls.cCst�|_t�|_dS)N)r5�filters�tests)rGrrrrH�sz DependencyFinderVisitor.__init__cCs$|j|�|jj|j�dS)N)�
generic_visitrmrJr()rGr&rrr�visit_Filter�s
z$DependencyFinderVisitor.visit_FiltercCs$|j|�|jj|j�dS)N)rornrJr()rGr&rrr�
visit_Test�s
z"DependencyFinderVisitor.visit_TestcCsdS)zStop visiting at blocks.Nr)rGr&rrr�visit_Block�sz#DependencyFinderVisitor.visit_BlockN)rNrOrPrQrHrprqrrrrrrrl�s
rlc@s:eZdZdZdd�Zdd�Zdd�ZdS)	r<z�A visitor that checks if a name is accessed without being
    declared.  This is different from the frame visitor as it will
    not stop at closure frames.
    cCst|�|_t�|_dS)N)r5r?r>)rGr?rrrrHszUndeclaredNameVisitor.__init__cCsi|jdkrR|j|jkrR|jj|j�|j|jkret��n|jj|j�dS)N�load)�ctxr(r?r>rJr=rI)rGr&rrr�
visit_Names
!z UndeclaredNameVisitor.visit_NamecCsdS)zStop visiting a blocks.Nr)rGr&rrrrrsz!UndeclaredNameVisitor.visit_BlockN)rNrOrPrQrHrurrrrrrr<�sr<c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)rbzA visitor for `Frame.inspect`.cCs
||_dS)N)rT)rGrTrrrrHszFrameIdentifierVisitor.__init__cCs�|jdkr(|jjj|j�nc|jdkrP|jjj|j�n;|jdkr�|jj|j�r�|jjj|j�dS)z2All assignments to names go through this function.�storeZparamrsN)rtrTrErJr(rFrLr>)rGr&rrrrusz!FrameIdentifierVisitor.visit_Namecs��j|j��j��j�jB����fdd�}||j�}||jp_f�}�jj|j	|��j
��jj||B�dS)Ncsm|s
t�S�j��_x|D]}�j|�q#W�jj�}�jj�jj���_|S)N)r5rMrTr#rEr>r\)rZsubnodera)�	old_names�real_identifiersrGrr�inner_visit's
	z4FrameIdentifierVisitor.visit_If.<locals>.inner_visit)r#�testrTrErF�body�else_r>r\�symmetric_differencerC)rGr&ryr{r|r)rwrxrGr�visit_If s	

zFrameIdentifierVisitor.visit_IfcCs|jjj|j�dS)N)rTrErJr()rGr&rrr�visit_Macro?sz"FrameIdentifierVisitor.visit_MacrocCs'|j|�|jjj|j�dS)N)rorTrErJ�target)rGr&rrr�visit_ImportBs
z#FrameIdentifierVisitor.visit_ImportcCsa|j|�xM|jD]B}t|t�rF|jjj|d�q|jjj|�qWdS)N�)ror?r!r3rTrErJ)rGr&r(rrr�visit_FromImportFs

z'FrameIdentifierVisitor.visit_FromImportcCs$|j|j�|j|j�dS)z'Visit assignments in the correct order.N)r#r&r�)rGr&rrr�visit_AssignNsz#FrameIdentifierVisitor.visit_AssigncCs|j|j�dS)zqVisiting stops at for blocks.  However the block sequence
        is visited as part of the outer scope.
        N)r#�iter)rGr&rrr�	visit_ForSsz FrameIdentifierVisitor.visit_ForcCs|j|j�dS)N)r#�call)rGr&rrr�visit_CallBlockYsz&FrameIdentifierVisitor.visit_CallBlockcCs|j|j�dS)N)r#�filter)rGr&rrr�visit_FilterBlock\sz(FrameIdentifierVisitor.visit_FilterBlockcCsdS)zStop visiting at block assigns.Nr)rGr&rrr�visit_AssignBlock_sz(FrameIdentifierVisitor.visit_AssignBlockcCsdS)zStop visiting at scopes.Nr)rGr&rrr�visit_Scopebsz"FrameIdentifierVisitor.visit_ScopecCsdS)zStop visiting at blocks.Nr)rGr&rrrrresz"FrameIdentifierVisitor.visit_BlockN)rNrOrPrQrHrur~rr�r�r�r�r�r�r�r�rrrrrrrbs
rbc@seZdZdZdS)�CompilerExitz�Raised if the compiler encountered a situation where it just
    doesn't make sense to further process the code.  Any block that
    raises such an exception is not further processed.
    N)rNrOrPrQrrrrr�isr�c@sNeZdZdddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zddd�Z	ddd�Z
dd�Zddd�Zdd�Z
dd�Zdddd�Zdddd �Zdd!d"�Zd#d$�Zd%d&�Zd'd(�Zfd)d*�Zd+d,�Zdd-d.d/�Zdd0d1�Zd2d3�Zd4d5�Zdd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Zd@dA�Z dBdC�Z!dDdE�Z"dFdG�Z#dHdI�Z$dJdK�Z%dLdM�Z&dNdO�Z'dPdQ�Z(dRdS�Z)dTdU�Z*dVdW�Z+dXdY�Z,dZd[�Z-d\d]�Z.d^d_�Z/d`da�Z0dbdc�Z1d-ddde�Z2d-dfdg�Z3e2dh�Z4e2di�Z5e2dj�Z6e2dk�Z7e2dl�Z8e2dm�Z9e2dn�Z:e2dodpd�Z;e2dqdpd�Z<e3dh�Z=e3di�Z>e3drdpd�Z?[2[3dsdt�Z@dudv�ZAdwdx�ZBdydz�ZCd{d|�ZDd}d~�ZEdd��ZFd�d��ZGd�d��ZHdd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVdS)��
CodeGeneratorNFcCs�|dkrt�}||_||_||_||_d|_||_i|_i|_d|_	d|_
d|_i|_i|_
g|_d|_d|_d|_d|_d|_d|_dS)NFrr�T)rr'r(r)r$Zcreated_block_contextr*�import_aliases�blocks�extends_so_far�has_known_extends�code_linenornrm�
debug_info�_write_debug_info�
_new_lines�
_last_line�_first_write�_last_identifier�_indentation)rGr'r(r)r$r*rrrrHrs,																				zCodeGenerator.__init__cCst|||j|j��dS)z*Fail with a :exc:`TemplateAssertionError`.N)rr(r))rG�msg�linenorrr�fail�szCodeGenerator.failcCs|jd7_d|jS)zGet a new unique identifier.r�zt_%d)r�)rGrrr�temporary_identifier�sz"CodeGenerator.temporary_identifiercCs'|j�|_|jd|j�dS)z7Enable buffering for the frame from that point onwards.z%s = []N)r�rX�	writeline)rG�framerrrrX�szCodeGenerator.buffercCs�|jjry|jd�|j�|jd|j�|j�|jd�|j�|jd|j�|j�n7|jjr�|jd|j�n|jd|j�dS)z(Return the buffer contents of the frame.zif context.eval_ctx.autoescape:zreturn Markup(concat(%s))zelse:zreturn concat(%s)N)rS�volatiler��indentrX�outdent�
autoescape)rGr�rrr�return_buffer_contents�s





z$CodeGenerator.return_buffer_contentscCs|jd7_dS)zIndent by one.r�N)r�)rGrrrr��szCodeGenerator.indentr�cCs|j|8_dS)zOutdent by step.N)r�)rG�steprrrr��szCodeGenerator.outdentcCs=|jdkr"|jd|�n|jd|j|�dS)z%Yield or write into the frame buffer.Nzyield z
%s.append()rXr�)rGr�r&rrr�start_write�szCodeGenerator.start_writecCs |jdk	r|jd�dS)z1End the writing process started by `start_write`.N�))rX�write)rGr�rrr�	end_write�szCodeGenerator.end_writecCs.|j||�|j|�|j|�dS)z4Simple shortcut for start_write + write + end_write.N)r�r�r�)rG�sr�r&rrr�simple_write�s
zCodeGenerator.simple_writecCsj|jdkr|jd�n
|jd�y%x|D]}|j||�q6WWntk
reYnXdS)z�Visit a list of nodes as block in a frame.  If the current frame
        is no buffer a dummy ``if 0: yield None`` is written automatically
        unless the force_generator parameter is set to False.
        Nzif 0: yield None�pass)rXr�r#r�)rGrr�r&rrr�
blockvisit�s


zCodeGenerator.blockvisitcCs�|jr�|jso|jjd|j�|j|j7_|jdk	ro|jj|j|jf�d|_d|_|jjd|j�d|_|jj|�dS)z&Write a string into the output stream.�
NFz    r)	r�r�r$r�r�r�r��appendr�)rGrrrrr��s		
			zCodeGenerator.writercCs!|j||�|j|�dS)z!Combination of newline and write.N)�newliner�)rGrr&rgrrrr��szCodeGenerator.writelinecCsSt|jd|�|_|dk	rO|j|jkrO|j|_|j|_dS)z/Add one or more newlines before the next write.r�N)�maxr�r�r�r�)rGr&rgrrrr�szCodeGenerator.newlinec	CsVd}x@tdd�|jD�|p(f�D]}t|�r,d}Pq,Wx.|jD]#}|jd�|j||�qSW|s�x.|jD]#}|jd�|j||�q�W|dk	r�x1t|�D]#\}}|jd||f�q�W|jr|jd�|j|j|�|r#|jdk	r?|jd	�n
|jd
�xE|jD]:}|jd|j	�|j|j
|�|jd�qVW|dk	r�x1t|�D]#\}}|jd||f�q�W|jdk	r|jd
�|j|j|�|jd�qR|jd�n/|jdk	rR|jd�|j|j|�dS)a,Writes a function call to the stream for the current node.
        A leading comma is added automatically.  The extra keyword
        arguments may not include python keywords otherwise a syntax
        error could occour.  The extra keyword arguments should be given
        as python dict.
        Fcss|]}|jVqdS)N)r;)rdrrrrrfsz*CodeGenerator.signature.<locals>.<genexpr>Tz, Nz, %s=%sz, *z
, **dict({z, **{z%r: z%r: %s, z}, **r��}z, **)r�kwargs�is_python_keyword�argsr�r#rZdyn_argsZ
dyn_kwargsr;r9)	rGr&r��extra_kwargsZkwarg_workaroundZkwarg�argr;r9rrr�	signaturesJ	,

	



zCodeGenerator.signaturecCs2x+|jjD]}|jd||f�q
WdS)z9Pull all the references identifiers into the local scope.zl_%s = context.resolve(%r)N)rTr>r�)rGr�r(rrr�pull_locals@szCodeGenerator.pull_localscCs�t�}x|D]}|j|�qWxqdD]i}t||�}xQt||�D]@}||kru|j�||<|jd||||f�qSWq.WdS)zPull all the dependencies.rmrnz%s = environment.%s[%r]N)zfiltersztests)rlr#�getattrr�r�)rGrr@r&Z
dependency�mappingr(rrr�pull_dependenciesEs	

	zCodeGenerator.pull_dependenciescCsO|jjrK|jdtr!dp$ddjdd�|jjD��f�dS)z+Disable Python optimizations for the frame.z%sdummy(%s)zif 0: �z, css|]}d|VqdS)�l_Nr)rdr(rrrrf[sz1CodeGenerator.unoptimize_scope.<locals>.<genexpr>N)rTrCr�r�join)rGr�rrr�unoptimize_scopeRs	zCodeGenerator.unoptimize_scopecCs�i}xB|j|�D]1}|j�||<}|jd||f�qWt�}x1|jjD]#}||kra|jd|�qaW|r�|jdj|�d�|S)a�This function returns all the shadowed variables in a dict
        in the form name: alias and will write the required assignments
        into the current scope.  No indentation takes place.

        This also predefines locally declared variables from the loop
        body because under some circumstances it may be the case that

        `extra_vars` is passed to `Frame.find_shadowed`.
        z	%s = l_%sr�z = z
 = missing)rhr�r�r5rTrErJr�)rGr�Z
extra_vars�aliasesr(ZidentZ
to_declarerrr�
push_scope^s
	zCodeGenerator.push_scopecCs�x1t|�D]#\}}|jd||f�q
Wt�}x1|jjD]#}||krJ|jd|�qJW|r�|jdj|�d�dS)z0Restore all aliases and delete unused variables.z	l_%s = %sr�z = z
 = missingN)rr�r5rTrErJr�)rGr�r�r(�aliasZ	to_deleterrr�	pop_scopets	zCodeGenerator.pop_scopeTc	Cs�|dkr|j�}t|�}|j�}|j|�|jj|jj@|jj|jjB@}|r�|j	ddj
t|��|j�|jj|jj|jj@8_|s�|Sd|_
d|_d|_dd�|jD�|_}t|d�}d|kr8d
|_|jjd�|jd�d|krjd
|_
|jjd�|jd�d	|kr�d
|_|jjd	�|jd
�|S)aMIn Jinja a few statements require the help of anonymous
        functions.  Those are currently macros and call blocks and in
        the future also recursive loops.  As there is currently
        technical limitation that doesn't allow reading and writing a
        variable in a scope where the initial value is coming from an
        outer scope, this function tries to fall back with a common
        error message.  Additionally the frame passed is modified so
        that the argumetns are collected and callers are looked up.

        This will return the modified frame.
        NzXIt's not possible to set and access variables derived from an outer scope! (affects: %s)z, FcSsg|]}d|j�qS)r�)r()rdrrrr�
<listcomp>�s	z2CodeGenerator.function_scoping.<locals>.<listcomp>�callerr��varargsTZl_callerZl_kwargsZ	l_varargs)r�zkwargsr�)�iter_child_nodesr4rircrTr>rCrErFr�r��sortedr��accesses_kwargs�accesses_varargs�accesses_callerr��	argumentsrArKr�)	rGr&r��children�find_specialZ
func_frameZoverridden_closure_varsr�r>rrr�function_scoping�sD
		
					
	
	
zCodeGenerator.function_scopingcCs�|j|||�}d|_|j}d|jjkrF|dg}|jddj|�|�|j�|j|�|j	|�|j
|j|�|j|�|j
�|S)z/Dump the function def of a macro or call block.F�loopz
l_loop=l_loopzdef macro(%s):z, )r�rWr�rTrCr�r�r�rXr�r�r{r�r�)rGr&r�r�r�rrr�
macro_body�s		





zCodeGenerator.macro_bodycCs�djdd�|jD��}t|dd�}t|j�dkrP|d7}|jd||f�x.|jD]#}|j||�|jd�qqW|jd	t|j�t|j	�t|j
�f�dS)
z<Dump the macro definition for the def created by macro_body.z, css|]}t|j�VqdS)N)�reprr()rdrrrrrf�sz*CodeGenerator.macro_def.<locals>.<genexpr>r(Nr��,z%Macro(environment, macro, %r, (%s), (z), %r, %r, %r))r�r�r��lenr�Zdefaultsr#r/r�r�r�)rGr&r�Z	arg_tupler(r�rrr�	macro_def�s
		zCodeGenerator.macro_defcCs7d|j}|jdk	r3|dt|j�7}|S)z.Return a human readable position for the node.zline %dNz in )r�r(r�)rGr&rarrr�position�s
zCodeGenerator.positioncCsv|dkstd��t|j|j�}ddlm}|jd�|jddj|��tsw|jd�|j	r�dp�d	}|j
tj�dk	}xV|j
tj�D]B}|j|jkr�|jd
|j|j�||j|j<q�Wx�|j
tj�D]�}|j|jkr|j}	|j�|j|	<}
d|	kr�|	jdd�\}}|jd
|||
f�q|jd|	|
f�qW|jd|j�|jd|dd�t|�}|j|j�d|_|_|o	|j|_|j�|r,|jd�dt|jd#�kra|j j!d�|jd�|j"|�|j#|j�|j$|j|�|j%�|r|js�|j�|jd�|j�|jd�|j�|jd�|j%d|j�xt&|j�D]\}
}t|�}|j|j�|
|_'|jd|
|f|d�|j�t|jd$�}d|kr�|j j!d�|jd�d|kr�|j j!d�|jd|
|
f�|j"|�|j#|j�|j$|j|�|j%�qW|jddjdd�|jD��dd�|jd d!jd"d�|j(D���dS)%Nzno root frame allowedr)�__all__zfrom __future__ import divisionzfrom jinja2.runtime import z, zdummy = lambda *x: Nonez, environment=environmentr�zblock %r defined twice�.r�zfrom %s import %s as %szimport %s as %sz	name = %rzdef root(context%s):rgTzparent_template = NonerGz#l_self = TemplateReference(context)zif parent_template is not None:z7for event in parent_template.root_render_func(context):zyield event�zdef block_%s(context%s):�superz%l_super = context.super(%r, block_%s)z
blocks = {%s}css|]}d||fVqdS)z%r: block_%sNr)rdrrrrrfTsz/CodeGenerator.visit_Template.<locals>.<genexpr>zdebug_info = %r�&css|]}d|VqdS)z%s=%sNr)rdrrrrrfYs)�self)r�zsuper))�AssertionErrorrr'r(Zjinja2.runtimer�r�r�rr*�findrZExtends�find_allZBlockr�r�r�ZImportedName�
importnamer�r��rsplitrRrcr{rUrVr�rWr�rArTrKr�r�r�r�rrYr�)rGr&r�rSZexportedZenvenvZhave_extendsrY�import_�impr��module�objr(�block_framer>rrr�visit_Template�s�

		




	





	


	
zCodeGenerator.visit_TemplatecCs�d}|jrL|jrdS|jdkrL|jd�|j�|d7}|jr[dp^d}|jd|j|f|�|j�|jd|�|j|�dS)	z.Call a block and register it for the template.r�Nrzif parent_template is None:zcontext.derived(locals())�contextz'for event in context.blocks[%r][0](%s):�event)	rUr�r�r�r�Zscopedr(r�r�)rGr&r��levelr�rrrrr\s		


	
zCodeGenerator.visit_BlockcCs	|js|jd|j�|jdkr{|jsK|jd�|j�|jdd�|jrqt��n
|j�|jd|�|j	|j
|�|jd|j�|jdt
�|j�|jd	�|j�|jr�d
|_|jd7_dS)
zCalls the extender.z,cannot use extend from a non top-level scoperzif parent_template is not None:zraise TemplateRuntimeError(%r)zextended multiple timesz+parent_template = environment.get_template(z, %r)z6for name, parent_block in parent_template.blocks.%s():z8context.blocks.setdefault(name, []).append(parent_block)Tr�N)rUr�r�r�r�r�r�r�r�r#�templater�r(�dict_item_iterrV)rGr&r�rrr�
visit_Extendsos.		
	

		
	


		zCodeGenerator.visit_ExtendscCs�|jr|j|�|jr6|jd�|j�d}t|jtj�r�t|jj	t
�rod}q�t|jj	ttf�r�d}n$t|jtj
tjf�r�d}|jd||�|j|j|�|jd|j�|jrJ|j�|jd�|j�|jd�|j�|jd	�|j�|jrc|jd
�n
|jd�|j�|jd|�|j�|jr�|j�d
S)zHandles includes.ztry:Zget_or_select_templateZget_templateZselect_templateztemplate = environment.%s(z, %r)zexcept TemplateNotFound:r�zelse:z]for event in template.root_render_func(template.new_context(context.parent, True, locals())):z*for event in template.module._body_stream:r�N)�with_contextr�Zignore_missingr�r�r!r�rZConstr9rr3r4ZTupleZListr#r�r(r�r�)rGr&r��	func_namerrr�
visit_Include�s@	
	

			






	


	zCodeGenerator.visit_IncludecCs�|jr|j|�|jd|j|�|jrJ|jd|j�|jd�|j|j|�|jd|j�|jr�|jd�n
|jd�|jr�|jj	d�r�|jd|j�|j
j|j�d	S)
zVisit regular imports.zl_%s = zcontext.vars[%r] = zenvironment.get_template(z, %r).z+make_module(context.parent, True, locals())r��_z!context.exported_vars.discard(%r)N)r�r�r�r�rUr�r#r�r(�
startswithrZrJ)rGr&r�rrrr��s	
	
	
zCodeGenerator.visit_ImportcCs.|j|�|jd�|j|j|�|jd|j�|jrZ|jd�n
|jd�g}g}x�|jD]�}t|t�r�|\}}n|}|j	d||f�|j	d|�|j
�|j	d|d|j|�jd	d
�jdd�t
|�f|f�|j�|jr`|j|�|jd
�s`|j|�|jj|�q}W|r�t|�dkr�|d}|j	d||f�n'|j	ddjdd�|D���|r*t|�dkr|j	d|d�n#|j	ddjtt
|���dS)zVisit named imports.z-included_template = environment.get_template(z, %r).z!make_module(context.parent, True)r�z.l_%s = getattr(included_template, %r, missing)zif l_%s is missing:zGl_%s = environment.undefined(%r %% included_template.__name__, name=%r)zGthe template %%r (imported on %s) does not export the requested name %s�{z{{r�z}}r�r�rzcontext.vars[%r] = l_%szcontext.vars.update({%s})z, css|]}d||fVqdS)z%r: l_%sNr)rdr(rrrrfsz1CodeGenerator.visit_FromImport.<locals>.<genexpr>z!context.exported_vars.discard(%r)z-context.exported_vars.difference_update((%s))N)r�r�r#r�r(r�r?r!r3r�r�r��replacer�r�rUr�r�rZrJr�r�r)rGr&r�Z	var_namesZdiscarded_namesr(r�rrrr��sP

	
	
	$

	


		zCodeGenerator.visit_FromImportc
Cs�|jdd#�}|jr9|j|||dd�}n|j�}|j|�|jpydt|jdd$�d%�k}|js�|j|d&�}n-|jd|�|j�|j	|�i}|r�|jd	�|j
jd�xK|jt
j�D]7}|jd
kr�|jdkr�|jd|j�q�W|j|�|jrk|j�}|jd|�d|kr�dt|jdd'�d(�kr�|jdd|j|��|jd|�|j|j|�|j|r�dp�d�|r�|jdk	r�|jd�|j|j|�|jd�|j|j|�|jd�|jrm|jd�n|j|j|�|jd�|j�}	|j|j|	�|jd�n,|jr�|jd�n|j|j|�|jr|jd�n|j|rdpd�|r�|jdk	r�|j�|jd�|j|j|�|jd�|j�|jd�|jd�|j�|j|j|�|jr�|jd|�|j�|jr
|jd |�|j�|j|j|�|j�|js&|j ||�|jr�|j!|�|j�|j"||�|jd!�|j|j|�|jd"�|j#|�dS))N�excluder�r�Fr�Zonlyr{z-def loop(reciter, loop_render_func, depth=0):zl_loop = missingrvz8Can't assign to special loop variable in for-loop targetz%s = 1r|rzz/l_loop = environment.undefined(%r, name='loop')z�'loop' is undefined. the filter section of a loop as well as the else block don't have access to the special 'loop' variable of the current loop.  Because there is no parent loop it's undefined.  Happened in loop on %szfor z, l_loop in LoopContext(z in �(z for Zreciterz if (z))z, loop_render_func, depth):z):�:zif not �continuer�z%s = 0zif %s:zloop(z, loop))ziter)zbody)�loop)r�)zelse_ztest)r�)$r�Z	recursiver�rircrAr�r�r�rXrTrKr�r�Namertr(r�r�r�r|r�r�r#r�r�rzr�rMr�r�r{r�r�r�r�)
rGr&r�r�Z
loop_frameZ
extended_loopr�r(Ziteration_indicatorZ
test_framerrrr�s�	
	


	
		


	
		






	
	

		



zCodeGenerator.visit_ForcCs�|j�}|jd|�|j|j|�|jd�|j�|j|j|�|j�|j	r�|jd�|j�|j|j	|�|j�dS)Nzif r�zelse:)
rjr�r#rzr�r�r�r{r�r|)rGr&r�Zif_framerrrr~�s


	

zCodeGenerator.visit_IfcCs�|j||�}|j�|jr_|jjd�sK|jd|j�|jd|j�|jd|j�|j||�|jj	|j�dS)Nr�zcontext.exported_vars.add(%r)zcontext.vars[%r] = zl_%s = )
r�r�rUr(r�r�r�r�rZrJ)rGr&r�Zmacro_framerrrr�s
	zCodeGenerator.visit_MacrocCs~|jdd�}|j|||�}|jd�|j||�|j||�|j|j|dd�|j|�dS)Nr�r�z	caller = �forward_callerT)zcall)r�r�r�r�r��
visit_Callr�r�)rGr&r�r�Z
call_framerrrr��s
zCodeGenerator.visit_CallBlockcCs�|j�}|j|j��|j|�}|j|�|j|�|j|j|�|j||�|j	|j
|�|j|�|j||�dS)N)
rircr�r�r�rXr�r{r�rpr�r�r�)rGr&r�Zfilter_framer�rrrr��s


zCodeGenerator.visit_FilterBlockcCs$|j|�|j|j|�dS)N)r�r#r&)rGr&r�rrr�visit_ExprStmt�s
zCodeGenerator.visit_ExprStmtcs��jr|jrdSd}�jjr��jj}t|dd�sXt|dd�rad}q�t|dd�r��fdd�}q��fdd�}nt}d}|jr��jd	��j�d}g}x	|jD]�}y(|s�tj	��|j
|j�}	Wn%tj	k
r4|j|�w�YnXyF|jj
rnt|	d
�rb|	j�}	nt|	�}	||	�}	Wn"tk
r�|j|�w�YnX|r�t|dt�r�|d j|	�q�|j|	g�q�Wt|�dks|jdk	r|jdk	rXt|�dkr:�jd
|j�n�jd|j��j�xk|D]c}
t|
t�r�tt|
��}|jdkr��jd|�q��j|d�q_|jdkr��jd|
�n
�j|
�d}|jjr�jd�n)|jj
r*�jd�n
�jd��jjdk	r��jd�t�jjdd�r{�jd�|d7}�j|
|��jd|�|jdk	r_�jd�q_W|jdk	r��j��jt|�dkr�dpd�n�g}
g}xY|D]Q}
t|
t�rQ|
jt|
�jdd��q|
jd�|j|
�qW�jd��jtt|
��d��j�x-|D]%}�j|�d}|jjr��jd�|d7}n#|jj
r�jd�|d7}�jjdk	r��jd�t�jjdd�rS�jd�nMt�jjdd�r{�jd�n%t�jjdd�r��jd�|d7}�j||��jd|d�q�W�j��jd�|r��j�dS)!NTZcontextfunctionFZevalcontextfunctionZenvironmentfunctioncst�jj�j|��S)N)r
r'�finalize)r)rGrr�<lambda>�sz,CodeGenerator.visit_Output.<locals>.<lambda>cst�jj|��S)N)r
r'r)r)rGrrr�szif parent_template is None:�__html__r��z
%s.append(z%s.extend((zyield z, z6(context.eval_ctx.autoescape and escape or to_string)(zescape(z
to_string(zenvironment.finalize(z	context, r�z))�%z%%z%sz % (rzcontext.eval_ctx, z
environment, ���r)r�rWr'rr�r
r�r�r�
Impossible�as_constrSr�r��hasattrrr�	Exceptionr!r4r�rXr�r
r�r�r�r#r�r�)rGr&r�Zallow_constant_finalize�funcrZ
outdent_laterr{�childZconstr:�val�close�formatr�Zargumentr)rGr�visit_Output�s�		




!







(
"













zCodeGenerator.visit_OutputcCs)|js
|S|j�}t�|_|S)N)rUrMr5�toplevel_assignments)rGr��assignment_framerrr�make_assignment_frameQs
	z#CodeGenerator.make_assignment_framecCs"|js
dSdd�|jD�}t|j�dkrgtt|j��}|jd||f�nd|jd�xGt|j�D]6\}}|r�|jd�|jd||f�q�W|jd�|rt|�dkr�|jd	|d
�n#|jddjt	t
|���dS)NcSs%g|]}|jd�s|�qS)r�)r�)rdrrrrr�_s	z6CodeGenerator.export_assigned_vars.<locals>.<listcomp>r�zcontext.vars[%r] = l_%szcontext.vars.update({z, z%r: l_%sz})zcontext.exported_vars.add(%r)rz"context.exported_vars.update((%s)))rUrr��nextr�r��	enumerater�r�rr�)rGr�rZpublic_namesr(�idxrrr�export_assigned_vars\s$	


		z"CodeGenerator.export_assigned_varscCsc|j|�|j|�}|j|j|�|jd�|j|j|�|j||�dS)Nz = )r�rr#r�r�r&r)rGr&r�rrrrr�ss

zCodeGenerator.visit_AssigncCs�|j�}|j|j�|j|�}|j|�|j|�|j|j|�|j||�|j|�}|j	|�|j
|j|�|jd|j�|j
||�dS)Nz
 = concat(%s))rircr{r�r�rXr�r�rr�r#r�r�r)rGr&r�r�r�rrrrr�{s


zCodeGenerator.visit_AssignBlockcCsV|jdkr+|jr+|jj|j�|jd|j�|jj|j�dS)Nrvr�)rtrUrrJr(r�rZ)rGr&r�rrrru�szCodeGenerator.visit_NamecCsE|j}t|t�r.|jt|��n|jt|��dS)N)r9r!r1r��strr�)rGr&r�rrrr�visit_Const�s	zCodeGenerator.visit_ConstcCsSy#|jt|j|j���Wn)tjk
rN|jd|j�YnXdS)Nz8(context.eval_ctx.autoescape and Markup or identity)(%r))r�r�rrSrr�data)rGr&r�rrr�visit_TemplateData�s
#	z CodeGenerator.visit_TemplateDatacCsy|jd�d}x@t|j�D]/\}}|rB|jd�|j||�q#W|j|dkrndpqd�dS)Nr�r�z, rz,)r�r)r�rrr#)rGr&r�rr:rrr�visit_Tuple�s

zCodeGenerator.visit_TuplecCsa|jd�x@t|j�D]/\}}|r<|jd�|j||�qW|jd�dS)N�[z, �])r�rrr#)rGr&r�rr:rrr�
visit_List�s

zCodeGenerator.visit_ListcCs�|jd�xct|j�D]R\}}|r<|jd�|j|j|�|jd�|j|j|�qW|jd�dS)Nr�z, z: r�)r�rrr#r;r9)rGr&r�rr:rrr�
visit_Dict�s


zCodeGenerator.visit_Dictcs�fdd�}|S)Ncs�|jjre�|jjkre|jd��|j|j|�|jd�|j|j|�nD|jd�|j|j|�|jd��|j|j|�|jd�dS)Nz$environment.call_binop(context, %r, z, r�z %s r�)r'�	sandboxedZintercepted_binopsr�r#�left�right)rGr&r�)�operatorrrr@�s

z$CodeGenerator.binop.<locals>.visitorr)r#�
interceptabler@r)r#r�binop�s
zCodeGenerator.binopcs�fdd�}|S)Ncsz|jjrE�|jjkrE|jd��|j|j|�n$|jd��|j|j|�|jd�dS)Nz#environment.call_unop(context, %r, r�r�)r'r Zintercepted_unopsr�r#r&)rGr&r�)r#rrr@�sz#CodeGenerator.uaop.<locals>.visitorr)r#r$r@r)r#r�uaop�s	zCodeGenerator.uaop�+�-�*�/z//z**r�andr$�orznot cCs�|jjrd}n|jjr*d}nd}|jd|�x.|jD]#}|j||�|jd�qKW|jd�dS)Nz;(context.eval_ctx.volatile and markup_join or unicode_join)Zmarkup_joinZunicode_joinz%s((z, z)))rSr�r�r�rr#)rGr&r�r�r�rrr�visit_Concat�s		zCodeGenerator.visit_ConcatcCs;|j|j|�x!|jD]}|j||�qWdS)N)r#�exprZops)rGr&r��oprrr�
visit_Compare�szCodeGenerator.visit_ComparecCs/|jdt|j�|j|j|�dS)Nz %s )r��	operatorsr/r#r.)rGr&r�rrr�
visit_Operand�szCodeGenerator.visit_OperandcCs8|jd�|j|j|�|jd|j�dS)Nzenvironment.getattr(z, %r))r�r#r&�attr)rGr&r�rrr�
visit_Getattr�s
zCodeGenerator.visit_GetattrcCs�t|jtj�rX|j|j|�|jd�|j|j|�|jd�nM|jd�|j|j|�|jd�|j|j|�|jd�dS)Nrrzenvironment.getitem(z, r�)r!r�rZSlicer#r&r�)rGr&r�rrr�
visit_Getitems


zCodeGenerator.visit_GetitemcCs�|jdk	r"|j|j|�|jd�|jdk	rQ|j|j|�|jdk	r�|jd�|j|j|�dS)Nr�)�startr#r��stopr�)rGr&r�rrr�visit_Slices

zCodeGenerator.visit_SlicecCse|j|j|jd�|jjj|j�}|dkrY|jd|j|j�t|dd�r{|jd�nAt|dd�r�|jd�nt|dd�r�|jd	�|jdk	r�|j	|j|�nc|j
jr
|jd
|j|jf�n7|j
j
r0|jd|j�n|jd|j�|j||�|jd
�dS)Nr�zno filter named %rZ
contextfilterFz	context, Zevalcontextfilterzcontext.eval_ctx, Zenvironmentfilterz
environment, zB(context.eval_ctx.autoescape and Markup(concat(%s)) or concat(%s))zMarkup(concat(%s))z
concat(%s)r�)r�rmr(r'�getr�r�r�r&r#rSr�rXr�r�)rGr&r�r
rrrrps(
	zCodeGenerator.visit_FiltercCs~|j|j|jd�|j|jjkrJ|jd|j|j�|j|j|�|j||�|jd�dS)Nr�zno test named %rr�)	r�rnr(r'r�r�r#r&r�)rGr&r�rrrrq4szCodeGenerator.visit_Testcs}���fdd�}�jd��j�j���jd��j�j���jd�|��jd�dS)NcsD�jdk	r"�j�j��S�jdd�j���dS)Nzenvironment.undefined(%r)zRthe inline if-expression on %s evaluated to false and no else section was defined.)Zexpr2r#r�r�r)r�r&rGrr�write_expr2=sz1CodeGenerator.visit_CondExpr.<locals>.write_expr2r�z if z else r�)r�r#Zexpr1rz)rGr&r�r:r)r�r&rGr�visit_CondExpr<s


zCodeGenerator.visit_CondExprcCsx|jjr|jd�n
|jd�|j|j|�|rNddipQd}|j|||�|jd�dS)Nzenvironment.call(context, z
context.call(r�r�)r'r r�r#r&r�)rGr&r�r�r�rrrr�Ls
zCodeGenerator.visit_CallcCs+|j|jd�|j|j|�dS)N�=)r�r;r#r9)rGr&r�rrr�
visit_KeywordVszCodeGenerator.visit_KeywordcCs1|jd�|j|j|�|jd�dS)NzMarkup(r�)r�r#r.)rGr&r�rrr�visit_MarkSafe\s
zCodeGenerator.visit_MarkSafecCs1|jd�|j|j|�|jd�dS)Nz5(context.eval_ctx.autoescape and Markup or identity)(r�)r�r#r.)rGr&r�rrr�visit_MarkSafeIfAutoescapeas
z(CodeGenerator.visit_MarkSafeIfAutoescapecCs|jd|j�dS)Nzenvironment.)r�r()rGr&r�rrr�visit_EnvironmentAttributefsz(CodeGenerator.visit_EnvironmentAttributecCs!|jd|j|jf�dS)Nzenvironment.extensions[%r].%s)r�Z
identifierr()rGr&r�rrr�visit_ExtensionAttributeisz&CodeGenerator.visit_ExtensionAttributecCs|j|j|j�dS)N)r�r�r�)rGr&r�rrr�visit_ImportedNamelsz CodeGenerator.visit_ImportedNamecCs|j|j�dS)N)r�r()rGr&r�rrr�visit_InternalNameosz CodeGenerator.visit_InternalNamecCs|jd�dS)Nr�)r�)rGr&r�rrr�visit_ContextReferencersz$CodeGenerator.visit_ContextReferencecCs|jd|�dS)Nr�)r�)rGr&r�rrr�visit_ContinueuszCodeGenerator.visit_ContinuecCs|jd|�dS)N�break)r�)rGr&r�rrr�visit_BreakxszCodeGenerator.visit_BreakcCsb|j�}|j|j��|j|�}|j|�|j|j|�|j||�dS)N)rircr�r�r�r�r{r�)rGr&r�Zscope_framer�rrrr�{s
zCodeGenerator.visit_Scopec
Cs�x�|jD]�}|jd|j�|j|j|�y|jj|j�}Wn!tjk
rsd|j_	Yq
Xt
|j|j|�q
WdS)Nzcontext.eval_ctx.%s = T)Zoptionsr�r;r#r9rrSrrr��setattr)rGr&r��keywordrrrr�visit_EvalContextModifier�sz'CodeGenerator.visit_EvalContextModifiercCs�|j�}|jj�}|jd|�|j||�x!|jD]}|j||�qFW|jj|�|jd|�dS)Nz%s = context.eval_ctx.save()zcontext.eval_ctx.revert(%s))r�rSZsaver�rJr{r#Zrevert)rGr&r�Zold_ctx_nameZ	safed_ctxrrrr�visit_ScopedEvalContextModifier�sz-CodeGenerator.visit_ScopedEvalContextModifier)WrNrOrPrHr�r�rXr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr�r�r�r�r�r~rr�r�r�rrrr�r�rurrrrrr%r&Z	visit_AddZ	visit_SubZ	visit_MulZ	visit_DivZvisit_FloorDivZ	visit_PowZ	visit_ModZ	visit_AndZvisit_OrZ	visit_PosZ	visit_NegZ	visit_Notr-r0r2r4r5r8rprqr;r�r=r>r?r@rArBrCrDrErGr�rJrKrrrrr�ps�65
D	c/+5~	�	


r�)0rQ�	itertoolsrrMrrIrr�Zjinja2rZjinja2.nodesrZjinja2.visitorrZjinja2.exceptionsrZjinja2.utilsr	r
rZjinja2._compatrr
rrrrr1rr8r�rr/r�r,r7rAr]rBrR�RuntimeErrorr=rlr<rbr	r�r�rrrr�<module>
sF.	
%XY

Zerion Mini Shell 1.0