zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
U
Þ=®d¥ïã@s˜dZddlZddlZddlZddlZddlmZddlmZddlm    Z    ddlm
Z
ddl m Z ddl mZd    d
lmZd    d lmZd    d lmZd    d lmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlm Z d    dlm!Z!d    dlm"Z"d    dlm#Z#d    dlm$Z$d    dl%m&Z&d    dl%m'Z'd    dl%m(Z(d    d l%m)Z)d    d!l%m*Z*d    d"l+m,Z,d    d#l+m-Z-d    d$l+m.Z.d    d%lm/Z/d    d&l0m1Z1d    d'l2m3Z3d    d(l2m4Z4d    d)l2m5Z5d    d*l6m7Z7d    d+l6m8Z8d    d,l6m9Z9d    d-l6m:Z:d    d.l6m;Z;d    d/l6m<Z<d    d0l6m=Z=ej>rtddl?Z@d    d1lAmBZBd    d2lCmDZDd    d3lEmFZFejGd4d5d6ZHed7d8ejIeHejJeHd9œd:d;„ƒZKeLejMejNejOejPeQfd<fd=œd>d?„ZRejMejNejMejNejOejPeQfd<fd@œdAdB„ZSd5ejTejUeQejIdCfejVeQdCfdDœdEdF„ZWd5d5dGœdHdI„ZXGdJd5„d5ƒZYGdKd<„d<ƒZZGdLdM„dMƒZ[GdNdO„dOƒZ\GdPdQ„dQƒZ]eZeY_^dS)RzKClasses for managing templates and their runtime and compile time
options.
éN)ÚChainMap)Ú    lru_cache)Úpartial)Úreduce)ÚCodeType)ÚMarkupé)Únodes)Ú CodeGenerator)Úgenerate)ÚBLOCK_END_STRING)ÚBLOCK_START_STRING)ÚCOMMENT_END_STRING)ÚCOMMENT_START_STRING)ÚDEFAULT_FILTERS)ÚDEFAULT_NAMESPACE)ÚDEFAULT_POLICIES)Ú DEFAULT_TESTS)ÚKEEP_TRAILING_NEWLINE)ÚLINE_COMMENT_PREFIX)ÚLINE_STATEMENT_PREFIX)Ú LSTRIP_BLOCKS)ÚNEWLINE_SEQUENCE)Ú TRIM_BLOCKS)ÚVARIABLE_END_STRING)ÚVARIABLE_START_STRING)ÚTemplateNotFound)ÚTemplateRuntimeError)ÚTemplatesNotFound)ÚTemplateSyntaxError)ÚUndefinedError©Ú    get_lexer)ÚLexer)Ú TokenStream)Ú EvalContext)ÚParser)ÚContext)Ú new_context)Ú    Undefined)Ú_PassArg)Úconcat)Úconsume)Ú import_string)Ú internalcode©ÚLRUCache)Úmissing)Ú BytecodeCache)Ú    Extension)Ú
BaseLoaderÚ
_env_boundÚ Environment)Úboundé
)Úmaxsize)ÚclsÚargsÚreturncGs||Ž}d|_|S)a Return a new spontaneous environment. A spontaneous environment
    is used for templates created directly rather than through an
    existing environment.
 
    :param cls: Environment class to create.
    :param args: Positional arguments passed to environment.
    T)Úshared)r:r;Úenv©r?úId:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\jinja2/environment.pyÚget_spontaneous_environmentBs    rAÚTemplate©Úsizer<cCs |dkr dS|dkriSt|ƒS)z*Return the cache class for the given size.rNr/)rDr?r?r@Ú create_cachePs
rE)Úcacher<cCs&|dkr dSt|ƒtkriSt|jƒS)z(Create an empty copy of the given cache.N)ÚtypeÚdictr0Úcapacity)rFr?r?r@Ú
copy_cache]s
 rJr3)Ú environmentÚ
extensionsr<cCs@i}|D]2}t|tƒr,t tjdt|ƒ¡}||ƒ||j<q|S)zuLoad the extensions from the list and bind it to the environment.
    Returns a dict of instantiated extensions.
    r3)Ú
isinstanceÚstrÚtÚcastÚTyper-Ú
identifier)rKrLÚresultÚ    extensionr?r?r@Úload_extensionsjs 
rU)rKr<cCsNt|jtƒstdƒ‚|j|jkr.|jks8ntdƒ‚|jdksJtdƒ‚|S)z*Perform a sanity check on the environment.z5'undefined' must be a subclass of 'jinja2.Undefined'.z<block, variable and comment start strings must be different.>ú
ú Ú
z8'newline_sequence' must be one of '\n', '\r\n', or '\r'.)Ú
issubclassÚ    undefinedr)ÚAssertionErrorÚblock_start_stringÚvariable_start_stringÚcomment_start_stringÚnewline_sequence)rKr?r?r@Ú_environment_config_check|s"ÿþþý
ü ür`c@sjeZdZUdZdZdZdZejde    d<dZ
e Z ej de    d<djZeZej ee    d<ej d    e    d
<eeeeeeeeeeeed d edddd d ddfeeeeeeejeejee e de ej!ej"eej dfe ej eejej#dej$fej"e ej#ejege ffejde%e ejde dœdd„Z&ej"eej dfddœdd„Z'ej$ddœdd„Z(e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)dfeeeeeeejeejee e de ej!ej"eej dfe ej eejej#dej$fej"e ej#ejege ffejde%e ejde ddœdd„Z*e+e,dœd d!„ƒZ-ej.ddœd"d#„Z/ej$ej"eej$fej"ej$efd$œd%d&„Z0ej$eej$d'œd(d)„Z1ej"eefej$ejej!ej$ejej2eej$fejeeje3e ej$d*œd+d,„Z4doeej$ejej!ej$ejej2eej$fejeeje3ej$d-œd.d/„Z5dpeej$ejej!ej$ejej2eej$fejeeje3ej$d-œd0d1„Z6e7dqeejeejee8j9d2œd3d4„ƒZ:eejeejee8j9d2œd5d6„Z;dreejeejeej.ej<e%eefd2œd7d8„Z=dseejeejeed2œd9d:„Z>dteejeejeejee?d;œd<d=„Z@due8j9ejeejee ed>œd?d@„ZAeeeBdAœdBdC„ZCeDjEdvej"ee8j9fejeejedDe eBdEœdFdG„ƒZFeDjEdwej"ee8j9fejeejedHe edEœdIdG„ƒZFe7dxej"ee8j9fejeejee e ej"eeBfdEœdJdG„ƒZFdyee dKdLœdMdN„ZGdzej"eeHjIfejejJeejej#ege fejeejej#egdfe ddPœdQdR„ZKd{ejejJeejej#ege fejLedSœdTdU„ZMd|ejedVdWœdXdY„ZNeeedZœd[d\„ZOe7eejejPeej$fd    d]œd^d_„ƒZQe7d}ej"ed    fejeejejPeej$fd    d`œdadb„ƒZRe7d~ejSej"ed    fejeejejPeej$fd    dcœddde„ƒZTe7dej"ed    ejLej"ed    ffejeejejPeej$fd    dfœdgdh„ƒZUd€ej"ee8j9fejejPeej$fejej d    d    diœdjdk„ZVejejPeej$fejPeej$fdlœdmdn„ZWdS)r6a¤The core component of Jinja is the `Environment`.  It contains
    important shared variables like configuration, filters, tests,
    globals and others.  Instances of this class may be modified if
    they are not shared and if no template was loaded so far.
    Modifications on environments after the first template was loaded
    will lead to surprising effects and undefined behavior.
 
    Here are the possible initialization parameters:
 
        `block_start_string`
            The string marking the beginning of a block.  Defaults to ``'{%'``.
 
        `block_end_string`
            The string marking the end of a block.  Defaults to ``'%}'``.
 
        `variable_start_string`
            The string marking the beginning of a print statement.
            Defaults to ``'{{'``.
 
        `variable_end_string`
            The string marking the end of a print statement.  Defaults to
            ``'}}'``.
 
        `comment_start_string`
            The string marking the beginning of a comment.  Defaults to ``'{#'``.
 
        `comment_end_string`
            The string marking the end of a comment.  Defaults to ``'#}'``.
 
        `line_statement_prefix`
            If given and a string, this will be used as prefix for line based
            statements.  See also :ref:`line-statements`.
 
        `line_comment_prefix`
            If given and a string, this will be used as prefix for line based
            comments.  See also :ref:`line-statements`.
 
            .. versionadded:: 2.2
 
        `trim_blocks`
            If this is set to ``True`` the first newline after a block is
            removed (block, not variable tag!).  Defaults to `False`.
 
        `lstrip_blocks`
            If this is set to ``True`` leading spaces and tabs are stripped
            from the start of a line to a block.  Defaults to `False`.
 
        `newline_sequence`
            The sequence that starts a newline.  Must be one of ``'\r'``,
            ``'\n'`` or ``'\r\n'``.  The default is ``'\n'`` which is a
            useful default for Linux and OS X systems as well as web
            applications.
 
        `keep_trailing_newline`
            Preserve the trailing newline when rendering templates.
            The default is ``False``, which causes a single newline,
            if present, to be stripped from the end of the template.
 
            .. versionadded:: 2.7
 
        `extensions`
            List of Jinja extensions to use.  This can either be import paths
            as strings or extension classes.  For more information have a
            look at :ref:`the extensions documentation <jinja-extensions>`.
 
        `optimized`
            should the optimizer be enabled?  Default is ``True``.
 
        `undefined`
            :class:`Undefined` or a subclass of it that is used to represent
            undefined values in the template.
 
        `finalize`
            A callable that can be used to process the result of a variable
            expression before it is output.  For example one can convert
            ``None`` implicitly into an empty string here.
 
        `autoescape`
            If set to ``True`` the XML/HTML autoescaping feature is enabled by
            default.  For more details about autoescaping see
            :class:`~markupsafe.Markup`.  As of Jinja 2.4 this can also
            be a callable that is passed the template name and has to
            return ``True`` or ``False`` depending on autoescape should be
            enabled by default.
 
            .. versionchanged:: 2.4
               `autoescape` can now be a function
 
        `loader`
            The template loader for this environment.
 
        `cache_size`
            The size of the cache.  Per default this is ``400`` which means
            that if more than 400 templates are loaded the loader will clean
            out the least recently used template.  If the cache size is set to
            ``0`` templates are recompiled all the time, if the cache size is
            ``-1`` the cache will not be cleaned.
 
            .. versionchanged:: 2.8
               The cache size was increased to 400 from a low 50.
 
        `auto_reload`
            Some loaders load templates from locations where the template
            sources may change (ie: file system or database).  If
            ``auto_reload`` is set to ``True`` (default) every time a template is
            requested the loader checks if the source changed and if yes, it
            will reload the template.  For higher performance it's possible to
            disable that.
 
        `bytecode_cache`
            If set to a bytecode cache object, this object will provide a
            cache for the internal Jinja bytecode so that templates don't
            have to be parsed if they were not changed.
 
            See :ref:`bytecode-cache` for more information.
 
        `enable_async`
            If set to true this enables async template execution which
            allows using async functions and generators.
    FNÚ    linked_tor
Úcode_generator_classÚÚ context_classrBÚtemplate_classr?Tiúte.Literal['\n', '\r\n', '\r']r3.r4r2)r\Úblock_end_stringr]Úvariable_end_stringr^Úcomment_end_stringÚline_statement_prefixÚline_comment_prefixÚ trim_blocksÚ lstrip_blocksr_Úkeep_trailing_newlinerLÚ    optimizedrZÚfinalizeÚ
autoescapeÚloaderÚ
cache_sizeÚ auto_reloadÚbytecode_cacheÚ enable_asynccCsÂ||_||_||_||_||_||_||_||_|    |_|
|_    | |_
| |_ ||_ ||_ ||_||_t ¡|_t ¡|_t ¡|_||_t|ƒ|_||_||_t ¡|_t|| ƒ|_||_ t!|ƒdS©N)"r\rgr]rhr^rirjrkrlrmr_rnrZrorprqrÚcopyÚfiltersrÚtestsrÚglobalsrrrErFrurtrZpoliciesrUrLÚis_asyncr`)Úselfr\rgr]rhr^rirjrkrlrmr_rnrLrorZrprqrrrsrtrurvr?r?r@Ú__init__$s6%
 
 
 
 
 zEnvironment.__init__)rTr<cCs|j t||gƒ¡dS)z\Adds an extension after the environment was created.
 
        .. versionadded:: 2.5
        N)rLÚupdaterU)r}rTr?r?r@Ú add_extensionpszEnvironment.add_extension)Ú
attributesr<cKs,| ¡D]\}}t||ƒst|||ƒqdS)zèAdd the items to the instance of the environment if they do not exist
        yet.  This is used by :ref:`extensions <writing-extensions>` to register
        callbacks and configuration values without breaking inheritance.
        N)ÚitemsÚhasattrÚsetattr)r}rÚkeyÚvaluer?r?r@Úextendws
zEnvironment.extend)r\rgr]rhr^rirjrkrlrmr_rnrLrorZrprqrrrsrtrurvr<cCsèttƒƒ}|d=|d=|d=|d=t |j¡}|j |j¡d|_||_|     ¡D]\}}|t
k    rPt |||ƒqP|t
k    r‚t |ƒ|_ n t|j ƒ|_ i|_|j     ¡D]\}}| |¡|j|<qž| t
k    rÒ|j t|| ƒ¡|t
k    rà||_t|ƒS)aCreate a new overlay environment that shares all the data with the
        current environment except for cache and the overridden attributes.
        Extensions cannot be removed for an overlayed environment.  An overlayed
        environment automatically gets all the extensions of the environment it
        is linked to plus optional extra extensions.
 
        Creating overlays should happen after the initial environment was set
        up completely.  Not all attributes are truly linked, some are just
        copied over so modifications on the original environment may not shine
        through.
 
        .. versionchanged:: 3.1.2
            Added the ``newline_sequence``,, ``keep_trailing_newline``,
            and ``enable_async`` parameters to match ``__init__``.
        r}rsrLrvT)rHÚlocalsÚobjectÚ__new__Ú    __class__Ú__dict__rÚ    overlayedrar‚r1r„rErFrJrLÚbindrUr|r`)r}r\rgr]rhr^rirjrkrlrmr_rnrLrorZrprqrrrsrtrurvr;Úrvr…r†r?r?r@Úoverlay€s((
   zEnvironment.overlay©r<cCst|ƒS)zThe lexer for this environment.r!©r}r?r?r@ÚlexerÄszEnvironment.lexercCstt|j ¡dd„dƒS)z)Iterates over the extensions by priority.cSs|jSrw)Úpriority©Úxr?r?r@Ú<lambda>Ëóz-Environment.iter_extensions.<locals>.<lambda>)r…)ÚiterÚsortedrLÚvaluesr’r?r?r@Úiter_extensionsÉszEnvironment.iter_extensions)ÚobjÚargumentr<c CsŠz
||WStttfk
r„t|tƒrrz t|ƒ}Wntk
rJYn(Xzt||ƒWYStk
rpYnX|j||dYSXdS)z:Get an item or attribute of an object but prefer the item.©rÚnameN)ÚAttributeErrorÚ    TypeErrorÚ LookupErrorrMrNÚ    ExceptionÚgetattrrZ)r}rržÚattrr?r?r@ÚgetitemÍs
 
 zEnvironment.getitem)rÚ    attributer<c
CsZz t||ƒWStk
r YnXz
||WStttfk
rT|j||dYSXdS)z‰Get an item or attribute of an object but prefer the attribute.
        Unlike :meth:`getitem` the attribute *must* be a string.
        rŸN)r¥r¡r¢r£rZ)r}rr¨r?r?r@r¥às 
zEnvironment.getattr)r r†r;ÚkwargsÚcontextÚeval_ctxÚ    is_filterr<c
CsP|r|j}d}    n
|j}d}    | |¡}
|
dkrd|    ›d|›d} t|tƒrˆz | ¡Wn2tk
r†} z| ›d| ›d} W5d} ~ XYnXt| ƒ‚|f|dk    r |nd•}|dk    r²|ni}t     |
¡} | tj
krð|dkrâtd    |    ›d
ƒ‚|  d |¡nV| tj kr.|dkr |dk    r|j }nt|ƒ}|  d |¡n| tjkrF|  d |¡|
||ŽS) NÚfilterÚtestzNo z named Ú.z (z-; did you forget to quote the callable name?)r?zAttempted to invoke a context z without context.r)ryrzÚgetrMr)Ú_fail_with_undefined_errorr¤rr*Zfrom_objrªÚinsertZ eval_contextr«r%rK)r}r r†r;r©rªr«r¬Zenv_mapZ    type_nameÚfuncÚmsgÚeZpass_argr?r?r@Ú_filter_test_commonís@
 
 
 "
 
 
ÿ 
 
  zEnvironment._filter_test_common)r r†r;r©rªr«r<c    Cs| ||||||d¡S)a/Invoke a filter on a value the same way the compiler does.
 
        This might return a coroutine if the filter is running from an
        environment in async mode and the filter supports async
        execution. It's your responsibility to await this if needed.
 
        .. versionadded:: 2.7
        T©r¶©r}r r†r;r©rªr«r?r?r@Ú call_filter#sÿzEnvironment.call_filterc    Cs| ||||||d¡S)aÇInvoke a test on a value the same way the compiler does.
 
        This might return a coroutine if the test is running from an
        environment in async mode and the test supports async execution.
        It's your responsibility to await this if needed.
 
        .. versionchanged:: 3.0
            Tests support ``@pass_context``, etc. decorators. Added
            the ``context`` and ``eval_ctx`` parameters.
 
        .. versionadded:: 2.7
        Fr·r¸r?r?r@Ú    call_test8sÿzEnvironment.call_test)Úsourcer Úfilenamer<cCs6z| |||¡WStk
r0|j|dYnXdS)ašParse the sourcecode and return the abstract syntax tree.  This
        tree of nodes is used by the compiler to convert the template into
        executable source- or bytecode.  This is useful for debugging or to
        extract information from templates.
 
        If you are :ref:`developing Jinja extensions <writing-extensions>`
        this gives you a good overview of the node tree generated.
        ©r»N)Ú_parserÚhandle_exception©r}r»r r¼r?r?r@ÚparseQszEnvironment.parsecCst||||ƒ ¡S)z8Internal parsing function used by `parse` and `compile`.)r&rÁrÀr?r?r@r¾eszEnvironment._parsecCs@t|ƒ}z|j |||¡WStk
r:|j|dYnXdS)aºLex the given sourcecode and return a generator that yields
        tokens as tuples in the form ``(lineno, token_type, value)``.
        This can be useful for :ref:`extension development <writing-extensions>`
        and debugging templates.
 
        This does not perform preprocessing.  If you want the preprocessing
        of the extensions to be applied you have to filter source through
        the :meth:`preprocess` method.
        r½N)rNr“Z    tokeniterrr¿rÀr?r?r@Úlexks
zEnvironment.lexcst‡‡fdd„| ¡t|ƒƒS)zäPreprocesses the source with all extensions.  This is automatically
        called for all parsing and compiling methods but *not* for :meth:`lex`
        because there you usually only want the actual source tokenized.
        cs| |ˆˆ¡Srw)Ú
preprocess)Úsrµ©r¼r r?r@r—‹r˜z(Environment.preprocess.<locals>.<lambda>)rrœrNrÀr?rÅr@rÀs
 
 ýzEnvironment.preprocess)r»r r¼Ústater<cCsR| |||¡}|j ||||¡}| ¡D]$}| |¡}t|tƒs(t|||ƒ}q(|S)z’Called by the parser to do the preprocessing and filtering
        for all the extensions.  Returns a :class:`~jinja2.lexer.TokenStream`.
        )rÃr“ÚtokenizerœZ filter_streamrMr$)r}r»r r¼rÆÚstreamÚextr?r?r@Ú    _tokenizes
 
 
zEnvironment._tokenize)r»r r¼Ú
defer_initr<cCst||||||jdS)z|Internal hook that can be overridden to hook a different generate
        method in.
 
        .. versionadded:: 2.5
        )rËro)r ro)r}r»r r¼rËr?r?r@Ú    _generate¥s úzEnvironment._generate)r»r¼r<cCs t||dƒS)z{Internal hook that can be overridden to hook a different compile
        method in.
 
        .. versionadded:: 2.5
        Úexec)Úcompile)r}r»r¼r?r?r@Ú_compileºszEnvironment._compilezte.Literal[False])r»r r¼ÚrawrËr<cCsdSrwr?©r}r»r r¼rÐrËr?r?r@rÎÂs    zEnvironment.compilezte.Literal[True]cCsdSrwr?rÑr?r?r@rÎÍs    cCs|d}zRt|tƒr"|}| |||¡}|j||||d}|r>|WS|dkrJd}| ||¡WStk
rv|j|dYnXdS)ašCompile a node or template source code.  The `name` parameter is
        the load name of the template after it was joined using
        :meth:`join_path` if necessary, not the filename on the file system.
        the `filename` parameter is the estimated filename of the template on
        the file system.  If the template came from a database or memory this
        can be omitted.
 
        The return value of this method is a python code object.  If the `raw`
        parameter is `True` the return value will be a string with python
        code equivalent to the bytecode returned otherwise.  This method is
        mainly used internally.
 
        `defer_init` is use internally to aid the module code generator.  This
        causes the generated code to be able to import without the global
        environment variable to be set.
 
        .. versionadded:: 2.4
           `defer_init` parameter added.
        N)rËz
<template>r½)rMrNr¾rÌrÏrr¿)r}r»r r¼rÐrËZ source_hintr?r?r@rÎØs
ÚTemplateExpression)r»Úundefined_to_noner<cCsšt||dd}z2| ¡}|jjs4td|jjjddƒ‚| |¡Wn tk
r`|j|dYnXt    j
t      dd¡|dd    g}|  t    j |dd    ¡}t||ƒS)
a‚A handy helper method that returns a callable that accepts keyword
        arguments that appear as variables in the expression.  If called it
        returns the result of the expression.
 
        This is useful if applications want to use the same rules as Jinja
        in template "configuration files" or similar situations.
 
        Example usage:
 
        >>> env = Environment()
        >>> expr = env.compile_expression('foo == 42')
        >>> expr(foo=23)
        False
        >>> expr(foo=42)
        True
 
        Per default the return value is converted to `None` if the
        expression returns an undefined value.  This can be changed
        by setting `undefined_to_none` to `False`.
 
        >>> env.compile_expression('var')() is None
        True
        >>> env.compile_expression('var', undefined_to_none=False)()
        Undefined
 
        .. versionadded:: 2.1
        Úvariable)rÆzchunk after expressionNr½rSÚstorer)Úlineno)r&Zparse_expressionrÈZeosrÚcurrentrÖZset_environmentr¿r    ZAssignÚNameÚ from_stringrBrÒ)r}r»rÓÚparserÚexprÚbodyÚtemplater?r?r@Úcompile_expressions ÿzEnvironment.compile_expressionÚdeflated)ÚtargetrLÚ filter_funcÚzipÚ log_functionÚ ignore_errorsr<c sšddlm}|dkr$tddœdd„}|dk    s0t‚|jdk    sBtdƒ‚ttddœ‡‡‡‡fd    d
„ }ˆdk    r¦d d lm}    m‰m}
m    } |    ˆd t
|
| dˆƒ‰|dˆ›ƒn$t j   ˆ¡s¼t  ˆ¡|dˆ›ƒz²| ||¡D] } |j || ¡\} }}z| | | |dd¡}WnHtk
rN}z(|s"‚|d| ›d|›ƒWY¢qØW5d}~XYnX| | ¡}|||ƒ|d| ›d|›ƒqØW5ˆrŒˆ ¡X|dƒdS)a3Finds all the templates the loader can find, compiles them
        and stores them in `target`.  If `zip` is `None`, instead of in a
        zipfile, the templates will be stored in a directory.
        By default a deflate zip algorithm is used. To switch to
        the stored algorithm, `zip` can be set to ``'stored'``.
 
        `extensions` and `filter_func` are passed to :meth:`list_templates`.
        Each template returned will be compiled to the target folder or
        zipfile.
 
        By default template compilation errors are ignored.  In case a
        log function is provided, errors are logged.  If you want template
        syntax errors to abort the compilation you can set `ignore_errors`
        to `False` and you will get an exception on syntax errors.
 
        .. versionadded:: 2.4
        r)Ú ModuleLoaderN©r–r<cSsdSrwr?r•r?r?r@rãMsz3Environment.compile_templates.<locals>.log_functionúNo loader configured.)r¼Údatar<c    sTˆr ˆ|ƒ}d|_ˆ ||¡n0ttj ˆ|¡dƒ}| | d¡¡W5QRXdS)NiíÚwbÚutf8)Ú external_attrÚwritestrÚopenÚosÚpathÚjoinÚwriteÚencode)r¼rèÚinfoÚf©ÚZipInforàrâÚzip_filer?r@Ú
write_fileSs z1Environment.compile_templates.<locals>.write_filer)ÚZipFileröÚ ZIP_DEFLATEDÚ
ZIP_STOREDÚw)rßZstoredzCompiling into Zip archive zCompiling into folder TzCould not compile "z": z
Compiled "z" as zFinished compiling templates)ÚloadersrårNr[rrÚzipfilerùrörúrûrHrîrïÚisdirÚmakedirsÚcloseÚlist_templatesÚ
get_sourcerÎrZget_module_filename)r}ràrLrárârãrärårørùrúrûr r»r¼Ú_Úcoderµr?rõr@Úcompile_templates/sB      ÿ 
 
 
 
zEnvironment.compile_templates)rLrár<csf|jdk    stdƒ‚|j ¡}ˆdk    rHˆdk    r4tdƒ‚ttdœ‡fdd„ ‰ˆdk    rb‡fdd„|Dƒ}|S)    aªReturns a list of templates for this environment.  This requires
        that the loader supports the loader's
        :meth:`~BaseLoader.list_templates` method.
 
        If there are other files in the template folder besides the
        actual templates, the returned list can be filtered.  There are two
        ways: either `extensions` is set to a list of file extensions for
        templates, or a `filter_func` can be provided which is a callable that
        is passed a template name and should return `True` if it should end up
        in the result list.
 
        If the loader does not support that, a :exc:`TypeError` is raised.
 
        .. versionadded:: 2.4
        Nrçz<either extensions or filter_func can be passed, but not bothræcsd|ko| dd¡dˆkS)Nr¯r)Úrsplitr•)rLr?r@rášsz/Environment.list_templates.<locals>.filter_funccsg|]}ˆ|ƒr|‘qSr?r?)Ú.0r )rár?r@Ú
<listcomp>žsz.Environment.list_templates.<locals>.<listcomp>)rrr[rr¢rNÚbool)r}rLráÚnamesr?)rLrár@r}s
ÿzEnvironment.list_templatesz te.NoReturn)r»r<cCsddlm}||d‚dS)zšException handling helper.  This is used internally to either raise
        rewritten exceptions or return a rendered traceback for the template.
        r)Úrewrite_traceback_stackr½N)Údebugr )r}r»r r?r?r@r¿¢s zEnvironment.handle_exception)rÝÚparentr<cCs|S)ašJoin a template with the parent.  By default all the lookups are
        relative to the loader root so this method returns the `template`
        parameter unchanged, but if the paths should be relative to the
        parent template, this function can be used to calculate the real
        template name.
 
        Subclasses may override this method and implement template path
        joining here.
        r?)r}rÝrr?r?r@Ú    join_pathªs
zEnvironment.join_path)r r{r<cCsŽ|jdkrtdƒ‚t |j¡|f}|jdk    r`|j |¡}|dk    r`|jrL|jr`|r\|j     |¡|S|j 
|||  |¡¡}|jdk    rŠ||j|<|S)Nz(no loader for this environment specified) rrr¢ÚweakrefÚrefrFr°rtÚ is_up_to_dater{rÚloadÚ make_globals)r}r r{Ú    cache_keyrÝr?r?r@Ú_load_template¶s"
 
 ÿÿ 
 
zEnvironment._load_template)r rr{r<cCs.t|tƒr|S|dk    r"| ||¡}| ||¡S)aHLoad a template by name with :attr:`loader` and return a
        :class:`Template`. If the template does not exist a
        :exc:`TemplateNotFound` exception is raised.
 
        :param name: Name of the template to load. When loading
            templates from the filesystem, "/" is used as the path
            separator, even on Windows.
        :param parent: The name of the parent template importing this
            template. :meth:`join_path` can be used to implement name
            transformations with this.
        :param globals: Extend the environment :attr:`globals` with
            these extra variables available for all renders of this
            template. If the template has already been loaded and
            cached, its globals are updated with any new items.
 
        .. versionchanged:: 3.0
            If a template is loaded from cache, ``globals`` will update
            the template's globals instead of ignoring the new values.
 
        .. versionchanged:: 2.4
            If ``name`` is a :class:`Template` object it is returned
            unchanged.
        N)rMrBrr)r}r rr{r?r?r@Ú get_templateÏs
 
 zEnvironment.get_template)r rr{r<c
Csˆt|tƒr| ¡|s tdd‚|D]V}t|tƒr:|S|dk    rN| ||¡}z| ||¡WSttfk
rxYq$Xq$t|ƒ‚dS)aøLike :meth:`get_template`, but tries loading multiple names.
        If none of the names can be loaded a :exc:`TemplatesNotFound`
        exception is raised.
 
        :param names: List of template names to try loading in order.
        :param parent: The name of the parent template importing this
            template. :meth:`join_path` can be used to implement name
            transformations with this.
        :param globals: Extend the environment :attr:`globals` with
            these extra variables available for all renders of this
            template. If the template has already been loaded and
            cached, its globals are updated with any new items.
 
        .. versionchanged:: 3.0
            If a template is loaded from cache, ``globals`` will update
            the template's globals instead of ignoring the new values.
 
        .. versionchanged:: 2.11
            If ``names`` is :class:`Undefined`, an :exc:`UndefinedError`
            is raised instead. If no templates were found and ``names``
            contains :class:`Undefined`, the message is more helpful.
 
        .. versionchanged:: 2.4
            If ``names`` contains a :class:`Template` object it is
            returned unchanged.
 
        .. versionadded:: 2.3
        z0Tried to select from an empty list of templates.)ÚmessageN)    rMr)r±rrBrrrr )r}r rr{r r?r?r@Úselect_templateôs #
ÿ
 zEnvironment.select_template)Útemplate_name_or_listrr{r<cCs8t|ttfƒr| |||¡St|tƒr*|S| |||¡S)z¤Use :meth:`select_template` if an iterable of template names
        is given, or :meth:`get_template` if one name is given.
 
        .. versionadded:: 2.3
        )rMrNr)rrBr)r}rrr{r?r?r@Úget_or_select_template*s
 
z"Environment.get_or_select_template)r»r{rer<cCs*| |¡}|p|j}| || |¡|d¡S)aýLoad a template from a source string without using
        :attr:`loader`.
 
        :param source: Jinja source to compile into a template.
        :param globals: Extend the environment :attr:`globals` with
            these extra variables available for all renders of this
            template. If the template has already been loaded and
            cached, its globals are updated with any new items.
        :param template_class: Return an instance of this
            :class:`Template` class.
        N)rreÚ    from_coderÎ)r}r»r{reZgsr:r?r?r@rÙ>s
 
zEnvironment.from_string)Údr<cCs|dkr i}t||jƒS)aSMake the globals map for a template. Any given template
        globals overlay the environment :attr:`globals`.
 
        Returns a :class:`collections.ChainMap`. This allows any changes
        to a template's globals to only affect that template, while
        changes to the environment's globals are still reflected.
        However, avoid modifying any globals after a template is loaded.
 
        :param d: Dict of template-specific globals.
 
        .. versionchanged:: 3.0
            Use :class:`collections.ChainMap` to always prevent mutating
            environment globals.
        N)rr{)r}rr?r?r@rSszEnvironment.make_globals)NNNN)NNNN)NN)NN)NN)NN)F)NNFF)NN.F)NNFF)T)NNrßNT)NN)N)NN)NN)NN)NN)XÚ__name__Ú
__module__Ú __qualname__Ú__doc__Z    sandboxedrrarOÚOptionalÚ__annotations__r=r
rbrQrðr+r'rdr r rrrrrrrrrrr)rNr
ÚSequenceÚUnionÚCallableÚAnyÚintr~r€r‡r1rÚpropertyr#r“ÚIteratorrœr§r¥ÚMappingr%r¶r¹rºr.r    rBrÁr¾ÚTuplerÂrÃr$rÊrÌrrÏÚtypingÚoverloadrÎrÞrîÚPathLikeÚ
CollectionrÚListrr¿rÚMutableMappingrrÚIterablerrrÙrr?r?r?r@r6Žsh
}éé L  éè Dþ  ÷ :ùø ùø üûþ     üû üû ûú ûú úù
úù
ú ù*ÿþ 0ùø Pýü % þü û$üû5úÿùüû þc@sÞeZdZUdZeZejeed<eed<ej    e
ej fed<ej e
ed<ej e
ed<ej e
ejegeje
ffed<ejegeje
fed<ej d    ed
<e
ed <ej ejgefed <eeeeeeeeeeeed dedddfeje
e j!fe
e
e
e
e
e
ej e
ej e
eedeej"eje
ejdfeejeej ejdej fejeejej e
geffeej dœdd„Z#e$dDee%ej    e
ej fej ejgefddœdd„ƒZ&e$eej    e
ej fej    e
ej fddœdd„ƒZ'e$eej    e
ej fej    e
ej fddœdd„ƒZ(ej ej e
d œd!d"„Z)ej ej e
d œd#d$„Z*ej ej d%d œd&d'„Z+ej ej eje
d œd(d)„Z,ej ej ej-e
d œd*d+„Z.dEej ej e
ej feej ej/e
ej fed,œd-d.„Z0dFej ej e
ej feej ej/e
ej fd    d,œd/d0„Z1dGej ej e
ej feej ej/e
ej fd    d,œd1d2„Z2e3dHej ed    d3œd4d5„ƒZ4dIej ed    d3œd6d7„Z5e6d    d8œd9d:„ƒZ7e8e8d;œd<d=„Z9e6ed8œd>d?„ƒZ:e6ej;ej<e8e8fd8œd@dA„ƒZ=e
d8œdBdC„Z>dS)JrBaoA compiled template that can be rendered.
 
    Use the methods on :class:`Environment` to create or load templates.
    The environment is used to configure how templates are compiled and
    behave.
 
    It is also possible to create a template object directly. This is
    not usually recommended. The constructor takes most of the same
    arguments as :class:`Environment`. All templates created with the
    same environment arguments share the same ephemeral ``Environment``
    instance behind the scenes.
 
    A template object should be considered immutable. Modifications on
    the object are not supported.
    Úenvironment_classrKr{r r¼ÚblocksÚroot_render_funcÚTemplateModuleÚ_moduleÚ _debug_infoÚ    _uptodater?TNFrfr3.)r»r\rgr]rhr^rirjrkrlrmr_rnrLrorZrprqrvr<cCsHt|j||||||||    |
| | | t|ƒ||||dddd|ƒ}|j||dS)NrF)re)rAr4Ú    frozensetrÙ)r:r»r\rgr]rhr^rirjrkrlrmr_rnrLrorZrprqrvr>r?r?r@rЉs4ézTemplate.__new__)rKrr{Úuptodater<cCs.||jdœ}t||ƒ| |||¡}||_|S)z˜Creates a template object from compiled code and the globals.  This
        is used by the loaders and environment to create a template object.
        )rKÚ__file__)Ú co_filenamerÍÚ_from_namespacer:)r:rKrr{r<Ú    namespacerr?r?r@rºs
 
zTemplate.from_code)rKÚ module_dictr{r<cCs| |||¡S)z˜Creates a template object from a module.  This is used by the
        module loader to create a template object.
 
        .. versionadded:: 2.4
        )r?)r:rKrAr{r?r?r@Úfrom_module_dictËs zTemplate.from_module_dict)rKr@r{r<cCsht |¡}||_||_|d|_|d|_|d|_|d|_d|_|d|_    d|_
||d<||d<|S)Nr r=r5ÚrootÚ
debug_inforKZ__jinja_template__) r‰rŠrKr{r r¼r5r6r8r9r:)r:rKr@r{rOr?r?r@r?Ùs
 
 
 
 
 
zTemplate._from_namespace©r;r©r<cOs°|jjrhddl}d}z | ¡}Wn tk
r@| ¡}d}YnXz| |j||Ž¡W¢S|rf| ¡X|     t
||Ž¡}z|j  |  |¡¡WSt k
rª|j ¡YnXdS)aThis method accepts the same arguments as the `dict` constructor:
        A dict, a dict subclass or some keyword arguments.  If no arguments
        are given the context will be empty.  These two calls do the same::
 
            template.render(knights='that say nih')
            template.render({'knights': 'that say nih'})
 
        This will return the rendered template as a string.
        rNFT)rKr|ÚasyncioZget_running_loopÚ RuntimeErrorZnew_event_looprZrun_until_completeÚ render_asyncr(rHr+r6r¤r¿)r}r;r©rFrZloopÚctxr?r?r@Úrenderõs"
 
 
zTemplate.rendercÏsh|jjstdƒ‚| t||Ž¡}z$|j dd„| |¡2ƒIdH¡WStk
rb|j ¡YSXdS)a.This works similar to :meth:`render` but returns a coroutine
        that when awaited returns the entire rendered template string.  This
        requires the async feature to be enabled.
 
        Example usage::
 
            await template.render_async(knights='that say nih; asynchronously')
        ú8The environment was not created with async mode enabled.cÓsg|z3dHW}|‘q6Srwr?)rÚnr?r?r@r    )sz)Template.render_async.<locals>.<listcomp>N)    rKr|rGr(rHr+r6r¤r¿)r}r;r©rIr?r?r@rHs    ÿÿzTemplate.render_asyncÚTemplateStreamcOst|j||ŽƒS)z[Works exactly like :meth:`generate` but returns a
        :class:`TemplateStream`.
        )rMr )r}r;r©r?r?r@rÈ.szTemplate.streamc/sŒˆjjrBddl}tjtdœ‡‡‡fdd„ }| |ƒ¡EdHdSˆ tˆˆŽ¡}zˆ     |¡EdHWn t
k
r†ˆj  ¡VYnXdS)abFor very large templates it can be useful to not render the whole
        template at once but evaluate each statement after another and yield
        piece for piece.  This method basically does exactly that and returns
        a generator that yields one item after another as strings.
 
        It accepts the same arguments as :meth:`render`.
        rNr‘c“sdd„ˆjˆˆŽ2ƒIdHS)NcÓsg|z3dHW}|‘q6Srwr?©rr–r?r?r@r    @sz6Template.generate.<locals>.to_list.<locals>.<listcomp>)Úgenerate_asyncr?©r;r©r}r?r@Úto_list?sz"Template.generate.<locals>.to_list) rKr|rFrOr1rNÚrunr(rHr6r¤r¿)r}r;r©rFrQrIr?rPr@r 4szTemplate.generatecOsj|jjstdƒ‚| t||Ž¡}z$| |¡2z3dHW}|Vq,6Wn tk
rd|j ¡VYnXdS)zsAn async version of :meth:`generate`.  Works very similarly but
        returns an async iterator instead.
        rKN)rKr|rGr(rHr6r¤r¿)r}r;r©rIÚeventr?r?r@rOLsÿzTemplate.generate_async)Úvarsr=rˆr<cCst|j|j|j|||j|ƒS)a^Create a new :class:`Context` for this template.  The vars
        provided will be passed to the template.  Per default the globals
        are added to the context.  If shared is set to `True` the data
        is passed as is to the context without adding the globals.
 
        `locals` can be a dict of local variables for internal usage.
        )r(rKr r5r{)r}rTr=rˆr?r?r@r(_s ÿzTemplate.new_contextcCs| |||¡}t||ƒS)aJThis method works like the :attr:`module` attribute when called
        without arguments but it will evaluate the template on every call
        rather than caching it.  It's also possible to provide
        a dict which is then used as context.  The arguments are the same
        as for the :meth:`new_context` method.
        )r(r7©r}rTr=rˆrIr?r?r@Ú make_moduleps zTemplate.make_modulecÃs0| |||¡}t||dd„| |¡2ƒIdHƒS)zûAs template module creation can invoke template code for
        asynchronous executions this method must be used instead of the
        normal :meth:`make_module` one.  Likewise the module attribute
        becomes unavailable in async mode.
        cÓsg|z3dHW}|‘q6Srwr?rNr?r?r@r    Œsz.Template.make_module_async.<locals>.<listcomp>N)r(r7r6rUr?r?r@Úmake_module_asyncs ÿzTemplate.make_module_async)rIr<cs^|jjrtdƒ‚ˆdk    rDˆj|j ¡}|rD| ‡fdd„|Dƒ¡S|jdkrX| ¡|_|jS)aOIf a context is passed in, this means that the template was
        imported. Imported templates have access to the current
        template's globals by default, but they can only be accessed via
        the context during runtime.
 
        If there are new globals, we need to create a new module because
        the cached module is already rendered and will not have access
        to globals from the current context. This new module is not
        cached because the template can be imported elsewhere, and it
        should have access to only the current template's globals.
        z&Module is not available in async mode.Ncsi|]}|ˆj|“qSr?©r©rÚk©rIr?r@Ú
<dictcomp>£sz0Template._get_default_module.<locals>.<dictcomp>)rKr|rGÚ globals_keysr{ÚkeysrVr8©r}rIr^r?r[r@Ú_get_default_modules 
 
zTemplate._get_default_modulecƒsZˆdk    r:ˆj|j ¡}|r:| ‡fdd„|Dƒ¡IdHS|jdkrT| ¡IdH|_|jS)Ncsi|]}|ˆj|“qSr?rXrYr[r?r@r\±sz6Template._get_default_module_async.<locals>.<dictcomp>)r]r{r^rWr8r_r?r[r@Ú_get_default_module_asyncªs
z"Template._get_default_module_asyncr‘cCs| ¡S)a›The template as module.  This is used for imports in the
        template runtime but is also useful if one wants to access
        exported template variables from the Python layer:
 
        >>> t = Template('{% macro foo() %}42{% endmacro %}23')
        >>> str(t.module)
        '23'
        >>> t.module.foo() == u'42'
        True
 
        This attribute is not available if async mode is enabled.
        )r`r’r?r?r@Úmodule¸szTemplate.module)rÖr<cCs(t|jƒD]\}}||kr
|Sq
dS)zrReturn the source line number of a line number in the
        generated bytecode as they are not in sync.
        r)ÚreversedrD)r}rÖZ template_lineZ    code_liner?r?r@Úget_corresponding_linenoÈs
z!Template.get_corresponding_linenocCs|jdkrdS| ¡S)z?If this variable is `False` there is a newer version available.NT)r:r’r?r?r@rÑs
zTemplate.is_up_to_datecCs |jrdd„|j d¡DƒSgS)zThe debug info mapping.cSs g|]}ttt| d¡ƒƒ‘qS)ú=)ÚtupleÚmapr(ÚsplitrNr?r?r@r    Üsÿz'Template.debug_info.<locals>.<listcomp>ú&)r9rhr’r?r?r@rDØs
 
þzTemplate.debug_infocCs>|jdkrdt|ƒd›}n
t|jƒ}dt|ƒj›d|›dS©Nzmemory:r–ú<ú ú>)r ÚidÚreprrGr©r}r r?r?r@Ú__repr__ãs
 
zTemplate.__repr__)N)NFN)NFN)NFN)N)N)?rrr r!r6r4rOrQr#r2rNr'r"ÚDictr&r'r*r
r r rrrrrrrrrrr)r%r    rBr$rŠÚ classmethodrrrBr?rJrHrÈr Ú AsyncIteratorrOr+r(rVrWr.r`rar)rbr(rdrr1r,rDrqr?r?r?r@rBjsô
$ìë 1ûúû û"þ üû üû üû ÿþ      
c@s\eZdZdZd eeejeje    ddœdd„Z
e dœdd„Z e    dœd    d
„Z e    dœd d „ZdS)r7zÁRepresents an imported template.  All the exported names of the
    template are available as attributes on this object.  Additionally
    converting it into a string renders the contents.
    N)rÝrªÚ body_streamr<cCsH|dkr&|jjrtdƒ‚t| |¡ƒ}||_|j | ¡¡|j    |_
dS)NztAsync mode requires a body stream to be passed to a template module. Use the async methods of the API you are using.) rKr|rGÚlistr6Ú _body_streamrŒrZ get_exportedr r)r}rÝrªrur?r?r@r~ñsÿzTemplateModule.__init__r‘cCstt|jƒƒSrw)rr+rwr’r?r?r@Ú__html__szTemplateModule.__html__cCs
t|jƒSrw)r+rwr’r?r?r@Ú__str__szTemplateModule.__str__cCs>|jdkrdt|ƒd›}n
t|jƒ}dt|ƒj›d|›dSrj)rrnrorGrpr?r?r@rq s
 
zTemplateModule.__repr__)N)rrr r!rBr'rOr"r3rNr~rrxryrqr?r?r?r@r7ës    üû r7c@s@eZdZdZeeddœdd„Zejejej    ejdœdd„Z
dS)    rÒzÂThe :meth:`jinja2.Environment.compile_expression` method returns an
    instance of this object.  It encapsulates the expression-like access
    to the template with an expression it wraps.
    N)rÝrÓr<cCs||_||_dSrw)Ú    _templateÚ_undefined_to_none)r}rÝrÓr?r?r@r~szTemplateExpression.__init__rEcOsD|j t||Ž¡}t|j |¡ƒ|jd}|jr@t|tƒr@d}|S)NrS)    rzr(rHr,r6rTr{rMr))r}r;r©rªrr?r?r@Ú__call__s 
zTemplateExpression.__call__) rrr r!rBr
r~rOr'r"r|r?r?r?r@rÒsrÒc@s¦eZdZdZejeddœdd„Zdejeej    fej
eej
eddœdd    „Z dd
œd d „Z e ejed œdd„Zde dd œdd„Zdd
œdd„Zed
œdd„ZdS)rMaûA template stream works pretty much like an ordinary python generator
    but it can buffer multiple items to reduce the number of total iterations.
    Per default the output is unbuffered which means that for every unbuffered
    instruction in the template one string is yielded.
 
    If buffering is enabled with a buffer size of 5, five items are combined
    into a new string.  This is mainly useful if you are streaming
    big templates to a client via WSGI which flushes after each iteration.
    N)Úgenr<cCs||_| ¡dSrw)Ú_genÚdisable_buffering)r}r}r?r?r@r~1szTemplateStream.__init__Ústrict)ÚfpÚencodingÚerrorsr<csŒd}t|tƒr(ˆdkrd‰t|dƒ}d}zPˆdk    rH‡‡fdd„|Dƒ}n|}t|dƒrb| |¡n|D]}| |¡qfW5|r†| ¡XdS)    aDump the complete stream into a file or file-like object.
        Per default strings are written, if you want to encode
        before writing specify an `encoding`.
 
        Example usage::
 
            Template('Hello {{ name }}!').stream(name='foo').dump('hello.html')
        FNzutf-8réTc3s|]}| ˆˆ¡VqdSrw)ròrN©r‚rƒr?r@Ú    <genexpr>Msz&TemplateStream.dump.<locals>.<genexpr>Ú
writelines)rMrNrírrƒr†rñ)r}rr‚rƒrÚiterableÚitemr?r„r@Údump5s 
 
 
 zTemplateStream.dumpr‘cCstt|jƒ|_d|_dS)zDisable the output buffering.FN)rÚnextr~Ú_nextÚbufferedr’r?r?r@rZsz TemplateStream.disable_bufferingrCccsxg}d}|j}z,||kr8t|jƒ}||ƒ|r|d7}qWntk
rX|sTYdSYnXt|ƒV|dd…=d}qdS)Nrr)ÚappendrŠr~Ú StopIterationr+)r}rDÚbufZc_sizeÚpushÚcr?r?r@Ú_buffered_generator_s
 
 
z"TemplateStream._buffered_generatorécCs,|dkrtdƒ‚d|_tt| |¡ƒ|_dS)z<Enable buffering.  Buffer `size` items before yielding them.rzbuffer size too smallTN)Ú
ValueErrorrŒrrŠr’r‹)r}rDr?r?r@Úenable_bufferingrszTemplateStream.enable_bufferingcCs|Srwr?r’r?r?r@Ú__iter__zszTemplateStream.__iter__cCs| ¡Srw)r‹r’r?r?r@Ú__next__}szTemplateStream.__next__)Nr€)r“)rrr r!rOr*rNr~r%ÚIOr"r‰rr(r’r•r–r—r?r?r?r@rM&s
üû %rM)_r!rîr-rOrÚ collectionsrÚ    functoolsrrrÚtypesrZ
markupsaferrcr    Úcompilerr
r Údefaultsr r rrrrrrrrrrrrrrÚ
exceptionsrrrrr r“r"r#r$r%rÚr&Zruntimer'r(r)Úutilsr*r+r,r-r.r0r1Ú TYPE_CHECKINGZtyping_extensionsÚteZbccacher2rÉr3rýr4ÚTypeVarr5rQr'rAr(r"r2r,rrNrErJr$r%rrrUr`r6rBr7rÒrMrer?r?r?r@Ú<module>s¨                                                þ 
þ  ý c(]