lf dZddlmZddlmZddlmZddlmZ ddl m Z ddl m Z dd l mZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%dddddd d!d"d#Z&e'e(d$rd$Z)nd%Z)d&gZ* e+d'e*,d(n #e-$rYnwxYw e+d)d*Z.n #e-$rd+Z.YnwxYwd,Z/ d?d.Z0d/Z1d0Z2Gd1d2e3Z4Gd3d4e3Z5Gd5d6e6Z7Gd7d8e%Z8Gd9d:e%Z9Gd;de%Zz>=.new_funcCsm > 3%."9 3~++D%.AAH4zz(E222qtU--f---r)r7r9s` r8 optimizeconstr;Bs...... (A & &&r:Nct|tjstd|||||||}||||jSdS)z+Generate the python source for a node tree.z Can't compile non template nodesN) isinstancer Template TypeErrorcode_generator_classr1streamgetvalue)r3 environmentnamefilenamerA defer_initr- generators r8generaterHNs~ dEN + +<:;;;00T8VZIOOD ~((***~r:c||tus |turdSt|ttt t ttftzvrdSt|ttttfvr|D]}t|sdSdSt|tur;t!|D])\}}t|sdSt|sdS*dSdS)z)Does the node have a safe representation?NTF)NotImplementedEllipsistypeboolintfloatcomplexrr rtuplelistset frozenset has_safe_reprdictr )valueitemkeys r8rUrU\s }//5H3D3Dt E{{tS%*fE TTTt E{{udC333  D && uu t e  #E**  JC %% uu '' uu t 5r:ct|} |D]}||n#t$rYnwxYw|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. )UndeclaredNameVisitorr1 VisitorExit undeclared)r namesvisitorr3s r8find_undeclaredr`qsh$E**G   D MM$           s , 99ceZdZdZdS)MacroRefc>||_d|_d|_d|_dS)NF)r3accesses_calleraccesses_kwargsaccesses_varargsr2r3s r8__init__zMacroRef.__init__s' $$ %r:N)__name__ __module__ __qualname__rhr:r8rbrb~s#&&&&&r:rbc2eZdZdZddZdZd dZdZeZdS) Framez&Holds compile time information for us.Nc||_t|r|jpd||_d|_d|_|o|j|_d|_|r|jpd|_||_||j|_dSdS)NlevelF) r.rsymbolstoplevel rootlevelrequire_output_checkbufferblockparent)r2r.rxrqs r8rhzFrame.__init__s  v8&.@DNNN  %+$Jv/J!  , 4    -DKKK  r:ct|j}|j|j|j|_|S)z!Create a copy of the current one.)object__new__ __class____dict__updaterrcopyr2rvs r8rz Frame.copysG ^^DN + + 4=)))\&&((  r:Fcv|r#t|j|jjdzSt|j|S)zReturn an inner frame.r rp)rnr.rrrq)r2isolateds r8innerz Frame.inners<  Fdl.@1.DEEE ET]D)))r:c<|}d|_|S)aReturn 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. F)rrtrs r8softz Frame.softsYY[[  r:)NNF) rirjrk__doc__rhrrr__copy__rlr:r8rnrnsa00((((>****   HHHr:rnceZdZdZdS)r\z?Exception used by the `UndeclaredNameVisitor` to signal a stop.Nrirjrkrrlr:r8r\r\sIIIIr:r\c*eZdZdZdZdZdZdZdS)DependencyFinderVisitorz.A visitor that collects filter and test calls.cRt|_t|_dSr,)rSfilterstestsr2s r8rhz DependencyFinderVisitor.__init__suu UU r:cn|||j|jdSr,) generic_visitraddrDrgs r8 visit_Filterz$DependencyFinderVisitor.visit_Filters4 4    #####r:cn|||j|jdSr,)rrrrDrgs r8 visit_Testz"DependencyFinderVisitor.visit_Tests2 4    ty!!!!!r:cdS)zStop visiting at blocks.Nrlrgs r8 visit_Blockz#DependencyFinderVisitor.visit_Blockr:N)rirjrkrrhrrrrlr:r8rrsV88$$$"""'''''r:rc$eZdZdZdZdZdZdS)r[zA 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. cTt||_t|_dSr,)rSr^r])r2r^s r8rhzUndeclaredNameVisitor.__init__sZZ %%r:c|jdkrM|j|jvr?|j|j|j|jkrt dS|j|jdS)Nload)ctxrDr^r]rr\discardrgs r8 visit_Namez UndeclaredNameVisitor.visit_Namesv 8v  $)tz"9"9 O   * * *$*,,!mm#-, J  ty ) ) ) ) )r:cdS)zStop visiting a blocks.Nrlrgs r8rz!UndeclaredNameVisitor.visit_Blockrr:N)rirjrkrrhrrrlr:r8r[r[sK    ***&&&&&r:r[ceZdZdZdS) 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. Nrrlr:r8rrsr:rceZdZ dmdZdZdZdZdndZd Zdod Z dpd Z d Z dpdZ dZ dZdqdZdqdZdpdZdZdZdndZdZdZdZdZdZdZdZdZd Zd!Zd"Zd#Z d$Z!d%Z"d&Z#d'Z$d(Z%dpd)Z&d*Z'd+Z(d,Z)d-Z*d.Z+d/Z,d0Z-d1Z.d2Z/d3Z0d4Z1d5Z2e3d6d7Z4e5Z6dZ7d8Z8d9Z9d:Z:d;Z;d<ZZ>d?Z?d@Z@dAZAdBZBdCZCdDZDdEZEdFZFdrdGZGdrdHZHeGdIZIeGdJZJeGdKZKeGdLZLeGdMZMeGdNZNeGdOZOeGdPdQZPeGdRdQZQeHdIZReHdJZSeHdSdQZT[G[HeUdTZVeUdUZWdVZXeUdWZYeUdXZZdYZ[eUdZZ\eUd[Z]eUd\Z^eUdnd]Z_d^Z`d_Zad`ZbdaZcdbZddcZeddZfdeZgdfZhdgZidhZjdiZkdjZldkZmdlZndS)s CodeGeneratorNFTc|t}||_||_||_||_d|_||_||_|rt||_ i|_ i|_ d|_ d|_ d|_i|_i|_g|_d|_d|_d|_d|_d|_d|_g|_g|_dg|_dS)NFrr Tcontext)rrCrDrErAcreated_block_contextrFr-rr0import_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)r2rCrDrErArFr-s r8rhzCodeGenerator.__init__s >#%%F&    %*"$"  4&{33DN!   "'  !%!!" !#*3 %%%r:c:t|||j|j)z*Fail with a :exc:`TemplateAssertionError`.)rrDrE)r2msglinenos r8failzCodeGenerator.fail<s$S&$)T]KKKr:c6|xjdz c_d|jzS)zGet a new unique identifier.r zt_%d)rrs r8temporary_identifierz"CodeGenerator.temporary_identifier@s$ "---r:cr||_|d|jzdS)z7Enable buffering for the frame from that point onwards.z%s = []N)rrv writeliner2r4s r8rvzCodeGenerator.bufferEs40022  y5</00000r:c|s|jjr|d||d|jz||d||d|jz|dS|jjr|d|jzdS|d|jzdS)z(Return the buffer contents of the frame.zif context.eval_ctx.autoescape:zreturn Markup(concat(%s))else:zreturn concat(%s)N)r.r/rindentrvoutdent autoescape)r2r4force_unescapeds r8return_buffer_contentsz$CodeGenerator.return_buffer_contentsJs ~& @AAA :U\IJJJ w''' 2U\ABBB * :U\IJJJ *U\9:::::r:c&|xjdz c_dS)zIndent by one.r Nrrs r8rzCodeGenerator.indent\s Qr:r c&|xj|zc_dS)zOutdent by step.Nr)r2steps r8rzCodeGenerator.outdent`s T!r:c|j|d|dS|d|jz|dS)z%Yield or write into the frame buffer.Nyield %s.append()rvr)r2r4r3s r8 start_writezCodeGenerator.start_writedsE <  NN8T * * * * * NN<%,6 = = = = =r:cB|j|ddSdS)z1End the writing process started by `start_write`.N))rvwriters r8 end_writezCodeGenerator.end_writeks% < # JJsOOOOO $ #r:c|||||||dS)z4Simple shortcut for start_write + write + end_write.N)rrr)r2sr4r3s r8 simple_writezCodeGenerator.simple_writeps? %%% 1  ur:c |d|D]}|||dS#t$rYdSwxYw)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)rr1r)r2r r4r3s r8 blockvisitzCodeGenerator.blockvisitvsk  NN6 " " " ( ( 4'''' ( (    DD s04 AAc|jr|jsk|jd|jz|xj|jz c_|j-|j|j|jfd|_d|_|jd|jzd|_|j|dS)z&Write a string into the output stream. NFz r) rrrArrrrappendr)r2xs r8rzCodeGenerator.writes ? $ 2 !!$"8999  DO3  )5O**D,BDDT+UVVV-1D* %D  K  ft'88 9 9 9DO !r:rc\|||||dS)z!Combination of newline and write.N)newliner)r2rr3extras r8rzCodeGenerator.writelines) T5!!! 1 r:ct|jd|z|_|*|j|jkr|j|_|j|_dSdSdS)z/Add one or more newlines before the next write.r N)maxrrrr)r2r3rs r8rzCodeGenerator.newlinesRdoq5y99   t > >%)[D ""kDOOO   > >r:cd}td|jD|pdD]}t|rd}n|jD]-}|d|||.|sg|jD]-}|d|||.|0t |D] \}}|d|d|!|jr0|d||j||r |j|d n|d |jD]O}|d |j z||j ||dP|0t |D] \}}||d |d!|jG|d ||j||ddS|ddS|j2|d||j|dSdS)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. Fc3$K|] }|jV dSr,)rY.0rs r8 z*CodeGenerator.signature..s$77aAE777777r:rlT, N=z, *z , **dict({z, **{z%r: : z}, **r}z, **) rr5is_python_keywordargsrr1r dyn_args dyn_kwargsrYrW) r2r3r4 extra_kwargskwarg_workaroundkwargargrYrWs r8 signaturezCodeGenerator.signatures!774;7779KLL  E '' #'  9 # #C JJt    JJsE " " " " 9 ) ) 4    5%(((('"+L"9"999JCJJJCCC78888 = - JJu    JJt}e , , ,  /* <(((( 7### ! ! 6EI-... 5;... 4    '"+L"9"9::JCJJSSS%%%89999* 7### 4?E222 3 3 _ ( JJv    JJt . . . . .) (r:c $t}|D]}||dD]d}t||}t||D]A}||vr|||<|||d|d|dBedS)zPull all the dependencies.)rrz = environment.[]N)rr1getattrrr)r2r r_r3 dependencymappingrDs r8pull_dependencieszCodeGenerator.pull_dependenciess)++  D MM$    ,  JdJ//G44  w&&$($=$=$?$?GDM18 DDDQ   r:c g}t|jjD]\}\}}|tkr|tkr1||d|d|dP|tkr||d|v|tkr| |td|r-|dd |zdSdS)N = (rzunknown load instruction %s = missing) r rrloadsrrrget_resolve_funcrrrNotImplementedErrorjoin)r2r4undefstargetactionparams r8 enter_framezCodeGenerator.enter_frames'01D'E'E F F #FOVU++++++8M8M8O8O8O8OQVQVQVWXXXX>))FFFEE:;;;;--- f%%%%)*DEEE  @ NN>EJJv,>,>> ? ? ? ? ? @ @r:c|seg}t|jjD]\}}|||r/|dd|zdSdSdS)Nrr)r rrrrrr)r2r4with_python_scoperr_s r8 leave_framezCodeGenerator.leave_frames  DF&u}':;; & &  f%%%% D~ 60B0BBCCCCC  D D D Dr:c.|jjrd|zSd|zS)Nz async def %szdef %s)rCis_async)r2rDs r8funczCodeGenerator.funcs%   $ )!D( ($r:c T|}|j|t|}d}t }g}t |jD]g\}}|jdkr|}|jdvr||j| |j |jht|j d} d| vr|O |j |t|jz nX#t$r|d|jYn1wxYw| |jdd|_d| vr8d|vr4| |jdd|_d| vr8d|vr4| |jdd|_d |_|j|||d d d |d ||||||||t |jD]\}}|j |j} |d| z| |j |t|jz } |d| z|| |n;#t$r.|| dd|jzd|jdYnwxYw|| |  |!|"|j ||#|d|$|d| ||fS)z/Dump the function def of a macro or call block.Ncaller)r5varargs)rr5rzhWhen defining macros or call blocks the special "caller" argument must be omitted or be given a default.Tr5rFmacrorr):if %s is missing:%s = = undefined(zparameter %r was not providedz, name=r)rr )%rrr analyze_noderbrS enumeraterrDrrrefr`bodydefaultslen IndexErrorrrdeclare_parameterrdrerfrurrrrrvr push_parameter_definitionsr1mark_parameter_storedrpop_parameter_definitionsrrr ) r2r3r4 macro_refexplicit_callerskip_special_paramsridxrr]rdefaults r8 macro_bodyzCodeGenerator.macro_bodys7  ""4(((TNN !ee!$),, 5 5HCx8##"%x000#''111 KK ))#(33 4 4 4 4$TY0OPP z ! !*M/C NN"BCCC!II1  EM;;HEEFFF(,I % z ! !h6I&I&I KK 77AA B B B(,I %  " "y8K'K'K KK 77 BB C C C)-I &&+" ""4((( DIIg$6$6$6$6 $H$OOO  E  ''...!$),,  HC-##CH--C NN.4 5 5 5 KKMMM +-c$)nn(<=w}--- 7E****   ss;chFFFR   & &s + + + LLNNNN &&(((  5))) ##E4#@@@ $777 is$("D %D32D3>"M5NNc 0dd|jjD}t|jdd}t |jjdkr|dz }|d|d|d |jd|jd|jd dS) zK|]}t|jVdSr,)reprrDrs r8rz*CodeGenerator.macro_def..Ms*HHqd16llHHHHHHr:rDNr ,zMacro(environment, macro, z, (z), z, context.eval_ctx.autoescape)) rr3rrrrrerfrd)r2r%r4 arg_tuplerDs r8 macro_defzCodeGenerator.macro_defKsIIHHIN4GHHHHH y~vt44 y~" # #q ( (  I  )))***)))  r:c\d|jz}|j|dt|jzz }|S)z.Return a human readable position for the node.zline %dN in )rrDr-)r2r3rs r8positionzCodeGenerator.position]s2  $ 9 &4 ??* *B r:cdddt|jDzS)Nz{%s}rc3*K|]\}}|d|VdSrNrl)rrDrs r8rz3CodeGenerator.dump_local_context..esE" " fff %" " " " " " r:)rr rr dump_storesrs r8dump_local_contextz CodeGenerator.dump_local_contextdsQ " " )%-*C*C*E*E F F" " "     r:c|d|d|d|ddS)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 NoneNrrs r8 write_commonszCodeGenerator.write_commonsjsX =>>> :;;; 8999 )*****r:ch|j|jdS)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)rrrrdump_param_targetsrs r8r"z(CodeGenerator.push_parameter_definitionsvs/ $$U]%E%E%G%GHHHHHr:c8|jdS)z+Pops the current parameter definitions set.N)rpoprs r8r$z'CodeGenerator.pop_parameter_definitionss !!#####r:cX|jr"|jd|dSdS)zMarks a parameter in the current parameter definitions as stored. This will skip the enforced undefined checks. N)rrr2rs r8r#z#CodeGenerator.mark_parameter_storeds;   6  !" % - -f 5 5 5 5 5 6 6r:c:|j|dSr,)rrrBs r8push_context_referencez$CodeGenerator.push_context_references %,,V44444r:c8|jdSr,)rr?rs r8pop_context_referencez#CodeGenerator.pop_context_references %))+++++r:c|jdS)NrArrs r8get_context_refzCodeGenerator.get_context_refs,R00r:c6|jd}|dkrdSd|zS)NrArresolvez %s.resolverHrBs r8rzCodeGenerator.get_resolve_funcs*.r2 Y  9f$$r:c\|d||dS)Nz .derived(r)rIr8rs r8derive_contextzCodeGenerator.derive_contexts8  " " " "  # #E * * * *  r:c2|jsdS||jdvS)z4Checks if a given target is an undeclared parameter.FrA)rrBs r8parameter_is_undeclaredz%CodeGenerator.parameter_is_undeclareds%$ 5.r222r:cR|jtdS)z+Pushes a new layer for assignment tracking.N)rrrSrs r8push_assign_trackingz"CodeGenerator.push_assign_trackings# !!#%%(((((r:c .|j}|jr|sdSd|D}t|dkrRt t |}|j|}|d|d|n|dt|D]P\}}|r| d|j|}| |d|Q| d |rst|dkr |d |d zdS|d d tt|zdSdS) zoPops the topmost level for assignment tracking and updates the context variables if necessary. Nc.g|]}|dddk|S)Nr r rlrs r8 z5CodeGenerator.pop_assign_tracking..s%888a1RaR5C<<<<>T ##D-##D))C NNNdddCC@ A A A A NN2 3 3 3&t__ 3 3 T%JJt$$$m''-- tttSS12222 JJt     <  A%%>aPQQQQQ8iiT< 8 899:   r:c  | Jdt|j|j}ddlm}|ddtz|dd|z|jjr|d|j rdpd }| tj du}| tjD]B}|j|jvr#|d |jz|j||j|j<C| tjD]}|j|jvr||j} |x|j| <} d | vr8| d d\} } |d | d | d| q|d| d| |d|jz||dd|dd||t5|}dt7|jdvr2|jd} |d| z|j|dx|_ |_!|o|j" |_#|r|d|$||%|j|&|j||'|d|(|r|j"s)||d|tRr"|jjs|dnc|d|jjrdpd z||d|(|(d|j" ztU|jD]\}}||d |zd|d|d||t5|}t7|jd!}d|vr2|jd} |d| zd"|vr8|jd"} || d#|d$|d%|j|||_+|$||%|j|&|j||'|d|(|d&dd'|jDzd|d(d)d*|j,DzdS)+Nzno root frame allowedr )exportedzfrom __future__ import %srzfrom jinja2.runtime import zHfrom jinja2.asyncsupport import auto_await, auto_aiter, AsyncLoopContextz, environment=environmentzblock %r defined twice.zfrom z import z as zimport z name = %rrootz(context, missing=missingr)rr2rz%s = TemplateReference(context)Tzparent_template = Nonerif parent_template is not None:z4yield from parent_template.root_render_func(context)z9%sfor event in parent_template.root_render_func(context):zasync z yield eventblock_)r2superrdz = context.super(z, block_rz blocks = {%s}c3$K|] }|d|V dS)z: block_Nrlrs r8rz/CodeGenerator.visit_Template..;s-'U'UA!!!QQ(?'U'U'U'U'U'Ur:zdebug_info = %r&c3 K|] }d|zV dS)z%s=%sNrlrs r8rz/CodeGenerator.visit_Template..As&(N(N1(N(N(N(N(N(Nr:)-rrCrDruntimer^rr code_featuresrrFfindr Extendsfind_allBlockrrr ImportedName importnamerrrsplitrrr;rnr`rrrr!rrsrtrrur rrr rsupports_yield_fromr rwr)r2r3r4r.r^envenv have_extendsrwimport_impaliasmoduleobjrrD block_framer]s r8visit_TemplatezCodeGenerator.visit_Templates}}5}}}t/;;%%%%%% 2TYY}5M5MMNNN 4tyy7J7JJKKK   $  NN/   _$D)DJyy//t; ]]5;// , ,EzT[(( 2UZ?NNN&+DK # #}}U%788 E EG!)<<<(373L3L3N3NN#C(5#::"%**S!"4"4KFCNNNUU#STTTTNNNUU#CDDD {TY./// 1561B1B1B1BFFF KST      h _TY :: : :-11&99C NN % "Q&&<===   ; -))%00GG**,,G  $-  $ NNN:>)))WWWMt    #,<ED NN<@DD$)))WWWU    KKMMM   gu - - - LLNNN Ur:c|js|d|j|jdkrq|js)|d||ddz|jrt||d|| |j || d|j z|dtz||d ||jrd |_|xjd z c_d S) zCalls the extender.z,cannot use extend from a non top-level scoperrbraise TemplateRuntimeError(%r)zextended multiple timesz+parent_template = environment.get_template(, %r)z6for name, parent_block in parent_template.blocks.%s():z8context.blocks.setdefault(name, []).append(parent_block)Tr N)rsrrrrrrrrr1templaterrDdict_item_iterrtr2r3r4s r8 visit_ExtendszCodeGenerator.visit_Extendsjs_~ S IIDdk R R R   " " ) @AAA NN;>WW X X X% "nn$  DdKKK 4=%((( 7TY&'''  D~ U     QRRR  ? *%)D " q r:c\|jr)|d|d}t|jt jrKt|jjtrd}nVt|jjttfrd}n-t|jt j t j frd}|d|z|| |j||d|jz|jr||d||d||d |d }|jr?|jjrd pd }||d ||dnV|jjr|dn4t*r|dd}n|d|s>||d|||jr|dSdS)zHandles includes.ztry:get_or_select_template get_templateselect_templateztemplate = environment.%s(rzexcept TemplateNotFound:rrFr}r~zR 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_streamTz9for event in template._get_default_module()._body_stream:rN)ignore_missingrrr=rr ConstrWrrQrRTupleListr1rrDr with_contextrCrr8rqr)r2r3r4 func_nameskip_event_yieldrs r8 visit_IncludezCodeGenerator.visit_Includes    NN6 " " " KKMMM, dmU[ 1 1 *$--|<< .* DM/%?? .-   UZ'@ A A *)I 3i?FFF 4=%((( 7TY&'''    LLNNN NN5 6 6 6 KKMMM NN6 " " " LLNNN NN7 # # # KKMMM    #,<ED NN 44!8!8!?!?!?!?A       &  NN!     # WXXX#'  O   KKMMM   gu - - - LLNNN    LLNNNNN  r:c|d|j|jz||jr|d|jz|jjr|d|d||j ||d|j z|j r>|d|jjrdpdd | |d n7|jjr|d n|d |jr9|j d s!|d|jzdSdSdS)zVisit regular imports.rcontext.vars[%r] = await zenvironment.get_template(, %r). make_module_asyncr_(context.get_all(), True, r_get_default_module_async()_get_default_module()r !context.exported_vars.discard(%r)N)rrrrrrsrrCrr1rrDrr8 startswithrs r8 visit_ImportzCodeGenerator.visit_Imports w!2!24;!?!??FFF > < JJ,t{: ; ; ;   $ ! JJx  ./// 4=%((( 8di'(((   0 JJJ$-:(@b@@++E2222      & 0 JJ4 5 5 5 5 JJ. / / / > N$+"8"8"="= N NN>L M M M M M N N N Nr:c |||d|jjrdpdz||j|d|jz|jr>|d|jjrdpdd|dn7|jjr|d n|d g}g}|j D]M}t|tr|\}}n|}| j |d |d | d j |z|| j |dd||dt#|d|d|jr?|||ds||O|rt-|dkr<|d}| d|dj |n7| ddfd|Dz|rst-|dkr | d|dzdS| ddt1t"|zdSdS)zVisit named imports.z/included_template = %senvironment.get_template(rr_rrrrrrrz = getattr(included_template, z , missing)rrzthe template %r (imported on z%) does not export the requested name z$ % included_template.__name__, name=r r rrUrVzcontext.vars.update({%s})rc3VK|]#}|dj|V$dSr6)rrr)rrDr4s r8rz1CodeGenerator.visit_FromImport..(sP  GKDDD%-*;*;D*A*A*AB      r:rz-context.exported_vars.difference_update((%s))N)rrrCrr1rrDrr8r^r=rQrrrrrr3r-rrsrrrrr )r2r3r4 var_namesdiscarded_namesrDrvs ` r8visit_FromImportzCodeGenerator.visit_FromImports T =(5X; =    4=%((( 8di'(((   0 JJJ$-:(@b@@++E2222      & 0 JJ4 5 5 5 5 JJ. / / / J 2 2D$&& " ee NN"'-"3"3E":":":":DDDB    NN.1B1B51I1II J J J KKMMM NN M%%e,,,,,}}T****DJJJ888DD     LLNNN~ 2  ''''',,2#**5111  9~~"" |/3ttU]5F5Ft5L5L5LM/ii    OX     ?##q((B_UVEWWXXXXX#%)YYtD//J/J%K%KL   r:c|}|}|}|jp%dt|ddv}d}|r|jd}|j|d|jr|j|d|jr| }|j|d| d | |z|j| | || |jjrd pd ||j||d ||jjrd pd|d| | d|j||j||d| | d||j||d||d|jra| d| dz|| |||j|_|r| d|z|t.jD]3} | jdkr&| jdkr|d| j4|jr,| } | d| z| |jjrd pd |||j||r>|jjr|d|zn.|d|zn|d |jr|d|z|jr|dna|jjr|s|d||j||jjr|s|d|jr|d|jr|d n||rd!pd| | |||j||jr| d"| z||||jo|j |jr| d#| z| | |||j|||||jr| |||!|||jjr|d$|d%|jjr|d||j||jjr|d|d&|"|dSdS)'Nr)r)only)rr) for_branchelsetestz %s(fiter):z async for zfor r2zauto_aiter(fiter)fiter:if rTrz'%s(reciter, loop_render_func, depth=0):rstorez8Can't assign to special loop variable in for-loop targetz%s = 1z, %s in AsyncLoopContext(z, %s in LoopContext(z%s(reciterz auto_aiter(rz&, undefined, loop_render_func, depth):z , undefined):z%s = 0zif %s:rzloop(z, loop))#r recursiver`iter_child_nodesrrr!relse_rrrrrr rCrr1rrrr rvrlr NamerrDrrrYrrrrr) r2r3r4 loop_frame test_frame else_frame extended_looploop_refloop_filter_funcrDiteration_indicators r8 visit_ForzCodeGenerator.visit_For5s[[]] [[]] [[]]  &O  ! !y ! 1 195 5 +   D!);;FCCH'''@@@ : E   + +DV + D D D 9 A#88::    + +DV + D D D NN<$))4D*E*EEty Q Q Q KKMMM   Z ( ( ( NN4+4EO P P P JJt{J / / / JJv    JJt'0H5HSG T T T JJsOOO KKMMM NN5$) , , , JJty* - - - JJsOOO KKMMM NN8 $ $ $ JJt{J / / / LLOOO   Z4  @ @ @ > 2 NN9DIIfH4 5 5 5MM%*--  Dx7""tyF':': NK : ;"&";";"="=  NN8&99 : : : t'0A\KVTRRR 4; +++  ( > 6ABBBB 1H<==== JJv    9 1 JJu// 0 0 0 > JJy ! ! ! !( * * =))) JJty% ( ( ((   3 9  JJsOOO > A JJ? @ @ @ @ JJ}8?C @ @ @  $$$  :... : ; NN8&99 : : :   $.*K^     :  NN8&99 : : : KKMMM   Z ( ( ( OODJ 3 3 3   Z ( ( ( LLNNN > "  ' ' 3 3 3 LLNNN   UD ) ) )( % 8$$$ JJw   ( * =))) JJty% ( ( ((  3 JJy ! ! ! NN5 ! ! ! ! ! " "r:c(|}|d|||j||d|||j|||j D]}|d|||j||d|||j|||j rZ|d|||j ||dSdS)Nrrzelif r) rrr1rrrrrrelif_r)r2r3r4if_framers r8visit_IfzCodeGenerator.visit_IfsN::<< ud### 49h''' 3   8,,, Z  E NN7E * * * JJuz8 , , , JJsOOO KKMMM OOEJ 1 1 1 LLNNNN :  NN7 # # # KKMMM OODJ 1 1 1 LLNNNNN   r:c|||\}}||jrT|jds|d|jz|d|jz|d|j|jz| ||dS)Nr rWrr) r*rrsrDrrrrrrr0)r2r3r4 macro_framer%s r8 visit_MacrozCodeGenerator.visit_Macros!%u!=!= Y  > >9'',, H :TYFGGG NN049< = = = 7U]..ty999::: y+.....r:c|||\}}|d||||||||j|d||dS)Nz caller = T)forward_caller)r*rr0r visit_Callcallr)r2r3r4 call_framer%s r8visit_CallBlockzCodeGenerator.visit_CallBlocks $e < < I {### y*--- %%%  5>>> ur:c|}|j|||||||j||||||j || || |dSr,) rrrrr rvrrrrfilterrr )r2r3r4 filter_frames r8visit_FilterBlockzCodeGenerator.visit_FilterBlocks{{}} ))$/// &&& L!!!  <000 %%% $+|444 u &&&&&r:c|}|j|||t |j|jD]Z\}}||||| d|||[| |j || |dSNr) rrrrr rtargetsvaluesrr1rrrr )r2r3r4 with_framerexprs r8 visit_WithzCodeGenerator.visit_Withs[[]] ''--- $$$ t{;; $ $LFD LLNNN JJvz * * * JJu    JJtU # # # #  :... $$$$$r:cf||||j|dSr,)rr1r3rs r8visit_ExprStmtzCodeGenerator.visit_ExprStmts0 T 49e$$$$$r: _FinalizeInfo)constsrcchjjSjx}d}jjrid}jjfd}t dddur|dz }d}n:t dddur|d z }d}nt d ddur |d z }fd }||_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(c,|Sr,rl)rWr) env_finalizes r8finalizez.CodeGenerator._make_finalize..finalizesw||E22333r:contextfunctionFT context, evalcontextfunctioncontext.eval_ctx, environmentfunction environment, c8j|Sr,)rC)rWr)rr2s r8rz.CodeGenerator._make_finalize..finalize's""7<<0@%#H#HIIIr:) _finalize_default_finalizerCrrr)r2rrr)rs` @@r8_make_finalizezCodeGenerator._make_finalizes( > %> !!337   $ J)C+4L 4 4 4 4 4 4|%6>>$FF{"' $ "5MME dE. / / $U## #~~e$$$r:c|jjr|dn7|jjr|dn|d|j||jdSdS)zXOutput extra source code before visiting a child of an ``Output`` node. z7(escape if context.eval_ctx.autoescape else to_string)(zescape(z to_string(N)r.r/rrrr2r3r4rs r8_output_child_prezCodeGenerator._output_child_preGs > " % JJP Q Q Q Q ^ & % JJy ! ! ! ! JJ| $ $ $ < # JJx| $ $ $ $ $ $ #r:cl|d|j|ddSdS)zWOutput extra source code after visiting a child of an ``Output`` node. rN)rrrs r8_output_child_postz CodeGenerator._output_child_postUs6 3 < # JJsOOOOO $ #r:c|jr2|jrdS|d||}g}|jD]} |js-t|t jst j | |||}n1#t j tf$r| |Y|wxYw|r7t|dtr|d || |g|jbt|dkr|d|jzn|d|jz||D]}t|trN||}|j|d|zL||dze|j|d|n||||||||||||||j|d|j>||t|dkrdnd |jr|dSdS) Nr|rAr rz %s.extend((rr.r)))rurrrrr rr=r Impossibler ExceptionrrRrvrrrrr1rrr) r2r3r4rrchildrrXvals r8 visit_OutputzCodeGenerator.visit_Output^s  % %  NN8 9 9 9 KKMMM&&(( Z % %E N- "%);<< - *,,,33E5(KK$i0    E"""   % 48T22 %R&&&& UG$$$$ < #4yyA~~|el:;;;;}u|;<<< KKMMM $ $D$%% $--d33<'NN8c>2222NN39----<'NN8T2222LL&&&&&tUH=== 4'''''eX>>><+JJsOOO < # LLNNN NN#d))q..33d ; ; ;  %  LLNNNNN  sA B&&+CCc|||||j||d||j|||dSr)rQrr1rrr3r\rs r8 visit_AssignzCodeGenerator.visit_Assigns~ !!### T 4;&&& 5 49e$$$   '''''r:c||}d|_|j|||||||j|| || |j || d|j ||j |n| d|jz| d||||dS)NFz9 = (Markup if context.eval_ctx.autoescape else identity)( concat(%s)r)rQrrurrrr rvrrrr1rrrrr\r )r2r3r4rys r8visit_AssignBlockzCodeGenerator.visit_AssignBlocks3 !!###kkmm ,1 (((... %%% K     ;/// T 4;&&& NOOO ; "   dk; 7 7 7 7 JJ|k&88 9 9 9 3   ''' %%%%%r:c |jdkr3|jr,|jr%|jd|j|j|j}|jdkrh|j|}|&|dtkr| |r&| d|jd|d|ddS| |dS) NrrArrz(undefined(name=z) if z is missing else r) rrsrrrDrrr find_loadrrOr)r2r3r4rrs r8rzCodeGenerator.visit_Names 8w  5> ! 6"2&**49555m ** 8v  =**3//D G11144S992 yyy###sss, 3r:c4|j|j}|d|z||ddz|||d|jddS)Nz!if not isinstance(%s, Namespace):rz/cannot assign attribute on non-namespace objectrr)rrrrDrrrattr)r2r3r4rs r8 visit_NSRefzCodeGenerator.visit_NSRefsm ** :S@AAA   ,? @     333 233333r:c||j}t|tr$|t |dS|t |dSr,)rr.r=rOrstrr-)r2r3r4rs r8 visit_ConstzCodeGenerator.visit_ConstscmmEN++ c5 ! ! " JJs3xx JJtCyy ! ! ! ! !r:c |t||jdS#tj$r!|d|jzYdSwxYw)Nz9(Markup if context.eval_ctx.autoescape else identity)(%r))rr-rr.r rdatars r8visit_TemplateDataz CodeGenerator.visit_TemplateDatas  JJtDMM%.99:: ; ; ; ; ;    JJKdiW       s:>,A.-A.c|dd}t|jD]2\}}|r|d|||3||dkrdpddS)NrrArrz,)rrrr'r1r2r3r4r(rXs r8 visit_TuplezCodeGenerator.visit_Tuples 3"4:.. $ $IC ! 4   JJtU # # # # 3!8$+,,,,,r:c|dt|jD]2\}}|r|d|||3|ddS)Nrrrr r s r8 visit_ListzCodeGenerator.visit_List sr 3"4:.. $ $IC ! 4   JJtU # # # # 3r:cR|dt|jD]g\}}|r|d||j||d||j|h|ddS)N{rrr)rrr'r1rYrWr s r8 visit_DictzCodeGenerator.visit_Dicts 3"4:.. * *IC ! 4   JJtx ' ' ' JJt    JJtz5 ) ) ) ) 3r:c,tfd}|S)Nc|jjrr|jjvrd|dz||j||d||j|nc|d||j||dz||j||ddS)Nz$environment.call_binop(context, %r, rr %s r)rC sandboxedintercepted_binopsrr1leftrightr2r3r4operators r8r_z$CodeGenerator.binop..visitors * . 0 CCC AHLMMM 49e,,, 4    4:u---- 3 49e,,, 6H,--- 4:u--- JJsOOOOOr:r;r interceptabler_s` r8binopzCodeGenerator.binops-        r:c,tfd}|S)Nc4|jjrB|jjvr4|dz||j|n3|dz||j||ddS)Nz#environment.call_unop(context, %r, rr)rCrintercepted_unopsrr1r3rs r8r_z#CodeGenerator.uaop..visitor2s * - 0 BBB @8KLLL 49e,,,, 3>*** 49e,,, JJsOOOOOr:rrs` r8uaopzCodeGenerator.uaop1s-       r:+-*/z//z**%and)rorznot c |jjrd}n|jjrd}nd}|d|z|jD]-}||||d.|ddS)Nz;(context.eval_ctx.volatile and markup_join or unicode_join) markup_join unicode_joinz%s((rr)r.r/rrr r1)r2r3r4rrs r8 visit_ConcatzCodeGenerator.visit_ConcatOs > " 'UII ^ & '%II&I 6I%&&&:  C JJsE " " " JJt     4r:c|d||j||jD]}||||ddS)Nrr)rr1rops)r2r3r4ops r8 visit_ComparezCodeGenerator.visit_Compare]sb 3 49e$$$( " "B JJr5 ! ! ! ! 3r:c|dt|jz||j|dS)Nr)r operatorsr2r1rrs r8 visit_OperandzCodeGenerator.visit_Operandes< 6Idg../// 49e$$$$$r:c(|jjr|d|d||j||d|jz|jjr|ddSdS)N(await auto_await(zenvironment.getattr(rr)rCrrr1r3rrs r8 visit_GetattrzCodeGenerator.visit_Getattris   $ - JJ+ , , , )*** 49e$$$ 7TY&'''   $  JJt       r:czt|jtjrb||j||d||j||ddS|jjr|d|d||j||d||j||d|jjr|ddSdS)Nrrr8zenvironment.getitem(rrr) r=rr Slicer1r3rrCrrs r8 visit_GetitemzCodeGenerator.visit_Getitemus dh , , ! JJty% ( ( ( JJsOOO JJtx ' ' ' JJsOOOOO( 1 /000 JJ- . . . JJty% ( ( ( JJt    JJtx ' ' ' JJsOOO( ! 4      ! !r:c*|j||j||d|j||j||j2|d||j|dSdS)Nr)startr1rstoprrs r8 visit_SlicezCodeGenerator.visit_Slices : ! JJtz5 ) ) ) 3 9 JJty% ( ( ( 9 JJsOOO JJty% ( ( ( ( ( ! r:c|jjr|d||j|jdz|jj|j}|#|d|jz|jt|dddur|dnQt|dddur|d n(t|d ddur|d |j | |j |nz|j j r'|d |j d |j dnG|j jr|d|j zn|d|j z||||d|jjr|ddSdS)Nawait auto_await(rzno filter named %r contextfilterFTrevalcontextfilterrenvironmentfilterrz/(context.eval_ctx.autoescape and Markup(concat(z )) or concat(rzMarkup(concat(%s))rr)rCrrrrDgetrrrr3r1r.r/rvrr)r2r3r4rs r8rzCodeGenerator.visit_Filters   $ , JJ* + + + 4< *S0111'++DI66 < II*TY6 D D D 4% 0 0D 8 8 JJ{ # # # # T. 6 6$ > > JJ+ , , , , T. 6 6$ > > JJ ' ' ' 9 JJty% ( ( ( ( ^ $ 4 JJJ8= elllT    ^ & 4 JJ+el: ; ; ; ; JJ|el2 3 3 3 tU### 3   $  JJsOOOOO  r:cN||j|jdz|j|jjvr#|d|jz|j||j|||||ddS)Nrzno test named %rr) rrrDrCrrr1r3rrs r8rzCodeGenerator.visit_Tests 4:di(3./// 9D,2 2 2 II(494dk B B B 49e$$$ tU### 3r:cBfd}djdjd|ddS)NcjjSddzzdS)Nzcond_expr_undefined(%r)zRthe inline if-expression on %s evaluated to false and no else section was defined.)expr2r1rr3)r4r3r2sr8 write_expr2z1CodeGenerator.visit_CondExpr..write_expr2scz%zz$*e444 JJ)359]]45H5HI     r:rz if z else r)rr1expr1r)r2r3r4rKs``` r8visit_CondExprzCodeGenerator.visit_CondExprs        3 4:u%%% 6 49e$$$ 8  3r:c|jjr|d|jjr|dn|d||j||rddipd}|||||d|jjr|ddSdS)NrBzenvironment.call(context, z context.call(rr)rCrrrr1r3r)r2r3r4rrs r8rzCodeGenerator.visit_Calls   $ , JJ* + + +   % ( JJ3 4 4 4 4 JJ ' ' ' 49e$$$%>8X*>F$  tUL111 3   $  JJsOOOOO  r:cv||jdz||j|dS)Nr)rrYr1rWrs r8 visit_KeywordzCodeGenerator.visit_Keywords6 48c>""" 4:u%%%%%r:c|d||j||ddS)NzMarkup(rrr1rrs r8visit_MarkSafezCodeGenerator.visit_MarkSafes= 9 49e$$$ 3r:c|d||j||ddS)Nz5(context.eval_ctx.autoescape and Markup or identity)(rrRrs r8visit_MarkSafeIfAutoescapez(CodeGenerator.visit_MarkSafeIfAutoescapes> JKKK 49e$$$ 3r:c@|d|jzdS)Nz environment.rrDrs r8visit_EnvironmentAttributez(CodeGenerator.visit_EnvironmentAttributes! >DI-.....r:cP|d|jd|jdS)Nzenvironment.extensions[z].)r identifierrDrs r8visit_ExtensionAttributez&CodeGenerator.visit_ExtensionAttributes+ doootyyQRRRRRr:cP||j|jdSr,)rrrors r8visit_ImportedNamez CodeGenerator.visit_ImportedNames$ 4&t788888r:c:||jdSr,rWrs r8visit_InternalNamez CodeGenerator.visit_InternalNames 49r:c0|ddS)Nr)rrs r8visit_ContextReferencez$CodeGenerator.visit_ContextReferences 9r:cV|||dSr,)rrMrs r8visit_DerivedContextReferencez+CodeGenerator.visit_DerivedContextReferences( 4&&u--.....r:c2|d|dS)Ncontinuer:rs r8visit_ContinuezCodeGenerator.visit_Continues z4(((((r:c2|d|dS)Nbreakr:rs r8 visit_BreakzCodeGenerator.visit_Breaks w%%%%%r:c|}|j|||||j|||dSr,)rrrrr rrr )r2r3r4 scope_frames r8 visit_ScopezCodeGenerator.visit_Scope sjkkmm ((... %%%  ;/// %%%%%r:c*|}||d|||d|z||j||||d}|j|| || |j || || dS)Nrz %s.vars = T)r)rrrMr1rrDrrrrr rrr rF)r2r3r4rrks r8visit_OverlayScopez CodeGenerator.visit_OverlayScopes'')) CCC)<)>BBc`|}|j}|d|z||||jD]}||||j||d|zdS)Nz%s = context.eval_ctx.save()zcontext.eval_ctx.revert(%s))rr.saverrsrr1revert)r2r3r4 old_ctx_name saved_ctxrs r8visit_ScopedEvalContextModifierz-CodeGenerator.visit_ScopedEvalContextModifier+s0022 N''))  5 DEEE &&tU333Y % %E JJue $ $ $ $ i((( 4|CDDDDDr:NFTr)r r,)Nr)T)orirjrkrhrrrvrrrrrrrrrrrrr r rr*r0r3r8r;r"r$r#rDrFrIrrMrOrQr\rzrrrrrrrrrrrrrrrrrrrrrrrrrrrrr rrrr r$ visit_Add visit_Sub visit_Mul visit_Divvisit_FloorDiv visit_Pow visit_Mod visit_Andvisit_Or visit_Pos visit_Neg visit_Notr;r/r3r6r9r<r@rrrMrrPrSrUrXr[r]r_rarcrfrirlrnrsryrlr:r8rrs TX@4@4@4@4HLLL... 111 ;;;;$"""">>>>        ****3/3/3/3/j   @@@ DDDD N N N `   $   + + +III$$$666555,,,111%%%    333 )))>z z z z x$$$L+!+!+!Z888tNNN2IIIVD"D"D"L*/// ' ' ' % % %%%%J0@AAM"I'''R###%%%& % % %MMM^(((&&&00 4 4 4"""---( c Ic Ic Ic IU4[[Nd Ic Ie5111IuT///HS IS IV5111I t  ] ]%%%  ] !!]!()))]@]]*   ] &&&   ///SSS999///)))&&&&&& % % % : : :EEEEEr:rrz)=r collectionsr functoolsr itertoolsrrrrr markupsaferr r_r _compatr r rrrrr exceptionsr idtrackingrrrrrrr0rutilsrr_rr5hasattrrVrriexecr SyntaxErrorrqr;rHrUr`rzrbrn RuntimeErrorr\rr[rrrrlr:r8rs766""""""$$$$$$222222######!!!!!!......&&&&&&******((((((******            74 NNN  D 0111)****   D D "###    ' ' 'QU + + + +*   &&&&&v&&&:::::F:::zJJJJJ,JJJ'''''k'''&&&&&&K&&&,9|E|E|E|E|EK|E|E|E|E|Es$3 CCC C..C87C8