1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
3

U'ícã
@srdZddlZddlmZddlmZddlmZddl	m
Z
ddlmZ
ddlmZdd	lmZd
dlmZd
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*fdZ+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.d1œd2d3„Z7ej*e6d4œd5d6„Z8ej9ej:ej9e.ej;e.d7œd8d9„Z<Gd:d;„d;ƒZ=Gd<d(„d(ƒZ>Gd=d>„d>e?ƒZ@Gd?d@„d@e"ƒZAGdAdB„dBe"ƒZBGdCdD„dDeCƒZDGdEd'„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)ÚEnvironmentÚF.)Zboundz==z!=ú>z>=ú<z<=Úinznot in)ÚeqÚneÚgtZgteqÚltZlteqrÚnotin)ÚfÚreturncs2dtjdtjtjdœ‡fdd„}ttjt|ƒˆƒS)NÚ
CodeGeneratorÚFrame)ÚselfÚnodeÚframeÚkwargsr!csH|jdk	r8|jjr8|jj||jƒ}||kr8|j||ƒSˆ|||f|ŽS)N)Ú	optimizerÚeval_ctxÚvolatileÚvisit)r$r%r&r'Únew_node)r ©ú1/tmp/pip-build-gk9425m9/Jinja2/jinja2/compiler.pyÚnew_func,s
zoptimizeconst.<locals>.new_func)r
ÚExprÚtÚAnyrÚcastr)r r/r-)r r.Ú
optimizeconst+s
r4r"r#)Úopr!cs"tdtjtddœ‡fdd„ƒ}|S)Nr")r$r%r&r!cs”|jjrNˆ|jjkrN|jdˆ›dƒ|j|j|ƒ|jdƒ|j|j|ƒn8|jdƒ|j|j|ƒ|jdˆ›dƒ|j|j|ƒ|jdƒdS)Nz environment.call_binop(context, z, ú(ú ú))ÚenvironmentÚ	sandboxedZintercepted_binopsÚwriter+ÚleftÚright)r$r%r&)r5r-r.Úvisitor<s

z_make_binop.<locals>.visitor)r4r
ÚBinExprr#)r5r>r-)r5r.Ú_make_binop;sr@cs"tdtjtddœ‡fdd„ƒ}|S)Nr")r$r%r&r!cs`|jjr6ˆ|jjkr6|jdˆ›dƒ|j|j|ƒn|jdˆƒ|j|j|ƒ|jdƒdS)Nzenvironment.call_unop(context, z, r6r8)r9r:Zintercepted_unopsr;r+r%)r$r%r&)r5r-r.r>Tsz_make_unop.<locals>.visitor)r4r
Ú	UnaryExprr#)r5r>r-)r5r.Ú
_make_unopQs
rBFTr)r%r9ÚnameÚfilenameÚstreamÚ
defer_initÚ	optimizedr!cCsHt|tjƒstdƒ‚|j||||||ƒ}|j|ƒ|dkrD|jjƒSdS)z+Generate the python source for a node tree.z Can't compile non template nodesN)Ú
isinstancer
ÚTemplateÚ	TypeErrorZcode_generator_classr+rEÚgetvalue)r%r9rCrDrErFrGÚ	generatorr-r-r.Úgeneratees


rM)Úvaluer!cCs†|dks|tks|tkrdSt|ƒttttttt	hkr:dSt|ƒt
ttt
hkr`tdd„|DƒƒSt|ƒtkr‚tdd„|jƒDƒƒSdS)z)Does the node have a safe representation?NTcss|]}t|ƒVqdS)N)Ú
has_safe_repr)Ú.0Úvr-r-r.ú	<genexpr>†sz has_safe_repr.<locals>.<genexpr>css"|]\}}t|ƒot|ƒVqdS)N)rO)rPÚkrQr-r-r.rR‰sF)ÚNotImplementedÚEllipsisÚtypeÚboolÚintÚfloatÚcomplexÚrangeÚstrrÚtupleÚlistÚsetÚ	frozensetÚallÚdictÚitems)rNr-r-r.rO}srO)r
Únamesr!cCs@t|ƒ}yx|D]}|j|ƒqWWntk
r8YnX|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
rdr>r%r-r-r.Úfind_undeclaredŽs
rhc@s*eZdZejejejfddœdd„ZdS)ÚMacroRefN)r%r!cCs||_d|_d|_d|_dS)NF)r%Úaccesses_callerÚaccesses_kwargsÚaccesses_varargs)r$r%r-r-r.Ú__init__žszMacroRef.__init__)	Ú__name__Ú
__module__Ú__qualname__r1ÚUnionr
ÚMacroÚ	CallBlockrmr-r-r-r.risric@sdeZdZdZdeejdejeddœdd„Zddœdd„Z	de
dd
œdd„Zddœd
d„Ze	Z
dS)r#z&Holds compile time information for us.N)r)ÚparentÚlevelr!cCs~||_||_|dkr4t|d|_d|_d|_d|_n(t|j|d|_|j|_|j|_|j|_d|_d|_d|_	d|_
d|_dS)N)ruF)r)rtrÚsymbolsÚrequire_output_checkÚbufferÚblockÚtoplevelÚ	rootlevelÚ
loop_frameÚblock_frameÚ
soft_frame)r$r)rtrur-r-r.rm¨s zFrame.__init__)r!cCs2tjttj|jƒƒ}|jj|jƒ|jj	ƒ|_|S)z!Create a copy of the current one.)
r1r3r#ÚobjectÚ__new__Ú	__class__Ú__dict__ÚupdatervÚcopy)r$Úrvr-r-r.r„Ûsz
Frame.copyF)Úisolatedr!cCs&|rt|j|jjddSt|j|ƒS)zReturn an inner frame.r	)ru)r#r)rvru)r$r†r-r-r.ÚinnerâszFrame.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)r„r{r~)r$r…r-r-r.Úsoftèsz
Frame.soft)NN)F)rnrorpÚ__doc__rr1ÚOptionalrXrmr„rWr‡rˆÚ__copy__r-r-r-r.r#¥s.
c@seZdZdZdS)rfz?Exception used by the `UndeclaredNameVisitor` to signal a stop.N)rnrorpr‰r-r-r-r.rføsrfc@sTeZdZdZddœdd„Zejddœdd„Zejddœd	d
„Z	ej
ddœdd„ZdS)
ÚDependencyFinderVisitorz.A visitor that collects filter and test calls.N)r!cCstƒ|_tƒ|_dS)N)r_ÚfiltersÚtests)r$r-r-r.rmÿsz DependencyFinderVisitor.__init__)r%r!cCs|j|ƒ|jj|jƒdS)N)Ú
generic_visitrÚaddrC)r$r%r-r-r.Úvisit_Filters
z$DependencyFinderVisitor.visit_FiltercCs|j|ƒ|jj|jƒdS)N)rrŽrrC)r$r%r-r-r.Ú
visit_Tests
z"DependencyFinderVisitor.visit_TestcCsdS)zStop visiting at blocks.Nr-)r$r%r-r-r.Úvisit_Blocksz#DependencyFinderVisitor.visit_Block)rnrorpr‰rmr
ÚFilterr‘ÚTestr’ÚBlockr“r-r-r-r.rŒüs
rŒc@sJeZdZdZejeddœdd„Zej	ddœdd„Z
ejddœd	d
„ZdS)rez¡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.
    N)rdr!cCst|ƒ|_tƒ|_dS)N)r_rdrg)r$rdr-r-r.rms
zUndeclaredNameVisitor.__init__)r%r!cCsJ|jdkr8|j|jkr8|jj|jƒ|j|jkrFtƒ‚n|jj|jƒdS)NÚload)ÚctxrCrdrgrrfÚdiscard)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)
rnrorpr‰r1ÚIterabler\rmr
ÚNameršr–r“r-r-r-r.resrec@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)rnrorpr‰r-r-r-r.r%src	@sFeZdZUdêdejeejeejejeeddœdd„Ze	edœd	d
„ƒZ
eeddœd
d„Zedœdd„Z
eddœdd„Zdëeeddœdd„Zddœdd„Zdìeddœdd„Zdíeejejddœdd„Zeddœd d!„Zdîeeejejdd"œd#d$„Zejejedd%œd&d'„Zedd(œd)d*„Zdïeejejedd,œd-d.„Zdðejejedd/œd0d1„Zdñejejejej feejej!eej"fdd2œd3d4„Z#ejejdd5œd6d7„Z$eddœd8d9„Z%dòeedd:œd;d<„Z&dóeeed?œd@dA„Z'eedBœdCdD„Z(ejej)ej*feej+ee,fdEœdFdG„Z-e,eddHœdIdJ„Z.ejedKœdLdM„Z/eedœdNdO„Z0ddœdPdQ„Z1eddœdRdS„Z2ddœdTdU„Z3eddVœdWdX„Z4eddVœdYdZ„Z5ddœd[d\„Z6edœd]d^„Z7edœd_d`„Z8eedœdadb„Z9eedVœdcdd„Z:ddœdedf„Z;eddœdgdh„Z<dôej=ejeddEœdidj„Z>ej?eddEœdkdl„Z@ejAeddEœdmdn„ZBejCeddEœdodp„ZDejejEejFfeddEœdqdr„ZGejEeddEœdsdt„ZHejFeddEœdudv„ZIejJeddEœdwdx„ZKejLeddEœdydz„ZMej)eddEœd{d|„ZNej*eddEœd}d~„ZOejPeddEœdd€„ZQejReddEœdd‚„ZSejTeddEœdƒd„„ZUGd…d†„d†ejVƒZWeXej"ej"d‡œdˆd‰„ƒZYdZZejeWZeWdœdŠd‹„Z[ejej"edŒœddŽ„Z\ej]eeWedœdd‘„Z^ej]eeWddœd’d“„Z_ej]eeWddœd”d•„Z`ejaeddEœd–d—„ZbejceddEœd˜d™„ZdejeeddEœdšd›„ZfejgeddEœdœd„ZhejieddEœdždŸ„ZjejkeddEœd d¡„ZlejmeddEœd¢d£„Znej+eddEœd¤d¥„ZoejpeddEœd¦d§„ZqejreddEœd¨d©„ZsetdªƒZuetd«ƒZvetd¬ƒZwetd­ƒZxetd®ƒZyetd¯ƒZzetd°ƒZ{etd±ƒZ|etd²ƒZ}e~dªƒZe~d«ƒZ€e~d³ƒZe‚ejƒeddEœd´dµ„ƒZ„e‚ej…eddEœd¶d·„ƒZ†ej‡eddEœd¸d¹„Zˆe‚ej‰eddEœdºd»„ƒZŠe‚ej‹eddEœd¼d½„ƒZŒejeddEœd¾d¿„ZŽeejejej feeejddÀœdÁd„ƒZ‘e‚ejeddEœdÃdĄƒZ’e‚ej eddEœdÅdƄƒZ“e‚ej”eddEœdÇdȄƒZ•e‚dõejeeddɜdÊd˄ƒZ–ej—eddEœdÌd̈́Z˜ej™eddEœdÎdτZšej›eddEœdÐdфZœejeddEœdÒdӄZžejŸeddEœdÔdՄZ ej¡eddEœdÖdׄZ¢ej£eddEœdØdلZ¤ej¥eddEœdÚdۄZ¦ej§eddEœdÜd݄Z¨ej©eddEœdÞd߄Zªej«eddEœdàdá„Z¬ej­eddEœdâdã„Z®ej¯eddEœdädå„Z°ej±eddEœdædç„Z²ej³eddEœdèdé„Z´dS)ör"NFTr)r9rCrDrErFrGr!cCs²|dkrtƒ}||_||_||_||_d|_||_d|_|rFt|ƒ|_i|_	i|_
d|_d|_d|_
i|_i|_g|_d|_d|_d|_d|_d|_d|_g|_g|_dg|_dS)NFrr	TÚcontext)rr9rCrDrEZcreated_block_contextrFr(rÚimport_aliasesÚblocksÚextends_so_farÚhas_known_extendsÚcode_linenorŽrÚ
debug_infoÚ_write_debug_infoÚ
_new_linesÚ
_last_lineÚ_first_writeÚ_last_identifierÚ_indentationÚ
_assign_stackÚ_param_def_blockÚ_context_reference_stack)r$r9rCrDrErFrGr-r-r.rm-s8	
zCodeGenerator.__init__)r!cCs
|jdk	S)N)r()r$r-r-r.rGvszCodeGenerator.optimizedzte.NoReturn)ÚmsgÚlinenor!cCst|||j|jƒ‚dS)z*Fail with a :exc:`TemplateAssertionError`.N)rrCrD)r$r®r¯r-r-r.Úfail|szCodeGenerator.failcCs|jd7_d|j›S)zGet a new unique identifier.r	Zt_)r©)r$r-r-r.Útemporary_identifier€sz"CodeGenerator.temporary_identifier)r&r!cCs |jƒ|_|j|j›dƒdS)z7Enable buffering for the frame from that point onwards.z = []N)r±rxÚ	writeline)r$r&r-r-r.rx…s
zCodeGenerator.buffer)r&Úforce_unescapedr!cCs¤|sŒ|jjrl|jdƒ|jƒ|jd|j›dƒ|jƒ|jdƒ|jƒ|jd|j›dƒ|jƒdS|jjrŒ|jd|j›dƒdS|jd|j›dƒdS)z(Return the buffer contents of the frame.zif context.eval_ctx.autoescape:zreturn Markup(concat(z))zelse:zreturn concat(r8N)r)r*r²ÚindentrxÚoutdentÚ
autoescape)r$r&r³r-r-r.Úreturn_buffer_contentsŠs

z$CodeGenerator.return_buffer_contentscCs|jd7_dS)zIndent by one.r	N)rª)r$r-r-r.r´žszCodeGenerator.indentr	)Ústepr!cCs|j|8_dS)zOutdent by step.N)rª)r$r¸r-r-r.rµ¢szCodeGenerator.outdent)r&r%r!cCs0|jdkr|jd|ƒn|j|j›d|ƒdS)z%Yield or write into the frame buffer.Nzyield z.append()rxr²)r$r&r%r-r-r.Ústart_write¦s
zCodeGenerator.start_writecCs|jdk	r|jdƒdS)z1End the writing process started by `start_write`.Nr8)rxr;)r$r&r-r-r.Ú	end_write­s
zCodeGenerator.end_write)Úsr&r%r!cCs$|j||ƒ|j|ƒ|j|ƒdS)z4Simple shortcut for start_write + write + end_write.N)r¹r;rº)r$r»r&r%r-r-r.Úsimple_write²s
zCodeGenerator.simple_write)r
r&r!cCsBy(|jdƒx|D]}|j||ƒqWWntk
r<YnXdS)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.
        ÚpassN)r²r+r)r$r
r&r%r-r-r.Ú
blockvisitºs

zCodeGenerator.blockvisit)Úxr!cCs€|jrp|jsR|jjd|jƒ|j|j7_|jdk	rR|jj|j|jfƒd|_d|_|jjd|jƒd|_|jj|ƒdS)z&Write a string into the output stream.Ú
NFz    r)	r¦r¨rEr;r£r¥r¤Úappendrª)r$r¿r-r-r.r;Ås
zCodeGenerator.writer)r¿r%Úextrar!cCs|j||ƒ|j|ƒdS)z!Combination of newline and write.N)Únewliner;)r$r¿r%rÂr-r-r.r²ÓszCodeGenerator.writeline)r%rÂr!cCs:t|jd|ƒ|_|dk	r6|j|jkr6|j|_|j|_dS)z/Add one or more newlines before the next write.r	N)Úmaxr¦r¯r§r¥)r$r%rÂr-r-r.rÃÚszCodeGenerator.newline)r%r&Úextra_kwargsr!c	CsÆtdd„tdd„|jDƒ|pfƒDƒƒ}x$|jD]}|jdƒ|j||ƒq0W|s¬x$|jD]}|jdƒ|j||ƒqZW|dk	r¬x*|jƒD]\}}|jd|›d|›ƒqŠW|jrÊ|jdƒ|j|j|ƒ|rž|jdk	ræ|jdƒn
|jd	ƒx8|jD].}|j|j	›d
ƒ|j|j
|ƒ|jdƒqøW|dk	rbx,|jƒD] \}}|j|›d
|›dƒq>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_keywordr1r3r\)rPrSr-r-r.rRðsz*CodeGenerator.signature.<locals>.<genexpr>css|]}|jVqdS)N)Úkey)rPr¿r-r-r.rRñsz, Nú=z, *z
, **dict({z, **{z: z}, **r8Ú}z, **)Úanyrr'Úargsr;r+rcZdyn_argsZ
dyn_kwargsrÇrN)	r$r%r&rÅZkwarg_workaroundÚargÚkwargrÇrNr-r-r.Ú	signatureásF 







zCodeGenerator.signature)r
r!c	Cstƒ}x|D]}|j|ƒqWxô|j|jdf|j|jdffD]Ô\}}}xÈt|ƒD]¼}||krh|jƒ||<|jdƒ|jƒ|j||›d|›d|›dƒ|jƒ|jdƒ|jƒ|jdƒ|jd	||›d
ƒ|jƒ|jd|dd…›d|›dƒ|jƒ|jƒqPWq<WdS)aæFind all filter and test names used in the template and
        assign them to variables in the compiled namespace. Checking
        that the names are registered with the environment is done when
        compiling the Filter and Test nodes. If the node is in an If or
        CondExpr node, the check is done at runtime instead.

        .. versionchanged:: 3.0
            Filters and tests in If and CondExpr nodes are checked at
            runtime instead of compile time.
        rrŽztry:z = environment.ú[ú]zexcept KeyError:z
@internalcodezdef z
(*unused):zraise TemplateRuntimeError("No Nr	z named z	 found.")éÿÿÿÿ)	rŒr+rrŽÚsortedr±r²r´rµ)r$r
r>r%Zid_maprdÚ
dependencyrCr-r-r.Úpull_dependenciess.

 

zCodeGenerator.pull_dependenciescCs®g}xŠ|jjjƒD]z\}\}}|tkr(q|tkrR|j|›d|jƒ›d|›dƒq|tkrp|j|›d|›ƒq|tkr„|j	|ƒqt
dƒ‚qW|rª|jdj|ƒ›dƒdS)Nz = r6r8zunknown load instructionz
 = missing)rvÚloadsrcrrr²Úget_resolve_funcr
rrÁÚNotImplementedErrorÚjoin)r$r&ÚundefsÚtargetÚactionÚparamr-r-r.Úenter_frameEs"zCodeGenerator.enter_frame)r&Úwith_python_scoper!cCsB|s>g}x|jjD]}|j|ƒqW|r>|jdj|ƒ›dƒdS)Nz = z
 = missing)rvrÕrÁr²rØ)r$r&rÞrÙrÚr-r-r.Úleave_frameUszCodeGenerator.leave_frameúasync Ú)Úasync_valueÚ
sync_valuer!cCs|jjr|S|S)N)r9Úis_async)r$rârãr-r-r.Úchoose_async]szCodeGenerator.choose_async)rCr!cCs|jƒ›d|›S)Nzdef )rå)r$rCr-r-r.Úfunc`szCodeGenerator.func)r%r&r!cCs¢|jƒ}|jj|ƒt|ƒ}d}tƒ}g}xNt|jƒD]@\}}|jdkrL|}|jdkrb|j|jƒ|j	|jj
|jƒƒq6Wt|jdƒ}	d|	krì|dk	rÔy|j
|t|jƒWqætk
rÐ|jd|jƒYqæXn|j	|jjdƒƒd|_d|	krd|kr|j	|jjdƒƒd|_d|	krDd|krD|j	|jjdƒƒd|_d|_|jj|ƒ|j|jdƒ›d	d
j|ƒ›d|ƒ|jƒ|j|ƒ|j|ƒ|j|ƒx¾t|jƒD]°\}}|jj
|jƒ}
|jd|
›d
ƒ|jƒy|j
|t|jƒ}Wn6tk
r*|j|
›d|j›d|j›dƒYnX|j|
›dƒ|j||ƒ|j|
ƒ|j ƒq¬W|j!ƒ|j"|j|ƒ|j#|dd|j$|dd|j ƒ||fS)z/Dump the function def of a macro or call block.NÚcallerr'ÚvarargszhWhen defining macros or call blocks the special "caller" argument must be omitted or be given a default.TFÚmacror6z, z):zif z is missing:z = undefined("parameter z was not provided", name=r8z = )r³)rÞ)r'rè)rçr'rè)%r‡rvÚanalyze_noderir_Ú	enumeraterËrCrrÁÚrefrhÚbodyÚdefaultsÚlenÚ
IndexErrorr°r¯Údeclare_parameterrjrkrlrwr²rærØr´rxrÝÚpush_parameter_definitionsr+Úmark_parameter_storedrµÚpop_parameter_definitionsr¾r·rß)r$r%r&Ú	macro_refZexplicit_callerZskip_special_paramsrËÚidxrÌrgrìÚdefaultr-r-r.Ú
macro_bodycsn

$


"
zCodeGenerator.macro_body)rõr&r!cCsrdjdd„|jjDƒƒ}t|jddƒ}t|jjƒdkr>|d7}|jd|›d	|›d
|j›d|j›d|j›dƒdS)z<Dump the macro definition for the def created by macro_body.z, css|]}t|jƒVqdS)N)ÚreprrC)rPr¿r-r-r.rR¸sz*CodeGenerator.macro_def.<locals>.<genexpr>rCNr	ú,zMacro(environment, macro, z, (z), z, context.eval_ctx.autoescape))	rØr%rËÚgetattrrïr;rkrlrj)r$rõr&Z	arg_tuplerCr-r-r.Ú	macro_def¶s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 )r¯rC)r$r%r…r-r-r.ÚpositionÂs
zCodeGenerator.positioncCs*djdd„|jjƒjƒDƒƒ}d|›dS)Nz, css |]\}}|›d|›VqdS)z: Nr-)rPrCrÚr-r-r.rRËsz3CodeGenerator.dump_local_context.<locals>.<genexpr>Ú{rÉ)rØrvZdump_storesrc)r$r&Zitems_kvr-r-r.Údump_local_contextÉsz CodeGenerator.dump_local_contextcCs,|jdƒ|jdƒ|jdƒ|jdƒdS)z·Writes 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_commonsÐs


zCodeGenerator.write_commonscCs|jj|jjƒƒdS)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)r¬rÁrvZdump_param_targets)r$r&r-r-r.ròÜsz(CodeGenerator.push_parameter_definitionscCs|jjƒdS)z+Pops the current parameter definitions set.N)r¬Úpop)r$r-r-r.rôåsz'CodeGenerator.pop_parameter_definitions)rÚr!cCs|jr|jdj|ƒdS)z€Marks a parameter in the current parameter definitions as stored.
        This will skip the enforced undefined checks.
        r	NrÑ)r¬r™)r$rÚr-r-r.róész#CodeGenerator.mark_parameter_storedcCs|jj|ƒdS)N)r­rÁ)r$rÚr-r-r.Úpush_context_referenceðsz$CodeGenerator.push_context_referencecCs|jjƒdS)N)r­r)r$r-r-r.Úpop_context_referenceósz#CodeGenerator.pop_context_referencecCs
|jdS)Nr	rÑ)r­)r$r-r-r.Úget_context_reföszCodeGenerator.get_context_refcCs |jd}|dkrdS|›dS)Nr	ržÚresolvez.resolverÑ)r­)r$rÚr-r-r.rÖùs
zCodeGenerator.get_resolve_funccCs|jƒ›d|j|ƒ›dS)Nz	.derived(r8)rrÿ)r$r&r-r-r.Úderive_contextÿszCodeGenerator.derive_contextcCs|js
dS||jdkS)z4Checks if a given target is an undeclared parameter.Fr	rÑ)r¬)r$rÚr-r-r.Úparameter_is_undeclaredsz%CodeGenerator.parameter_is_undeclaredcCs|jjtƒƒdS)z+Pushes a new layer for assignment tracking.N)r«rÁr_)r$r-r-r.Úpush_assign_trackingsz"CodeGenerator.push_assign_trackingcCsš|jjƒ}|jr"|jr"|js(|r,dSdd„|Dƒ}t|ƒdkr¶tt|ƒƒ}|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
|›ƒqîW|jdƒ|jr–|jr–|r–t|ƒdkrt|j
d|d›dƒn"dj
tt|ƒƒ}|j
d|›dƒdS)zoPops the topmost level for assignment tracking and updates the
        context variables if necessary.
        NcSs g|]}|dd…dkr|‘qS)Nr	Ú_r-)rPr¿r-r-r.ú
<listcomp>sz5CodeGenerator.pop_assign_tracking.<locals>.<listcomp>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(rr8zcontext.exported_vars.update((z)))r«rr}r|rzrïÚnextÚiterrvrìr²rër;rØÚmaprù)r$r&ÚvarsZpublic_namesrCrìröÚ	names_strr-r-r.Úpop_assign_trackingsB



z!CodeGenerator.pop_assign_trackingcCs$|dkstdƒ‚t|j|jƒ}ddlm}m}|jjrDt||ƒ}nt|ƒ}|j	dƒ|j	ddj
|ƒƒ|jrtdnd}|jt
jƒdk	}xD|jt
jƒD]4}	|	j|jkr¾|jd	|	j›d
|	jƒ|	|j|	j<q–Wx†|jt
jƒD]v}
|
j|jkrÜ|
j}|jƒ|j|<}d|kr<|jddƒ\}
}|j	d|
›d
|›d|›ƒqÜ|j	d|›d|›ƒqÜW|j	d|j›ƒ|j	|jdƒ›d|›ddd|jƒ|jƒt|ƒ}dt|jd+ƒkrÎ|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ƒ|jjs~|j	dƒn$|j	dƒ|jƒ|j	dƒ|j*ƒ|j*d|j$ƒx|jj+ƒD]\}}	|j	|jd|ƒ›d|›d|	dƒ|jƒ|jƒt|ƒ}d|_,t|	jd,ƒ}d|kr@|jj dƒ}|j	|›dƒd|krr|jj dƒ}|j	|›d |›d!|›d"ƒ|jj!|	ƒ||_-|j	d#ƒ|j&|ƒ|j'|	jƒ|j(|	j|ƒ|j)|dd|j*ƒqÂWdj
d$d%„|jDƒƒ}|j	d&|›d'ddd(j
d)d%„|j.Dƒƒ}|j	d*|›ƒdS)-Nzno root frame allowedr	)ÚexportedÚasync_exportedz%from __future__ import generator_stopzfrom jinja2.runtime import z, ráz, environment=environmentzblock z defined twiceÚ.zfrom z import z as zimport zname = Úrootz(context, missing=missingz):)rÂr$z = TemplateReference(context)Tzparent_template = None)rÞzif parent_template is not None:z4yield from parent_template.root_render_func(context)z=async for event in parent_template.root_render_func(context):zyield eventZblock_Úsuperz = context.super(z, block_r8z_block_vars = {}css|]}|›d|›VqdS)z: block_Nr-)rPr¿r-r-r.rR«sz/CodeGenerator.visit_Template.<locals>.<genexpr>z
blocks = {rÉú&css |]\}}|›d|›VqdS)rÈNr-)rPrSrQr-r-r.rR­sz
debug_info = )r$)r$r)/ÚAssertionErrorrr9rCZruntimerrrärÒr²rØrFÚfindr
ÚExtendsÚfind_allr–r r°r¯ÚImportedNameÚ
importnamerŸr±Úrsplitrær´rr#rhrírvrñrêrzr{r¢rwrÝrÔr¾rßrµrcr}ryr¤)r$r%r&r)rrZexported_namesZenvenvZhave_extendsryÚimport_ÚimpÚaliasÚmoduleÚobjrìrCr}rgZ
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
ƒ|jjrÆ|j
dkrÆ|jd	|j	›d
|›d|ƒn@|j|jƒ›d|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](r8zfor event in context.blocks[z):Úevent)rzr¢r¡r²r´ÚscopedrrÚrequiredrCrµr9rärxrår¼)r$r%r&ruržr-r-r.r“°s8

zCodeGenerator.visit_BlockcCsÆ|js|jd|jƒ|jdkrV|js6|jdƒ|jƒ|jdƒ|jrNtƒ‚n|jƒ|jd|ƒ|j	|j
|ƒ|jd|j›dƒ|jdƒ|jƒ|jd	ƒ|jƒ|j
r´d
|_|jd7_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, r8z9for name, parent_block in parent_template.blocks.items():z8context.blocks.setdefault(name, []).append(parent_block)Tr	N)rzr°r¯r¡r¢r²r´rrµr+Útemplater;rCr{)r$r%r&r-r-r.Ú
visit_ExtendsÛs(




zCodeGenerator.visit_ExtendscCsp|jr|jdƒ|jƒd}t|jtjƒrVt|jjtƒr>d}qnt|jjt	t
fƒrnd}nt|jtjtjfƒrnd}|jd|›d|ƒ|j
|j|ƒ|jd|j›dƒ|jrè|jƒ|jd	ƒ|jƒ|jd
ƒ|jƒ|jdƒ|jƒd}|jr|j|jƒ›d
|j|ƒ›dƒn$|jjr,|jdƒn|jdƒd}|s\|jƒ|jd|ƒ|jƒ|jrl|jƒdS)zHandles includes.ztry:Zget_or_select_templateZget_templateZselect_templateztemplate = environment.r6z, r8zexcept TemplateNotFound:r½zelse: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_missingr²r´rHr'r
ÚConstrNr\r]r^ÚTupleÚListr+r;rCrµÚwith_contextrårÿr9rär¼)r$r%r&Ú	func_nameZskip_event_yieldr-r-r.Ú
visit_IncludesJ





zCodeGenerator.visit_IncludecCsˆ|j|jdƒ›dƒ|j|j|ƒ|jd|j›dƒ|jrld|jdƒ›}|j|›d|j|ƒ›dƒn|jd	|jdƒ›d
ƒdS)Nzawait zenvironment.get_template(z, z).Zmake_moduleZ_asyncz(context.get_all(), True, r8Z_get_default_modulez	(context))r;rår+r'rCr,rÿ)r$r%r&Úf_namer-r-r.Ú_import_common9szCodeGenerator._import_commoncCsn|j|jj|jƒ›d|ƒ|jr6|jd|j›dƒ|j||ƒ|jrj|jjdƒrj|jd|j›dƒdS)zVisit regular imports.z = z
context.vars[z] = r	zcontext.exported_vars.discard(r8N)r²rvrìrÚrzr;r0Ú
startswith)r$r%r&r-r-r.Úvisit_ImportHszCodeGenerator.visit_Importc
s®|j|ƒ|jdƒ|j|ˆƒg}g}xÌ|jD]Â}t|tƒrH|\}}n|}|jˆjj|ƒ›d|›dƒ|jdˆjj|ƒ›dƒ|j	ƒd|j
|ƒ›d|›}|jˆjj|ƒ›d|›d	|›d
ƒ|jƒˆjr0|j
|ƒ|jdƒs0|j
|ƒq0W|r\t|ƒdkr2|d
}|jd|›dˆjj|ƒ›ƒn*dj‡fdd„|Dƒƒ}|jd|›dƒ|rªt|ƒdkrˆ|jd|d
›d
ƒn"djtt|ƒƒ}	|jd|	›dƒdS)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=r8r	r	rz
context.vars[z] = z, c3s$|]}|›dˆjj|ƒ›VqdS)z: N)rvrì)rPrC)r&r-r.rRysz1CodeGenerator.visit_FromImport.<locals>.<genexpr>zcontext.vars.update({z})zcontext.exported_vars.discard(z)context.exported_vars.difference_update((z))N)rÃr;r0rdrHr]r²rvrìr´rýrµrzrÁr1rïrØr
rù)
r$r%r&Z	var_namesZdiscarded_namesrCr ÚmessageZnames_kvrr-)r&r.Úvisit_FromImportSsD



 

 zCodeGenerator.visit_FromImportcCsˆ|jƒ}d|_|jƒ}|jƒ}|jpRdt|jd)dd*ƒkpRtdd„|jtjƒDƒƒ}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|jddƒƒ|j|j|ƒ|jd
ƒ|j|jddƒƒ|jdƒ|jƒ|jd|j
ƒ|j|j
|ƒ|jdƒ|jƒ|jdƒ|j|j|ƒ|jdƒ|j|dd|jrÀ|j|jdƒ›d|ƒ|jƒ|j|ƒ|j|_|rÖ|j|›dƒx<|jtjƒD],}	|	jdkrä|	jdkrä|jd|	jƒqäW|jr4|jƒ}
|j|
›dƒ|j|jddƒ|ƒ|j|j|ƒ|r||jd|›d
|jdƒ›dƒn
|jd
ƒ|j
rž|j|›dƒ|jr²|jdƒnF|jj rÎ|rÎ|jdƒ|j|j!|ƒ|jj rø|rø|jd ƒ|j
r
|jd ƒ|jr|jd!ƒn|j|r,d"ndƒ|jƒ|j|ƒ|jd#ƒ|j"|j#|ƒ|jrt|j|
›d$ƒ|jƒ|j||jo|jd|jrâ|jd|
›dƒ|jƒ|j|ƒ|j"|j|ƒ|j|ƒ|jƒ|jrh|j$|ƒ|jƒ|j%||ƒ|j|jd%ƒ›d&ƒ|jj r2|jdƒ|j|j!|ƒ|jj rT|jd ƒ|jd'ƒ|j&|ƒ|j'r„|j'd+j(|j	j)ƒdS),NTÚlooprí)Úonlycss|]}|jVqdS)N)r%)rPryr-r-r.rR’sz*CodeGenerator.visit_For.<locals>.<genexpr>)Z
for_branchÚelseÚtestz(fiter):z
async for zfor z in zauto_aiter(fiter)Zfiterú:zif zyield é)rÞz%(reciter, loop_render_func, depth=0):z
 = missingÚstorez8Can't assign to special loop variable in for-loop targetz = 1z, ZAsynczLoopContext(r6Zreciterzauto_aiter(r8z&, undefined, loop_render_func, depth):z
, undefined):z_loop_vars = {}z = 0zawait zloop(z, loop)r	)rí)r5rÑ)*r‡r|Ú	recursiverhÚiter_child_nodesrÊrr
r–rvrñrêÚelse_r8r±r²rær´rÝrår+rÚr;rµrßrxrœr˜rCr°r¯r9rärr¾rír·r¹rºr«Údifference_updateZstores)r$r%r&r|Z
test_frameZ
else_frameZ
extended_loopZloop_refZloop_filter_funcrCZiteration_indicatorr-r-r.Ú	visit_For…sÆ






 














zCodeGenerator.visit_ForcCsÎ|jƒ}|jd|ƒ|j|j|ƒ|jdƒ|jƒ|j|j|ƒ|jƒxP|j	D]F}|jd|ƒ|j|j|ƒ|jdƒ|jƒ|j|j|ƒ|jƒqRW|j
rÊ|jdƒ|jƒ|j|j
|ƒ|jƒdS)Nzif r9zelif zelse:)rˆr²r+r8r;r´r¾rírµÚelif_r>)r$r%r&Zif_framerAr-r-r.Úvisit_Ifs&


zCodeGenerator.visit_IfcCs||j||ƒ\}}|jƒ|jrR|jjdƒs>|jd|j›dƒ|jd|j›dƒ|j|jj|jƒ›dƒ|j	||ƒdS)Nr	zcontext.exported_vars.add(r8z
context.vars[z] = z = )
rørÃrzrCr1r;r²rvrìrü)r$r%r&Zmacro_framerõr-r-r.Úvisit_Macro%szCodeGenerator.visit_MacrocCsR|j||ƒ\}}|jdƒ|j||ƒ|j||ƒ|j|j|dd|j|ƒdS)Nz	caller = T)Úforward_caller)rør²rür¹Ú
visit_CallÚcallrº)r$r%r&Z
call_framerõr-r-r.Úvisit_CallBlock/s
zCodeGenerator.visit_CallBlockcCsh|jƒ}|jj|ƒ|j|ƒ|j|ƒ|j|j|ƒ|j||ƒ|j|j	|ƒ|j
|ƒ|j|ƒdS)N)r‡rvrêrÝrxr¾rír¹r‘Úfilterrºrß)r$r%r&Zfilter_framer-r-r.Úvisit_FilterBlock7s


zCodeGenerator.visit_FilterBlockcCs€|jƒ}|jj|ƒ|j|ƒxDt|j|jƒD]2\}}|jƒ|j||ƒ|j	dƒ|j||ƒq.W|j
|j|ƒ|j|ƒdS)Nz = )
r‡rvrêrÝÚzipÚtargetsÚvaluesrÃr+r;r¾rírß)r$r%r&Z
with_framerÚÚexprr-r-r.Ú
visit_WithBs

zCodeGenerator.visit_WithcCs|j|ƒ|j|j|ƒdS)N)rÃr+r%)r$r%r&r-r-r.Úvisit_ExprStmtNs
zCodeGenerator.visit_ExprStmtc@s,eZdZUejejdefejedS)zCodeGenerator._FinalizeInfo.N)	rnrorpr1rŠÚCallabler\ÚconstÚsrcr-r-r-r.Ú
_FinalizeInfoRs
rS)rNr!cCst|ƒS)z¼The 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\)rNr-r-r.Ú_default_finalizeVszCodeGenerator._default_finalizecsˆjdk	rˆjSˆj}‰d}ˆjjr®d}ˆjj‰tjdtjdtjdijtjˆƒƒ}d}|dkr|t	j
t	j
dœ‡‡fdd„}n2|›|›d	}|dkr®t	j
t	j
dœ‡‡‡fd
d„}ˆj||ƒˆ_ˆjS)a‰Build 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(ržzcontext.eval_ctxr9)rNr!csˆˆ|ƒƒS)Nr-)rN)r÷Úenv_finalizer-r.Úfinalize‚sz.CodeGenerator._make_finalize.<locals>.finalizez, csˆˆˆj|ƒƒS)N)r9)rN)r÷rUr$r-r.rVŠs)Ú	_finalizerTr9rVrržÚeval_contextÚgetÚfrom_objr1r2rS)r$rVrRÚpass_argr-)r÷rUr$r.Ú_make_finalize`s&


zCodeGenerator._make_finalize)Úgroupr!cCstt|ƒƒS)z™Given a group of constant values converted from ``Output``
        child nodes, produce a string to write to the template module
        source.
        )rùr)r$r]r-r-r.Ú_output_const_reprsz CodeGenerator._output_const_repr)r%r&rVr!cCs:|j|jƒ}|jjrt|ƒ}t|tjƒr0t|ƒ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)r¶rrHr
ÚTemplateDatar\rQ)r$r%r&rVrQr-r-r.Ú_output_child_to_const—s
z$CodeGenerator._output_child_to_constcCsL|jjr|jdƒn|jjr(|jdƒn
|jdƒ|jdk	rH|j|jƒdS)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;r¶rR)r$r%r&rVr-r-r.Ú_output_child_pre¬s

zCodeGenerator._output_child_precCs"|jdƒ|jdk	r|jdƒdS)zWOutput extra source code after visiting a child of an
        ``Output`` node.
        r8N)r;rR)r$r%r&rVr-r-r.Ú_output_child_post¼s

z CodeGenerator._output_child_postc	
Csþ|jr"|jrdS|jdƒ|jƒ|jƒ}g}x|jD]†}y,|jpLt|tjƒsVtj	ƒ‚|j
|||ƒ}Wn&tj	tfk
rŒ|j|ƒw6YnX|r°t|d	t
ƒr°|d
j|ƒq6|j|gƒq6W|jdk	rt|ƒdkrì|j|j›dƒn|j|j›dƒ|jƒx²|D]ª}t|t
ƒrR|j|ƒ}|jdkrB|jd|ƒn|j|dƒnb|jdkrl|jd|ƒn
|j|ƒ|j|||ƒ|j||ƒ|j|||ƒ|jdk	r|jdƒqW|jdk	rê|jƒ|jt|ƒdkrädndƒ|jrú|jƒdS)Nzif parent_template is None:r	z.append(z	.extend((zyield rúr8z))rÑrÑ)rwr¢r²r´r\r
rQrHr`Ú
ImpossibleraÚ	ExceptionrÁr^rxrïr^rÃrbr+rcr;rµ)	r$r%r&rVríÚchildrQÚitemÚvalr-r-r.Úvisit_OutputÇsV




zCodeGenerator.visit_OutputcCsF|jƒ|j|ƒ|j|j|ƒ|jdƒ|j|j|ƒ|j|ƒdS)Nz = )rrÃr+rÚr;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|j›dƒ|jdƒ|j|ƒ|j|ƒdS)NFz9 = (Markup if context.eval_ctx.autoescape else identity)(zconcat(r8)rr‡rwrvrêrÝrxr¾rírÃr+rÚr;rHr‘rrß)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|j›d|›d|›dƒdS|j|ƒdS)
Nr;r	r—rz(undefined(name=z) if z is missing else r8rÑ)
r˜rzr|r}r«rrCrvrìZ	find_loadrrr;)r$r%r&rìr—r-r-r.rš6s

zCodeGenerator.visit_NamecCsV|jj|jƒ}|jd|›dƒ|jƒ|jdƒ|jƒ|j|›d|j›dƒdS)Nzif not isinstance(z
, Namespace):zMraise TemplateRuntimeError("cannot assign attribute on non-namespace object")rÏrÐ)rvrìrCr²r´rµÚattr)r$r%r&rìr-r-r.Úvisit_NSRefOszCodeGenerator.visit_NSRefcCs8|j|jƒ}t|tƒr&|jt|ƒƒn|jt|ƒƒdS)N)r_r)rHrYr;r\rù)r$r%r&rhr-r-r.Úvisit_Const]s
zCodeGenerator.visit_ConstcCsJy|jt|j|jƒƒƒWn*tjk
rD|jd|j›dƒYnXdS)Nz6(Markup if context.eval_ctx.autoescape else identity)(r8)r;rùr_r)r
rdÚdata)r$r%r&r-r-r.Úvisit_TemplateDatads
z CodeGenerator.visit_TemplateDatacCsZ|jdƒd}x0t|jƒD]"\}}|r0|jdƒ|j||ƒqW|j|dkrPdndƒdS)Nr6r	z, rz,)r8rÑ)r;rërcr+)r$r%r&rörgr-r-r.Úvisit_Tuplels

zCodeGenerator.visit_TuplecCsJ|jdƒx0t|jƒD]"\}}|r,|jdƒ|j||ƒqW|jdƒdS)NrÏz, rÐ)r;rërcr+)r$r%r&rörgr-r-r.Ú
visit_Listus

zCodeGenerator.visit_ListcCsd|jdƒxJt|jƒD]<\}}|r,|jdƒ|j|j|ƒ|jdƒ|j|j|ƒqW|jdƒdS)Nrþz, z: rÉ)r;rërcr+rÇrN)r$r%r&rörgr-r-r.Ú
visit_Dict}s


zCodeGenerator.visit_Dictú+ú-Ú*ú/z//z**ú%ÚandÚorznot cCsd|jjrd}n|jjrd}nd}|j|›dƒx$|jD]}|j||ƒ|jdƒq8W|jdƒdS)Nz8(markup_join if context.eval_ctx.volatile else str_join)Zmarkup_joinZstr_joinz((z, z)))r)r*r¶r;r
r+)r$r%r&r-rÌr-r-r.Úvisit_Concat”szCodeGenerator.visit_ConcatcCsB|jdƒ|j|j|ƒx|jD]}|j||ƒq W|jdƒdS)Nr6r8)r;r+rMÚops)r$r%r&r5r-r-r.Ú
visit_Compare¢s

zCodeGenerator.visit_ComparecCs*|jdt|j›dƒ|j|j|ƒdS)Nr7)r;Ú	operatorsr5r+rM)r$r%r&r-r-r.Ú
visit_OperandªszCodeGenerator.visit_OperandcCsT|jjr|jdƒ|jdƒ|j|j|ƒ|jd|j›dƒ|jjrP|jdƒdS)Nz(await auto_await(zenvironment.getattr(z, r8z)))r9rär;r+r%rl)r$r%r&r-r-r.Ú
visit_Getattr®s

zCodeGenerator.visit_GetattrcCs¢t|jtjƒr@|j|j|ƒ|jdƒ|j|j|ƒ|jdƒn^|jjrR|jdƒ|jdƒ|j|j|ƒ|jdƒ|j|j|ƒ|jdƒ|jjrž|jdƒdS)NrÏrÐz(await auto_await(zenvironment.getitem(z, r8z)))	rHrÌr
ÚSlicer+r%r;r9rä)r$r%r&r-r-r.Ú
visit_Getitemºs




zCodeGenerator.visit_GetitemcCs`|jdk	r|j|j|ƒ|jdƒ|jdk	r:|j|j|ƒ|jdk	r\|jdƒ|j|j|ƒdS)Nr9)Ústartr+r;Ústopr¸)r$r%r&r-r-r.Úvisit_SliceÏs




zCodeGenerator.visit_Slice)r%r&Ú	is_filterr!ccs|jjr|jdƒ|r@|j|j|j›dƒ|jjj|jƒ}n(|j|j|j›dƒ|jjj|jƒ}|dkr¢|jr¢|r€dnd}|jd|›d|j›d|j	ƒt
jdt
jd	t
jd
ijt
j
|ƒƒ}|dk	rÜ|j|›dƒdV|j||ƒ|jdƒ|jjr|jdƒdS)
Nzawait auto_await(r6rHr8zNo z named rržzcontext.eval_ctxr9z, r8)r9rär;rrCrYrŽr~r°r¯rržrXrZrÎ)r$r%r&r†ræÚ	type_namer[r-r-r.Ú_filter_test_commonÙs*



z!CodeGenerator._filter_test_commonc
Cs|j||dƒx|jdk	r*|j|j|ƒnX|jjrP|jd|j›d|j›dƒn2|jjrn|jd|j›dƒn|jd|j›dƒWdQRXdS)NTz(Markup(concat(z.)) if context.eval_ctx.autoescape else concat(z))zMarkup(concat(zconcat(r8)rˆr%r+r)r*r;rxr¶)r$r%r&r-r-r.r‘s
zCodeGenerator.visit_Filterc
Cs,|j||dƒ|j|j|ƒWdQRXdS)NF)rˆr+r%)r$r%r&r-r-r.r’szCodeGenerator.visit_Testcslˆjƒ‰ddœ‡‡‡fdd„}ˆjdƒˆjˆjˆƒˆjdƒˆjˆjˆƒˆjdƒ|ƒˆjdƒdS)N)r!cs8ˆjdk	rˆjˆjˆƒdSˆjdˆjˆƒ›dƒdS)Nz1cond_expr_undefined("the inline if-expression on z6 evaluated to false and no else section was defined."))Zexpr2r+r;rýr-)r&r%r$r-r.Úwrite_expr2s

z1CodeGenerator.visit_CondExpr.<locals>.write_expr2r6z if z else r8)rˆr;r+Zexpr1r8)r$r%r&r‰r-)r&r%r$r.Úvisit_CondExprs


zCodeGenerator.visit_CondExpr)r%r&rDr!cCsÈ|jjr|jdƒ|jjr&|jdƒn
|jdƒ|j|j|ƒ|rJddind}|jr\ddini}|jrnddini}|r†|j|f|Žn|sŽ|ršt	|f|Ž}|j
|||ƒ|jdƒ|jjrÄ|jdƒdS)Nzawait auto_await(zenvironment.call(context, z
context.call(rçZ
_loop_varsZ_block_varsr8)r9rär;r:r+r%r|r}rƒrbrÎ)r$r%r&rDrÅZloop_kwargsZblock_kwargsr-r-r.rE0s"


zCodeGenerator.visit_CallcCs"|j|jdƒ|j|j|ƒdS)NrÈ)r;rÇr+rN)r$r%r&r-r-r.Ú
visit_KeywordGszCodeGenerator.visit_KeywordcCs&|jdƒ|j|j|ƒ|jdƒdS)NzMarkup(r8)r;r+rM)r$r%r&r-r-r.Úvisit_MarkSafeMs
zCodeGenerator.visit_MarkSafecCs&|jdƒ|j|j|ƒ|jdƒdS)Nz6(Markup if context.eval_ctx.autoescape else identity)(r8)r;r+rM)r$r%r&r-r-r.Úvisit_MarkSafeIfAutoescapeRs
z(CodeGenerator.visit_MarkSafeIfAutoescapecCs|jd|jƒdS)Nzenvironment.)r;rC)r$r%r&r-r-r.Úvisit_EnvironmentAttributeYsz(CodeGenerator.visit_EnvironmentAttributecCs|jd|j›d|j›ƒdS)Nzenvironment.extensions[z].)r;Ú
identifierrC)r$r%r&r-r-r.Úvisit_ExtensionAttribute^sz&CodeGenerator.visit_ExtensionAttributecCs|j|j|jƒdS)N)r;rŸr)r$r%r&r-r-r.Úvisit_ImportedNamecsz CodeGenerator.visit_ImportedNamecCs|j|jƒdS)N)r;rC)r$r%r&r-r-r.Úvisit_InternalNamefsz CodeGenerator.visit_InternalNamecCs|jdƒdS)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)NÚcontinue)r²)r$r%r&r-r-r.Úvisit_ContinuesszCodeGenerator.visit_ContinuecCs|jd|ƒdS)NÚbreak)r²)r$r%r&r-r-r.Úvisit_BreakvszCodeGenerator.visit_BreakcCs:|jƒ}|jj|ƒ|j|ƒ|j|j|ƒ|j|ƒdS)N)r‡rvrêrÝr¾rírß)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†)r±r²rr+ržrr‡rvrêrÝr¾rírßr)r$r%r&r˜r™r-r-r.Úvisit_OverlayScope€s


z CodeGenerator.visit_OverlayScopec
Csxxr|jD]h}|jd|j›dƒ|j|j|ƒy|jj|jƒ}Wntjk
r^d|j_	YqXt
|j|j|ƒqWdS)Nzcontext.eval_ctx.z = T)Úoptionsr²rÇr+rNr_r)r
rdr*Úsetattr)r$r%r&Úkeywordrhr-r-r.Úvisit_EvalContextModifierŽsz'CodeGenerator.visit_EvalContextModifiercCsl|jƒ}|jjƒ}|j|›dƒ|j||ƒx|jD]}|j||ƒq6W|jj|ƒ|jd|›dƒdS)Nz = context.eval_ctx.save()zcontext.eval_ctx.revert(r8)r±r)Úsaver²rŸrír+Úrevert)r$r%r&Zold_ctx_nameZ	saved_ctxrfr-r-r.Úvisit_ScopedEvalContextModifier›s
z-CodeGenerator.visit_ScopedEvalContextModifier)NFT)F)r	)N)N)Nr)Nr)N)F)ràrá)N)F)µrnrorpr1rŠr\ÚTextIOrWrmÚpropertyrGrXr°r±r#rxr·r´rµr
ÚNoder¹rºr¼r›r¾r;r²rÃrqÚCallr”r•ÚMappingr2rÎrÔrÝrßrårærrrsr*rirørürýrÿrròrôrórrrrÖrrrrrIr#r–r“rr(ÚIncluder.ÚImportZ
FromImportr0r2r4ÚForr@ÚIfrBrCrGZFilterBlockrIÚWithrNZExprStmtrOZ
NamedTuplerSÚstaticmethodrTrWr\r^r0rarbrcZOutputriÚAssignrjZAssignBlockrkrœršZNSRefrmr)rnr`rprqr+rrÚDictrsr@Z	visit_AddZ	visit_SubZ	visit_MulZ	visit_DivZvisit_FloorDivZ	visit_PowZ	visit_ModZ	visit_AndZvisit_OrrBZ	visit_PosZ	visit_NegZ	visit_Notr4ZConcatr{ÚComparer}ZOperandrZGetattrr€ZGetitemr‚rr…rÚIteratorrˆr‘r’ZCondExprrŠrEÚKeywordr‹ZMarkSaferŒZMarkSafeIfAutoescaperZEnvironmentAttributerŽZExtensionAttributerrr‘ZInternalNamer’ZContextReferencer“ZDerivedContextReferencer”ÚContinuer–ÚBreakr˜ZScoperšZOverlayScoper›ZEvalContextModifierrŸZScopedEvalContextModifierr¢r-r-r-r.r",s
"A,4+Q	.u++4
2
0	O	


'
)NFT)Fr‰Útypingr1Ú
contextlibrÚ	functoolsrÚiorÚ	itertoolsrržrrÆZ
markupsaferrrár
Ú
exceptionsrZ
idtrackingrr
rrrrr(rÚutilsrrr>rZ
TYPE_CHECKINGZtyping_extensionsÚter9rZTypeVarrPr2rr~r4r\r?r@rArBrIrŠr£rWrMrOr›r¥ÚSetrhrir#ÚRuntimeErrorrfrŒrererr"r-r-r-r.Ú<module>sd" &
S