/usr/local/lib/python3.6/site-packages/jinja2/__pycache__
NameSizeModeActions
async_utils.cpython-36.pyc24350644editdlrm
bccache.cpython-36.pyc130970644editdlrm
compiler.cpython-36.pyc543690644editdlrm
constants.cpython-36.pyc14960644editdlrm
debug.cpython-36.pyc53440644editdlrm
defaults.cpython-36.pyc12410644editdlrm
environment.cpython-36.pyc523970644editdlrm
exceptions.cpython-36.pyc54980644editdlrm
ext.cpython-36.pyc262740644editdlrm
filters.cpython-36.pyc497540644editdlrm
idtracking.cpython-36.pyc111250644editdlrm
lexer.cpython-36.pyc199830644editdlrm
loaders.cpython-36.pyc202170644editdlrm
meta.cpython-36.pyc37460644editdlrm
nativetypes.cpython-36.pyc48050644editdlrm
nodes.cpython-36.pyc411930644editdlrm
optimizer.cpython-36.pyc18610644editdlrm
parser.cpython-36.pyc276350644editdlrm
runtime.cpython-36.pyc328630644editdlrm
sandbox.cpython-36.pyc116960644editdlrm
tests.cpython-36.pyc64820644editdlrm
utils.cpython-36.pyc272170644editdlrm
visitor.cpython-36.pyc38390644editdlrm
_identifier.cpython-36.pyc18500644editdlrm
__init__.cpython-36.pyc18650644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/jinja2/__pycache__/compiler.cpython-36.pyc (54369B)
3 ^TBg @srdZddlZddlmZddlmZddlmZddl m Z ddl m Z ddlmZdd lmZd d lmZd d lmZd d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlm Z d dl!m"Z"ej#r ddl$Z%d dl&m'Z'ej(dej)dej*fdZ+dddddd d!d"d#Z,e+e+d$d%d&Z-e.ej)d'ej/d(gdfd)d*d+Z0e.ej)d'ej1d(gdfd)d,d-Z2dFej3d0ej4e.ej4e.ej4ej5e6e6ej4e.d1d2d3Z7ej*e6d4d5d6Z8ej9ej:ej9e.ej;e.d7d8d9ZGd=d>d>e?Z@Gd?d@d@e"ZAGdAdBdBe"ZBGdCdDdDeCZDGdEd'd'e"ZEdS)Gz0Compiles nodes from the parser into Python code.N)contextmanager)update_wrapper)StringIO)chain) iskeyword)escape)Markup)nodes)TemplateAssertionError)Symbols)VAR_LOAD_ALIAS)VAR_LOAD_PARAMETER)VAR_LOAD_RESOLVE)VAR_LOAD_UNDEFINED) EvalContext) Optimizer)_PassArg)concat) NodeVisitor) EnvironmentF.)Zboundz==z!=>z>=.new_func)r ExprtAnyrcastr)r r.r,)r r- optimizeconst+s  r3r"r#)opr!cs"tdtjtddfdd }|S)Nr")r$r%r&r!cs|jjrN|jjkrN|jdd|j|j||jd|j|j|n8|jd|j|j||jdd|j|j||jddS)Nz environment.call_binop(context, z, ( )) environment sandboxedZintercepted_binopswriter+leftright)r$r%r&)r4r,r-visitor<s   z_make_binop..visitor)r3r BinExprr#)r4r=r,)r4r- _make_binop;sr?cs"tdtjtddfdd }|S)Nr")r$r%r&r!cs`|jjr6|jjkr6|jdd|j|j|n|jd|j|j||jddS)Nzenvironment.call_unop(context, z, r5r7)r8r9Zintercepted_unopsr:r+r%)r$r%r&)r4r,r-r=Ts z_make_unop..visitor)r3r UnaryExprr#)r4r=r,)r4r- _make_unopQs rAFTr)r%r8namefilenamestream defer_init optimizedr!cCsHt|tjstd|j||||||}|j||dkrD|jjSdS)z+Generate the python source for a node tree.z Can't compile non template nodesN) isinstancer Template TypeErrorZcode_generator_classr+rDgetvalue)r%r8rBrCrDrErF generatorr,r,r-generatees   rL)valuer!cCs|dks|tks|tkrdSt|ttttttt hkr:dSt|t t t t hkr`tdd|DSt|tkrtdd|jDSdS)z)Does the node have a safe representation?NTcss|]}t|VqdS)N) has_safe_repr).0vr,r,r- sz has_safe_repr..css"|]\}}t|ot|VqdS)N)rN)rOkrPr,r,r-rQsF)NotImplementedEllipsistypeboolintfloatcomplexrangestrrtuplelistset frozensetalldictitems)rMr,r,r-rN}s rN)r namesr!c Cs@t|}yx|D]}|j|qWWntk r8YnX|jS)zCheck 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 rcr=r%r,r,r-find_undeclareds rgc@s*eZdZejejejfddddZdS)MacroRefN)r%r!cCs||_d|_d|_d|_dS)NF)r%accesses_calleraccesses_kwargsaccesses_varargs)r$r%r,r,r-__init__szMacroRef.__init__) __name__ __module__ __qualname__r0Unionr Macro CallBlockrlr,r,r,r-rhsrhc@sdeZdZdZdeejdejeddddZddddZ de dd d d Z ddd dZ e Z dS)r#z&Holds compile time information for us.N)r)parentlevelr!cCs~||_||_|dkr4t|d|_d|_d|_d|_n(t|j|d|_|j|_|j|_|j|_d|_d|_d|_ d|_ d|_ dS)N)rtF) r)rsr symbolsrequire_output_checkbufferblocktoplevel rootlevel loop_frame block_frame soft_frame)r$r)rsrtr,r,r-rls  zFrame.__init__)r!cCs2tjttj|j}|jj|j|jj |_|S)z!Create a copy of the current one.) r0r2r#object__new__ __class____dict__updaterucopy)r$rvr,r,r-rs z Frame.copyF)isolatedr!cCs&|rt|j|jjddSt|j|S)zReturn an inner frame.r )rt)r#r)rurt)r$rr,r,r-innersz Frame.innercCs|j}d|_d|_|S)a&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. This is only used to implement if-statements and conditional expressions. FT)rrzr})r$rr,r,r-softsz Frame.soft)NN)F)rmrnro__doc__rr0OptionalrWrlrrVrr__copy__r,r,r,r-r#s. c@seZdZdZdS)rez?Exception used by the `UndeclaredNameVisitor` to signal a stop.N)rmrnrorr,r,r,r-resrec@sTeZdZdZddddZejddddZejddd d Z ej ddd d Z dS) DependencyFinderVisitorz.A visitor that collects filter and test calls.N)r!cCst|_t|_dS)N)r^filterstests)r$r,r,r-rlsz DependencyFinderVisitor.__init__)r%r!cCs|j||jj|jdS)N) generic_visitraddrB)r$r%r,r,r- visit_Filters z$DependencyFinderVisitor.visit_FiltercCs|j||jj|jdS)N)rrrrB)r$r%r,r,r- visit_Tests z"DependencyFinderVisitor.visit_TestcCsdS)zStop visiting at blocks.Nr,)r$r%r,r,r- visit_Block sz#DependencyFinderVisitor.visit_Block) rmrnrorrlr FilterrTestrBlockrr,r,r,r-rs rc@sJeZdZdZejeddddZej ddddZ ej ddd d Z dS) rdzA 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. N)rcr!cCst||_t|_dS)N)r^rcrf)r$rcr,r,r-rls zUndeclaredNameVisitor.__init__)r%r!cCsJ|jdkr8|j|jkr8|jj|j|j|jkrFtn|jj|jdS)Nload)ctxrBrcrfrrediscard)r$r%r,r,r- visit_Names  z UndeclaredNameVisitor.visit_NamecCsdS)zStop visiting a blocks.Nr,)r$r%r,r,r-r!sz!UndeclaredNameVisitor.visit_Block) rmrnrorr0Iterabler[rlr Namerrrr,r,r,r-rdsrdc@seZdZdZdS) CompilerExitzRaised 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)rmrnrorr,r,r,r-r%src @sFeZdZUddejeejeejejeeddddZe edd d Z ee d d d dZ edddZ eddddZdeeddddZddddZde ddddZdeejejddddZeddd d!Zdeeejejdd"d#d$Zejejedd%d&d'Zedd(d)d*Zdeejeje dd,d-d.Zdejeje dd/d0d1Zdejejejej feejej!eej"fdd2d3d4Z#ejejdd5d6d7Z$eddd8d9Z%deedd:d;d<Z&deeed?d@dAZ'eedBdCdDZ(ejej)ej*feej+ee,fdEdFdGZ-e,eddHdIdJZ.ejedKdLdMZ/eeddNdOZ0dddPdQZ1edddRdSZ2dddTdUZ3eddVdWdXZ4eddVdYdZZ5ddd[d\Z6edd]d^Z7edd_d`Z8eeddadbZ9eedVdcddZ:dddedfZ;edddgdhZej?eddEdkdlZ@ejAeddEdmdnZBejCeddEdodpZDejejEejFfeddEdqdrZGejEeddEdsdtZHejFeddEdudvZIejJeddEdwdxZKejLeddEdydzZMej)eddEd{d|ZNej*eddEd}d~ZOejPeddEddZQejReddEddZSejTeddEddZUGdddejVZWeXej"ej"dddZYdZZejeWZeWdddZ[ejej"edddZ\ej]eeWedddZ^ej]eeWddddZ_ej]eeWddddZ`ejaeddEddZbejceddEddZdejeeddEddZfejgeddEddZhejieddEddZjejkeddEddZlejmeddEddZnej+eddEddZoejpeddEddZqejreddEddZsetdZuetdZvetdZwetdZxetdZyetdZzetdZ{etdZ|etdZ}e~dZe~dZe~dZeejeddEddZeejeddEddZejeddEddZeejeddEddZeejeddEddZejeddEddZeejejej feeejdddd„ZeejeddEddĄZeej eddEddƄZeejeddEddȄZedejeeddɜdd˄ZejeddEdd̈́ZejeddEddτZejeddEddфZejeddEddӄZejeddEddՄZejeddEddׄZejeddEddلZejeddEddۄZejeddEdd݄ZejeddEdd߄ZejeddEddZejeddEddZejeddEddZejeddEddZejeddEddZdS)r"NFTr)r8rBrCrDrErFr!cCs|dkrt}||_||_||_||_d|_||_d|_|rFt||_i|_ i|_ d|_ d|_ d|_ i|_i|_g|_d|_d|_d|_d|_d|_d|_g|_g|_dg|_dS)NFrr Tcontext)rr8rBrCrDZcreated_block_contextrEr(rimport_aliasesblocksextends_so_farhas_known_extends code_linenorr debug_info_write_debug_info _new_lines _last_line _first_write_last_identifier _indentation _assign_stack_param_def_block_context_reference_stack)r$r8rBrCrDrErFr,r,r-rl-s8  zCodeGenerator.__init__)r!cCs |jdk S)N)r()r$r,r,r-rFvszCodeGenerator.optimizedz te.NoReturn)msglinenor!cCst|||j|jdS)z*Fail with a :exc:`TemplateAssertionError`.N)r rBrC)r$rrr,r,r-fail|szCodeGenerator.failcCs|jd7_d|jS)zGet a new unique identifier.r Zt_)r)r$r,r,r-temporary_identifiersz"CodeGenerator.temporary_identifier)r&r!cCs |j|_|j|jddS)z7Enable buffering for the frame from that point onwards.z = []N)rrw writeline)r$r&r,r,r-rws zCodeGenerator.buffer)r&force_unescapedr!cCs|s|jjrl|jd|j|jd|jd|j|jd|j|jd|jd|jdS|jjr|jd|jddS|jd|jddS)z(Return the buffer contents of the frame.zif context.eval_ctx.autoescape:zreturn Markup(concat(z))zelse:zreturn concat(r7N)r)r*rindentrwoutdent autoescape)r$r&rr,r,r-return_buffer_contentss  z$CodeGenerator.return_buffer_contentscCs|jd7_dS)zIndent by one.r N)r)r$r,r,r-rszCodeGenerator.indentr )stepr!cCs|j|8_dS)zOutdent by step.N)r)r$rr,r,r-rszCodeGenerator.outdent)r&r%r!cCs0|jdkr|jd|n|j|jd|dS)z%Yield or write into the frame buffer.Nzyield z.append()rwr)r$r&r%r,r,r- start_writes zCodeGenerator.start_writecCs|jdk r|jddS)z1End the writing process started by `start_write`.Nr7)rwr:)r$r&r,r,r- end_writes zCodeGenerator.end_write)sr&r%r!cCs$|j|||j||j|dS)z4Simple shortcut for start_write + write + end_write.N)rr:r)r$rr&r%r,r,r- simple_writes  zCodeGenerator.simple_write)r r&r!c CsBy(|jdx|D]}|j||qWWntk r<YnXdS)zVisit 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. passN)rr+r)r$r r&r%r,r,r- blockvisits   zCodeGenerator.blockvisit)xr!cCs|jrp|jsR|jjd|j|j|j7_|jdk rR|jj|j|jfd|_d|_|jjd|jd|_|jj|dS)z&Write a string into the output stream. NFz r) rrrDr:rrrappendr)r$rr,r,r-r:s zCodeGenerator.writer)rr%extrar!cCs|j|||j|dS)z!Combination of newline and write.N)newliner:)r$rr%rr,r,r-rs zCodeGenerator.writeline)r%rr!cCs:t|jd||_|dk r6|j|jkr6|j|_|j|_dS)z/Add one or more newlines before the next write.r N)maxrrrr)r$r%rr,r,r-rszCodeGenerator.newline)r%r& extra_kwargsr!c Cstddtdd|jD|pfD}x$|jD]}|jd|j||q0W|sx$|jD]}|jd|j||qZW|dk rx*|jD]\}}|jd|d|qW|jr|jd|j|j||r|jdk r|jdn |jd x8|jD].}|j|j d |j|j ||jdqW|dk rbx,|jD] \}}|j|d |dq>W|jdk r|jd |j|j||jd n |jd n$|jdk r|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 occur. The extra keyword arguments should be given as python dict. css|]}ttjt|VqdS)N)is_python_keywordr0r2r[)rOrRr,r,r-rQsz*CodeGenerator.signature..css|] }|jVqdS)N)key)rOrr,r,r-rQsz, N=z, *z , **dict({z, **{z: z}, **r7}z, **) anyrr'argsr:r+rbZdyn_argsZ dyn_kwargsrrM) r$r%r&rZkwarg_workaroundargZkwargrrMr,r,r- signaturesF                 zCodeGenerator.signature)r r!c Cst}x|D]}|j|q Wx|j|jdf|j|jdffD]\}}}xt|D]}||krh|j||<|jd|j|j||d|d|d|j|jd|j|jd|jd ||d |j|jd |d dd|d|j|jqPWqg}x|jjD]}|j|qW|r>|jdj|ddS)Nz = z = missing)rurrrr)r$r&rrrr,r,r- leave_frameUs zCodeGenerator.leave_frameasync ) async_value sync_valuer!cCs|jjr |S|S)N)r8is_async)r$rrr,r,r- choose_async]szCodeGenerator.choose_async)rBr!cCs|jd|S)Nzdef )r)r$rBr,r,r-func`szCodeGenerator.func)r%r&r!c Cs|j}|jj|t|}d}t}g}xNt|jD]@\}}|jdkrL|}|jdkrb|j|j|j |jj |jq6Wt |j d} d| kr|dk ry|j |t|jWqtk r|jd|jYqXn|j |jjdd|_d| krd|kr|j |jjdd|_d| krDd|krD|j |jjdd|_d|_|jj||j|jdd d j|d ||j|j||j||j|xt|jD]\}}|jj |j} |jd | d |jy|j |t|j} Wn6tk r*|j| d|jd|jdYnX|j| d|j| ||j| |j qW|j!|j"|j ||j#|dd|j$|dd|j ||fS)z/Dump the function def of a macro or call block.Ncallerr'varargszhWhen defining macros or call blocks the special "caller" argument must be omitted or be given a default.TFmacror5z, z):zif z is missing:z = undefined("parameter z was not provided", name=r7z = )r)r)r'r)rr'r)%rru analyze_noderhr^ enumeraterrBrrrefrgbodydefaultslen IndexErrorrrdeclare_parameterrirjrkrvrrrrrwrpush_parameter_definitionsr+mark_parameter_storedrpop_parameter_definitionsrrr) r$r%r& macro_refZexplicit_callerZskip_special_paramsridxrrfrdefaultr,r,r- macro_bodycsn      $   "  zCodeGenerator.macro_body)rr&r!c Csrdjdd|jjD}t|jdd}t|jjdkr>|d7}|jd|d |d |jd|jd|jd dS) z.rBNr ,zMacro(environment, macro, z, (z), z, context.eval_ctx.autoescape)) rr%rgetattrrr:rjrkri)r$rr&Z arg_tuplerBr,r,r- macro_defs zCodeGenerator.macro_def)r%r!cCs*d|j}|jdk r&|d|j}|S)z.Return a human readable position for the node.zline Nz in )rrB)r$r%rr,r,r-positions  zCodeGenerator.positioncCs*djdd|jjjD}d|dS)Nz, css |]\}}|d|VqdS)z: Nr,)rOrBrr,r,r-rQsz3CodeGenerator.dump_local_context..{r)rruZ dump_storesrb)r$r&Zitems_kvr,r,r-dump_local_contextsz CodeGenerator.dump_local_contextcCs,|jd|jd|jd|jddS)zWrites a common preamble that is used by root and block functions. Primarily this sets up common local helpers and enforces a generator through a dead branch. z$resolve = context.resolve_or_missingz!undefined = environment.undefinedzcond_expr_undefined = Undefinedzif 0: yield NoneN)r)r$r,r,r- write_commonss   zCodeGenerator.write_commonscCs|jj|jjdS)aQPushes all parameter targets from the given frame into a local stack that permits tracking of yet to be assigned parameters. In particular this enables the optimization from `visit_Name` to skip undefined expressions for parameters in macros as macros can reference otherwise unbound parameters. N)rrruZdump_param_targets)r$r&r,r,r-rsz(CodeGenerator.push_parameter_definitionscCs|jjdS)z+Pops the current parameter definitions set.N)rpop)r$r,r,r-rsz'CodeGenerator.pop_parameter_definitions)rr!cCs|jr|jdj|dS)zMarks a parameter in the current parameter definitions as stored. This will skip the enforced undefined checks. r Nr)rr)r$rr,r,r-rsz#CodeGenerator.mark_parameter_storedcCs|jj|dS)N)rr)r$rr,r,r-push_context_referencesz$CodeGenerator.push_context_referencecCs|jjdS)N)rr)r$r,r,r-pop_context_referencesz#CodeGenerator.pop_context_referencecCs |jdS)Nr r)r)r$r,r,r-get_context_refszCodeGenerator.get_context_refcCs |jd}|dkrdS|dS)Nr rresolvez.resolver)r)r$rr,r,r-rs zCodeGenerator.get_resolve_funccCs|jd|j|dS)Nz .derived(r7)rr)r$r&r,r,r-derive_contextszCodeGenerator.derive_contextcCs|js dS||jdkS)z4Checks if a given target is an undeclared parameter.Fr r)r)r$rr,r,r-parameter_is_undeclaredsz%CodeGenerator.parameter_is_undeclaredcCs|jjtdS)z+Pushes a new layer for assignment tracking.N)rrr^)r$r,r,r-push_assign_trackingsz"CodeGenerator.push_assign_trackingcCs|jj}|j r"|j r"|j s(| r,dSdd|D}t|dkrtt|}|jj |}|jr~|j d|d|dS|jr|j d|d|dS|j d|d|n~|jr|j d n|jr|j d n |j d xDt |D]8\}}|r|j d |jj |}|j |d |qW|j d|j r|j r|rt|dkrt|j d|ddn"d j tt|}|j d|ddS)zoPops the topmost level for assignment tracking and updates the context variables if necessary. NcSs g|]}|dddkr|qS)Nr _r,)rOrr,r,r- sz5CodeGenerator.pop_assign_tracking..r z _loop_vars[z] = z _block_vars[z context.vars[z_loop_vars.update({z_block_vars.update({zcontext.vars.update({z, z: z})zcontext.exported_vars.add(rr7zcontext.exported_vars.update((z)))rrr|r{ryrnextiterrurrrr:rmapr)r$r&varsZ public_namesrBrr names_strr,r,r-pop_assign_tracking sB          z!CodeGenerator.pop_assign_trackingcCs$|dkstdt|j|j}ddlm}m}|jjrDt||}nt|}|j d|j ddj ||j rtdnd}|j t jdk }xD|jt jD]4} | j|jkr|jd | jd | j| |j| j<qWx|jt jD]v} | j|jkr| j} |j|j| <} d | kr<| jd d\} }|j d | d |d| q|j d| d| qW|j d|j|j |jdd|ddd|j|jt|}dt|jd+kr|jj d}|j |d|jj!|d|_"|_#|o|j$ |_%|r|j d|j&||j'|j|j(|j||j)|dd|j*|r|j$s`|j|j d|j|jjs~|j dn$|j d|j|j d|j*|j*d|j$ x|jj+D]\}} |j |jd|d|d| d|j|jt|}d|_,t| jd,}d|kr@|jj d}|j |dd|krr|jj d}|j |d |d!|d"|jj!| ||_-|j d#|j&||j'| j|j(| j||j)|dd|j*qWdj d$d%|jD}|j d&|d'ddd(j d)d%|j.D}|j d*|dS)-Nzno root frame allowedr )exportedasync_exportedz%from __future__ import generator_stopzfrom jinja2.runtime import z, rz, environment=environmentzblock z defined twice.zfrom z import z as zimport zname = rootz(context, missing=missingz):)rr$z = TemplateReference(context)Tzparent_template = None)rzif parent_template is not None:z4yield from parent_template.root_render_func(context)z=async for event in parent_template.root_render_func(context):z yield eventZblock_superz = context.super(z, block_r7z_block_vars = {}css|]}|d|VqdS)z: block_Nr,)rOrr,r,r-rQsz/CodeGenerator.visit_Template..z blocks = {r&css |]\}}|d|VqdS)rNr,)rOrRrPr,r,r-rQsz debug_info = )r$)r$r)/AssertionErrorrr8rBZruntimerrrrrrrEfindr Extendsfind_allrrrr ImportedName importnamerrrsplitrrrr#rgrrurrryrzrrvrrrrrrbr|rxr)r$r%r&r)rrZexported_namesZenvenvZ have_extendsrximport_impaliasmoduleobjrrBr|rfZ blocks_kv_strZ debug_kv_strr,r,r-visit_Template9s                       zCodeGenerator.visit_TemplatecCsd}|jr8|jrdS|jdkr8|jd|j|d7}|jrJ|j|}n|j}|jr|jd|j d||j|jd|j d||j |j j r|j dkr|jd |j d |d |n@|j|jd |j d |d ||j|jd||j |j |dS)z.Call a block and register it for the template.rNzif parent_template is None:r zif len(context.blocks[z]) <= 1:z+raise TemplateRuntimeError("Required block z not found")zyield from context.blocks[z][0](r7zfor event in context.blocks[z):event)ryrrrrscopedrrrequiredrBrr8rrwrr)r$r%r&rtrr,r,r-rs8     zCodeGenerator.visit_BlockcCs|js|jd|j|jdkrV|js6|jd|j|jd|jrNtn|j|jd||j |j ||j d|j d|jd|j|jd |j|j rd |_|jd 7_d S) zCalls the extender.z,cannot use extend from a non top-level scoperzif parent_template is not None:z5raise TemplateRuntimeError("extended multiple times")z+parent_template = environment.get_template(z, r7z9for name, parent_block in parent_template.blocks.items():z8context.blocks.setdefault(name, []).append(parent_block)Tr N)ryrrrrrrrrr+templater:rBrz)r$r%r&r,r,r- visit_Extendss(      zCodeGenerator.visit_ExtendscCsp|jr|jd|jd}t|jtjrVt|jjtr>d}qnt|jjt t frnd}nt|jtj tj frnd}|jd|d||j |j||jd|jd|jr|j|jd |j|jd |j|jd |jd }|jr|j|jd |j|dn$|jjr,|jdn|jdd}|s\|j|jd||j|jrl|jdS)zHandles includes.ztry:Zget_or_select_templateZ get_templateZselect_templateztemplate = environment.r5z, r7zexcept TemplateNotFound:rzelse:FzUfor event in template.root_render_func(template.new_context(context.get_all(), True, z)):zGfor event in (await template._get_default_module_async())._body_stream:z6yield from template._get_default_module()._body_streamTr"N)Zignore_missingrrrGr%r ConstrMr[r\r]TupleListr+r:rBr with_contextrrr8rr)r$r%r& func_nameZskip_event_yieldr,r,r- visit_IncludesJ       zCodeGenerator.visit_IncludecCs|j|jdd|j|j||jd|jd|jrld|jd}|j|d|j|dn|jd |jdd dS) Nzawait zenvironment.get_template(z, z).Z make_moduleZ_asyncz(context.get_all(), True, r7Z_get_default_modulez (context))r:rr+r%rBr*r)r$r%r&Zf_namer,r,r-_import_common9szCodeGenerator._import_commoncCsn|j|jj|jd||jr6|jd|jd|j|||jrj|jjd rj|jd|jddS)zVisit regular imports.z = z context.vars[z] = rzcontext.exported_vars.discard(r7N)rrurrryr:r- startswith)r$r%r&r,r,r- visit_ImportHs  zCodeGenerator.visit_Importc s|j||jd|j|g}g}x|jD]}t|trH|\}}n|}|jjj|d|d|jdjj|d|j d|j |d|}|jjj|d|d |d |j j r0|j ||jd s0|j |q0W|r\t|d kr2|d }|jd|djj|n*djfdd|D}|jd|d|rt|d kr|jd|d d n"djtt|} |jd| ddS)zVisit named imports.zincluded_template = z = getattr(included_template, z , missing)zif z is missing:z9the template {included_template.__name__!r} (imported on z%) does not export the requested name z = undefined(fz, name=r7rr rz context.vars[z] = z, c3s$|]}|djj|VqdS)z: N)rur)rOrB)r&r,r-rQysz1CodeGenerator.visit_FromImport..zcontext.vars.update({z})zcontext.exported_vars.discard(z)context.exported_vars.difference_update((z))N)rr:r-rcrGr\rrurrrrryrr.rrr r) r$r%r&Z var_namesZdiscarded_namesrBrmessageZnames_kvr r,)r&r-visit_FromImportSsD          zCodeGenerator.visit_FromImportc Cs|j}d|_|j}|j}|jpRdt|jd)dd*kpRtdd|jtjD}d}|rh|j j d}|j j |dd|j r|j j |dd|j r|j}|j j |d d|j|j|d |j |j|j||j|jd d |j|j||jd |j|jdd|jd|j|jd|j |j|j ||jd|j|jd|j|j||jd|j|dd|jr|j|jdd||j|j||j|_|r|j|dx<|jtjD],} | jdkr| jdkr|jd| jqW|j r4|j} |j| d|j|jd d ||j|j||r||jd|d |jddn |jd |j r|j|d|jr|jdnF|jj r| r|jd|j|j!||jj r| r|jd |j r |jd |jr|jd!n|j|r,d"nd|j|j||jd#|j"|j#||j rt|j| d$|j|j||jo|j d|j r|jd| d|j|j||j"|j ||j||j|jrh|j$||j|j%|||j|jd%d&|jj r2|jd|j|j!||jj rT|jd |jd'|j&||j'r|j'd+j(|j j)dS),NTloopr)onlycss|] }|jVqdS)N)r#)rOrxr,r,r-rQsz*CodeGenerator.visit_For..)Z for_branchelsetestz(fiter):z async for zfor z in zauto_aiter(fiter)Zfiter:zif zyield )rz%(reciter, loop_render_func, depth=0):z = missingstorez8Can't assign to special loop variable in for-loop targetz = 1z, ZAsyncz LoopContext(r5Zreciterz auto_aiter(r7z&, undefined, loop_render_func, depth):z , undefined):z_loop_vars = {}z = 0zawait zloop(z, loop)r )r)r2r)*rr{ recursivergZiter_child_nodesrrr rrurrelse_r5rrrrrrr+rr:rrrwrrrBrrr8rr rrrrrrdifference_updateZstores) r$r%r&r{Z test_frameZ else_frameZ extended_loopZloop_refZloop_filter_funcrBZiteration_indicatorr,r,r- visit_Fors                           zCodeGenerator.visit_ForcCs|j}|jd||j|j||jd|j|j|j||jxP|j D]F}|jd||j|j||jd|j|j|j||jqRW|j r|jd|j|j|j ||jdS)Nzif r6zelif zelse:) rrr+r5r:rrrrelif_r:)r$r%r&Zif_framer=r,r,r-visit_Ifs&       zCodeGenerator.visit_IfcCs||j||\}}|j|jrR|jjds>|jd|jd|jd|jd|j|jj|jd|j ||dS)Nrzcontext.exported_vars.add(r7z context.vars[z] = z = ) rrryrBr.r:rrurr)r$r%r&Z macro_framerr,r,r- visit_Macro%s zCodeGenerator.visit_MacrocCsR|j||\}}|jd|j|||j|||j|j|dd|j|dS)Nz caller = T)forward_caller)rrrr visit_Callcallr)r$r%r&Z call_framerr,r,r-visit_CallBlock/s    zCodeGenerator.visit_CallBlockcCsh|j}|jj||j||j||j|j||j|||j|j ||j ||j |dS)N) rrurrrwrrrrfilterrr)r$r%r&Z filter_framer,r,r-visit_FilterBlock7s     zCodeGenerator.visit_FilterBlockcCs|j}|jj||j|xDt|j|jD]2\}}|j|j|||j d|j||q.W|j |j ||j |dS)Nz = ) rrurrziptargetsvaluesrr+r:rrr)r$r%r&Z with_framerexprr,r,r- visit_WithBs    zCodeGenerator.visit_WithcCs|j||j|j|dS)N)rr+r%)r$r%r&r,r,r-visit_ExprStmtNs zCodeGenerator.visit_ExprStmtc@s,eZdZUejejdefejedS)zCodeGenerator._FinalizeInfo.N) rmrnror0rCallabler[constsrcr,r,r,r- _FinalizeInfoRs rO)rMr!cCst|S)zThe default finalize function if the environment isn't configured with one. Or, if the environment has one, this is called on that function's output for constants. )r[)rMr,r,r-_default_finalizeVszCodeGenerator._default_finalizecsjdk rjSj}d}jjrd}jjtjdtjdtjdijtj}d}|dkr|t j t j dfdd }n2||d }|dkrt j t j dfd d }j ||_jS) aBuild the finalize function to be used on constants and at runtime. Cached so it's only created once for all output nodes. Returns a ``namedtuple`` with the following attributes: ``const`` A function to finalize constant data at compile time. ``src`` Source code to output around nodes to be evaluated at runtime. Nzenvironment.finalize(rzcontext.eval_ctxr8)rMr!cs |S)Nr,)rM)r env_finalizer,r-finalizesz.CodeGenerator._make_finalize..finalizez, csj|S)N)r8)rM)rrQr$r,r-rRs) _finalizerPr8rRrr eval_contextgetfrom_objr0r1rO)r$rRrNpass_argr,)rrQr$r-_make_finalize`s&    zCodeGenerator._make_finalize)groupr!cCs tt|S)zGiven a group of constant values converted from ``Output`` child nodes, produce a string to write to the template module source. )rr)r$rYr,r,r-_output_const_reprsz CodeGenerator._output_const_repr)r%r&rRr!cCs:|j|j}|jjrt|}t|tjr0t|S|j|S)aCTry to optimize a child of an ``Output`` node by trying to convert it to constant, finalized data at compile time. If :exc:`Impossible` is raised, the node is not constant and will be evaluated at runtime. Any other exception will also be evaluated at runtime for easier debugging. ) as_constr)rrrGr TemplateDatar[rM)r$r%r&rRrMr,r,r-_output_child_to_consts  z$CodeGenerator._output_child_to_constcCsL|jjr|jdn|jjr(|jdn |jd|jdk rH|j|jdS)zXOutput extra source code before visiting a child of an ``Output`` node. z1(escape if context.eval_ctx.autoescape else str)(zescape(zstr(N)r)r*r:rrN)r$r%r&rRr,r,r-_output_child_pres    zCodeGenerator._output_child_precCs"|jd|jdk r|jddS)zWOutput extra source code after visiting a child of an ``Output`` node. r7N)r:rN)r$r%r&rRr,r,r-_output_child_posts  z CodeGenerator._output_child_postc Cs|jr"|jrdS|jd|j|j}g}x|jD]}y,|jpLt|tjsVtj |j |||}Wn&tj t fk r|j |w6YnX|rt|d t r|d j |q6|j |gq6W|jdk rt|dkr|j|jdn|j|jd|jx|D]}t|t rR|j|}|jdkrB|jd|n|j|dnb|jdkrl|jd|n |j||j||||j|||j||||jdk r |jdq W|jdk r|j|jt|dkrdnd|jr|jdS) Nzif parent_template is None:r z.append(z .extend((zyield rr7z))rr)rvrrrrXr rMrGr\ Impossibler] Exceptionrr]rwrrZrr^r+r_r:r) r$r%r&rRrchildrMitemvalr,r,r- visit_OutputsV               zCodeGenerator.visit_OutputcCsF|j|j||j|j||jd|j|j||j|dS)Nz = )rrr+rr:r%r)r$r%r&r,r,r- visit_Assigns   zCodeGenerator.visit_AssigncCs|j|j}d|_|jj||j||j||j|j||j ||j |j ||j d|j dk r|j|j |n|j d|jd|j d|j||j|dS)NFz9 = (Markup if context.eval_ctx.autoescape else identity)(zconcat(r7)rrrvrurrrwrrrr+rr:rDrrr)r$r%r&r|r,r,r-visit_AssignBlocks         zCodeGenerator.visit_AssignBlockcCs|jdkr4|js|js|jr4|jr4|jd j|j|jj|j}|jdkr|jj |}|dk ov|dt kov|j | s|j d|jd|d|ddS|j |dS) Nr8r rrz(undefined(name=z) if z is missing else r7r) rryr{r|rrrBrurZ find_loadrrr:)r$r%r&rrr,r,r-r6s     zCodeGenerator.visit_NamecCsV|jj|j}|jd|d|j|jd|j|j|d|jddS)Nzif not isinstance(z , Namespace):zMraise TemplateRuntimeError("cannot assign attribute on non-namespace object")rr)rurrBrrrattr)r$r%r&rr,r,r- visit_NSRefOszCodeGenerator.visit_NSRefcCs8|j|j}t|tr&|jt|n|jt|dS)N)r[r)rGrXr:r[r)r$r%r&rdr,r,r- visit_Const]s  zCodeGenerator.visit_Constc CsJy|jt|j|jWn*tjk rD|jd|jdYnXdS)Nz6(Markup if context.eval_ctx.autoescape else identity)(r7)r:rr[r)r r`data)r$r%r&r,r,r-visit_TemplateDatads z CodeGenerator.visit_TemplateDatacCsZ|jdd}x0t|jD]"\}}|r0|jd|j||qW|j|dkrPdnddS)Nr5r z, rz,)r7r)r:rrbr+)r$r%r&rrcr,r,r- visit_Tuplels  zCodeGenerator.visit_TuplecCsJ|jdx0t|jD]"\}}|r,|jd|j||qW|jddS)Nrz, r)r:rrbr+)r$r%r&rrcr,r,r- visit_Listus   zCodeGenerator.visit_ListcCsd|jdxJt|jD]<\}}|r,|jd|j|j||jd|j|j|qW|jddS)Nrz, z: r)r:rrbr+rrM)r$r%r&rrcr,r,r- visit_Dict}s   zCodeGenerator.visit_Dict+-*/z//z**%andorznot cCsd|jjrd}n|jjrd}nd}|j|dx$|jD]}|j|||jdq8W|jddS)Nz8(markup_join if context.eval_ctx.volatile else str_join)Z markup_joinZstr_joinz((z, z)))r)r*rr:r r+)r$r%r&r+rr,r,r- visit_Concats  zCodeGenerator.visit_ConcatcCsB|jd|j|j|x|jD]}|j||q W|jddS)Nr5r7)r:r+rIops)r$r%r&r4r,r,r- visit_Compares   zCodeGenerator.visit_ComparecCs*|jdt|jd|j|j|dS)Nr6)r: operatorsr4r+rI)r$r%r&r,r,r- visit_OperandszCodeGenerator.visit_OperandcCsT|jjr|jd|jd|j|j||jd|jd|jjrP|jddS)Nz(await auto_await(zenvironment.getattr(z, r7z)))r8rr:r+r%rh)r$r%r&r,r,r- visit_Getattrs  zCodeGenerator.visit_GetattrcCst|jtjr@|j|j||jd|j|j||jdn^|jjrR|jd|jd|j|j||jd|j|j||jd|jjr|jddS)Nrrz(await auto_await(zenvironment.getitem(z, r7z))) rGrr Slicer+r%r:r8r)r$r%r&r,r,r- visit_Getitems      zCodeGenerator.visit_GetitemcCs`|jdk r|j|j||jd|jdk r:|j|j||jdk r\|jd|j|j|dS)Nr6)startr+r:stopr)r$r%r&r,r,r- visit_Slices     zCodeGenerator.visit_Slice)r%r& is_filterr!ccs|jjr|jd|r@|j|j|jd|jjj|j}n(|j|j|jd|jjj|j}|dkr|j r|rdnd}|jd|d|jd|j t j dt j d t jd ijt j |}|dk r|j|d dV|j|||jd |jjr |jd dS) Nzawait auto_await(r5rDr5zNo z named rrzcontext.eval_ctxr8z, r7)r8rr:rrBrUrr}rrrrrTrVr)r$r%r&rrZ type_namerWr,r,r-_filter_test_commons*       z!CodeGenerator._filter_test_commonc Cs|j||dx|jdk r*|j|j|nX|jjrP|jd|jd|jdn2|jjrn|jd|jdn|jd|jdWdQRXdS)NTz(Markup(concat(z.)) if context.eval_ctx.autoescape else concat(z))zMarkup(concat(zconcat(r7)rr%r+r)r*r:rwr)r$r%r&r,r,r-rs zCodeGenerator.visit_Filterc Cs,|j||d|j|j|WdQRXdS)NF)rr+r%)r$r%r&r,r,r-rszCodeGenerator.visit_Testcsljddfdd }jdjjjdjjjd|jddS)N)r!cs8jdk rjjdSjdjddS)Nz1cond_expr_undefined("the inline if-expression on z6 evaluated to false and no else section was defined."))Zexpr2r+r:rr,)r&r%r$r,r- write_expr2s  z1CodeGenerator.visit_CondExpr..write_expr2r5z if z else r7)rr:r+Zexpr1r5)r$r%r&rr,)r&r%r$r-visit_CondExprs   zCodeGenerator.visit_CondExpr)r%r&r@r!cCs|jjr|jd|jjr&|jdn |jd|j|j||rJddind}|jr\ddini}|jrnddini}|r|j|f|n|s|rt |f|}|j ||||jd|jjr|jddS)Nzawait auto_await(zenvironment.call(context, z context.call(rZ _loop_varsZ _block_varsr7) r8rr:r9r+r%r{r|rrar)r$r%r&r@rZ loop_kwargsZ block_kwargsr,r,r-rA0s"     zCodeGenerator.visit_CallcCs"|j|jd|j|j|dS)Nr)r:rr+rM)r$r%r&r,r,r- visit_KeywordGszCodeGenerator.visit_KeywordcCs&|jd|j|j||jddS)NzMarkup(r7)r:r+rI)r$r%r&r,r,r-visit_MarkSafeMs zCodeGenerator.visit_MarkSafecCs&|jd|j|j||jddS)Nz6(Markup if context.eval_ctx.autoescape else identity)(r7)r:r+rI)r$r%r&r,r,r-visit_MarkSafeIfAutoescapeRs z(CodeGenerator.visit_MarkSafeIfAutoescapecCs|jd|jdS)Nz environment.)r:rB)r$r%r&r,r,r-visit_EnvironmentAttributeYsz(CodeGenerator.visit_EnvironmentAttributecCs|jd|jd|jdS)Nzenvironment.extensions[z].)r: identifierrB)r$r%r&r,r,r-visit_ExtensionAttribute^sz&CodeGenerator.visit_ExtensionAttributecCs|j|j|jdS)N)r:rr)r$r%r&r,r,r-visit_ImportedNamecsz CodeGenerator.visit_ImportedNamecCs|j|jdS)N)r:rB)r$r%r&r,r,r-visit_InternalNamefsz CodeGenerator.visit_InternalNamecCs|jddS)Nr)r:)r$r%r&r,r,r-visit_ContextReferenceisz$CodeGenerator.visit_ContextReferencecCs|j|j|dS)N)r:r)r$r%r&r,r,r-visit_DerivedContextReferencensz+CodeGenerator.visit_DerivedContextReferencecCs|jd|dS)Ncontinue)r)r$r%r&r,r,r-visit_ContinuesszCodeGenerator.visit_ContinuecCs|jd|dS)Nbreak)r)r$r%r&r,r,r- visit_BreakvszCodeGenerator.visit_BreakcCs:|j}|jj||j||j|j||j|dS)N)rrurrrrr)r$r%r& scope_framer,r,r- visit_Scopeys   zCodeGenerator.visit_ScopecCs|j}|j|d|j||j|d|j|j||j||jdd}|jj||j ||j |j ||j ||j dS)Nz = z.vars = T)r)rrrr+rrrrurrrrrr)r$r%r&rrr,r,r-visit_OverlayScopes     z CodeGenerator.visit_OverlayScopec Csxxr|jD]h}|jd|jd|j|j|y|jj|j}Wntjk r^d|j_ YqXt |j|j|qWdS)Nzcontext.eval_ctx.z = T) optionsrrr+rMr[r)r r`r*setattr)r$r%r&keywordrdr,r,r-visit_EvalContextModifiers z'CodeGenerator.visit_EvalContextModifiercCsl|j}|jj}|j|d|j||x|jD]}|j||q6W|jj||jd|ddS)Nz = context.eval_ctx.save()zcontext.eval_ctx.revert(r7)rr)saverrrr+revert)r$r%r&Z old_ctx_nameZ saved_ctxrbr,r,r-visit_ScopedEvalContextModifiers    z-CodeGenerator.visit_ScopedEvalContextModifier)NFT)F)r )N)N)Nr)Nr)N)F)rr)N)F)rmrnror0rr[TextIOrVrlpropertyrFrWrrr#rwrrrr Noderrrrrr:rrrpZCallrrMappingr1rrrrrrrqrrr(rhrrrrrrrrrrrrrrrrrHr!rrrr&Includer,ZImportZ FromImportr-r/r1ZForr<ZIfr>r?rCZ FilterBlockrEZWithrJZExprStmtrKZ NamedTuplerO staticmethodrPrSrXrZr/r]r^r_ZOutputreZAssignrfZ AssignBlockrgrrZNSRefrir'rjr\rlrmr)rnDictror?Z visit_AddZ visit_SubZ visit_MulZ visit_DivZvisit_FloorDivZ visit_PowZ visit_ModZ visit_AndZvisit_OrrAZ visit_PosZ visit_NegZ visit_Notr3ZConcatrwZCompareryZOperandr{ZGetattrr|ZGetitemr~r}rrIteratorrrrZCondExprrrAKeywordrZMarkSaferZMarkSafeIfAutoescaperZEnvironmentAttributerZExtensionAttributerrrZ InternalNamerZContextReferencerZDerivedContextReferencerContinuerZBreakrZScoperZ OverlayScoperZEvalContextModifierrZScopedEvalContextModifierrr,r,r,r-r",s "A  ,4+Q   .u++4  2    0 O     '  )NFT)FrZtypingr0 contextlibr functoolsrior itertoolsrrrrZ markupsaferrrr exceptionsr Z idtrackingr r rrrrr(rutilsrrr=rZ TYPE_CHECKINGZtyping_extensionster8rZTypeVarrLr1rrzr3r[r>r?r@rArHrrrVrLrNrrSetrgrhr# RuntimeErrorrerrdrarr"r,r,r,r-sd                    " & S