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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
3

U'íc7îã@s dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZddlm
Z
ddlmZd	d
lmZd	dlmZd	dlmZd	d
lmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlmZd	dlm Z d	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%lm0Z0d	d&l1m2Z2d	d'l3m4Z4d	d(l3m5Z5d	d)l3m6Z6d	d*l7m8Z8d	d+l7m9Z9d	d,l7m:Z:d	d-l7m;Z;d	d.l7m<Z<d	d/l7m=Z=d	d0l7m>Z>ej?r|ddl@ZAd	d1lBmCZCd	d2lDmEZEd	d3lFmGZGejHd4d5d6ZIe	d7d8ejJeIejKeId9œd:d;„ƒZLeMejNejOejPejQeRfd<fd=œd>d?„ZSejNejOejNejOejPejQeRfd<fd@œdAdB„ZTd5ejUejVeRejJdCfejWeRdCfdDœdEdF„ZXd5d5dGœdHdI„ZYGdJd5„d5ƒZZGdKd<„d<ƒZ[GdLdM„dMƒZ\GdNdO„dOƒZ]GdPdQ„dQƒZ^e[eZ__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)Zboundé
)Úmaxsize)ÚclsÚargsÚreturncGs||Ž}d|_|S)aReturn 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)r7r8Úenv©r<ú4/tmp/pip-build-gk9425m9/Jinja2/jinja2/environment.pyÚget_spontaneous_environmentCs	r>ÚTemplate)Úsizer9cCs |dkrdS|dkriSt|ƒS)z*Return the cache class for the given size.rN)r.)r@r<r<r=Úcreate_cacheQs
rA)Úcacher9cCs&|dkrdSt|ƒtkriSt|jƒS)z(Create an empty copy of the given cache.N)ÚtypeÚdictr.Úcapacity)rBr<r<r=Ú
copy_cache^s
rFr1)ÚenvironmentÚ
extensionsr9cCsDi}x:|D]2}t|tƒr.tjtjdt|ƒƒ}||ƒ||j<q
W|S)zuLoad the extensions from the list and bind it to the environment.
    Returns a dict of instantiated extensions.
    r1)Ú
isinstanceÚstrÚtÚcastÚTyper,Ú
identifier)rGrHÚresultÚ	extensionr<r<r=Úload_extensionsks

rQ)rGr9cCsPt|jtƒstdƒ‚|j|jko,|jkns:tdƒ‚|jdksLtdƒ‚|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'.>rTrSrR)Ú
issubclassÚ	undefinedr(ÚAssertionErrorÚblock_start_stringÚvariable_start_stringÚcomment_start_stringÚnewline_sequence)rGr<r<r=Ú_environment_config_check}sr\c@sHeZdZUdZdZdZdZejddZ	e
Zejde
Zeje
ejdeeeeeeeeeeeefdedddddddfeeeeeeejeejeeedeejej eejd	feejeejej!d
ej"fej eej!ejegeffejde#eejded
œdd„Z$ej eejd	fddœ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'feeeeeeejeejeeeejej eejd	feejeejej!d
ej"fej eej!ejegeffejde#eejdddœdd„Z(e)e*dœdd„ƒZ+ej,d	dœdd„Z-ej"ej eej"fej ej"efdœdd „Z.ej"eej"d!œd"d#„Z/ej eefej"ejejej"ejej0eej"feje
eje1eej"d$œd%d&„Z2dieej"ejejej"ejej0eej"feje
eje1ej"d'œd(d)„Z3djeej"ejejej"ejej0eej"feje
eje1ej"d'œd*d+„Z4e5dkeejeejee6j7d,œd-d.„ƒZ8eejeejee6j7d,œd/d0„Z9dleejeejeej,ej:e#eefd,œd1d2„Z;dmeejeejeed,œd3d4„Z<dneejeejeejee=d5œd6d7„Z>doe6j7ejeejeeed8œd9d:„Z?eee@d;œd<d=„ZAeBjCdpej ee6j7fejeejed>ee@d?œd@dA„ƒZDeBjCdqej ee6j7fejeejedBeed?œdCdA„ƒZDe5drej ee6j7fejeejeeeej ee@fd?œdDdA„ƒZDdseedEdFœdGdH„ZEdtej eeFjGfejejHeejej!egefejeejej!egdfeddJœdKdL„ZIduejejHeejej!egefejJedMœdNdO„ZKdvejedPdQœdRdS„ZLeeedTœdUdV„ZMe5eejej0eej"fddWœdXdY„ƒZNe5dwej edfejeejej0eej"fddZœd[d\„ƒZOe5dxejPej edfejeejej0eej"fdd]œd^d_„ƒZQe5dyej edejJej edffejeejej0eej"fdd`œdadb„ƒZRdzej ee6j7fejej0eej"fejejdddcœddde„ZSejej0eej"fejTeej"fdfœdgdh„ZUdS){r4a¤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.
    FNr
r?Tizte.Literal['\n', '\r\n', '\r']r1.r2r0)rXÚblock_end_stringrYÚvariable_end_stringrZÚcomment_end_stringÚline_statement_prefixÚline_comment_prefixÚtrim_blocksÚ
lstrip_blocksr[Úkeep_trailing_newlinerHÚ	optimizedrVÚfinalizeÚ
autoescapeÚloaderÚ
cache_sizeÚauto_reloadÚbytecode_cacheÚenable_asynccCsÂ||_||_||_||_||_||_||_||_|	|_|
|_	||_
||_||_||_
||_||_tjƒ|_tjƒ|_tjƒ|_||_t|ƒ|_||_||_tjƒ|_t||
ƒ|_||_ t!|ƒdS)N)"rXr]rYr^rZr_r`rarbrcr[rdrVrerfrgrÚcopyÚfiltersrÚtestsrÚglobalsrhrArBrkrjrZpoliciesrQrHÚis_asyncr\)ÚselfrXr]rYr^rZr_r`rarbrcr[rdrHrerVrfrgrhrirjrkrlr<r<r=Ú__init__#s6%




zEnvironment.__init__)rPr9cCs|jjt||gƒƒdS)z\Adds an extension after the environment was created.

        .. versionadded:: 2.5
        N)rHÚupdaterQ)rrrPr<r<r=Ú
add_extensionoszEnvironment.add_extension)Ú
attributesr9cKs0x*|jƒD]\}}t||ƒs
t|||ƒq
WdS)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)rrrvÚkeyÚvaluer<r<r=Úextendvs
zEnvironment.extend)rXr]rYr^rZr_r`rarbrcrHrerVrfrgrhrirjrkr9cCsÜttƒƒ}|d=|d=|d=tj|jƒ}|jj|jƒd|_||_x(|j	ƒD]\}}|t
k	rLt|||ƒqLW|t
k	r€t|ƒ|_
nt|j
ƒ|_
i|_x&|jj	ƒD]\}}|j|ƒ|j|<qžW|t
k	rÔ|jjt||ƒƒt|ƒS)agCreate 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.
        rrrirHT)rDÚlocalsÚobjectÚ__new__Ú	__class__Ú__dict__rtÚ	overlayedÚ	linked_torwr/ryrArBrFrHÚbindrQr\)rrrXr]rYr^rZr_r`rarbrcrHrerVrfrgrhrirjrkr8Úrvrzr{r<r<r=Úoverlays$!
zEnvironment.overlay)r9cCst|ƒS)zThe lexer for this environment.)r!)rrr<r<r=Úlexer¹szEnvironment.lexercCstt|jjƒdd„dƒS)z)Iterates over the extensions by priority.cSs|jS)N)Úpriority)Úxr<r<r=Ú<lambda>Àsz-Environment.iter_extensions.<locals>.<lambda>)rz)ÚiterÚsortedrHÚvalues)rrr<r<r=Úiter_extensions¾szEnvironment.iter_extensions)ÚobjÚargumentr9cCs~y||Stttfk
rxt|tƒrjyt|ƒ}Wntk
rHYn"Xy
t||ƒStk
rhYnX|j||dSXdS)z:Get an item or attribute of an object but prefer the item.)rÚnameN)ÚAttributeErrorÚ	TypeErrorÚLookupErrorrIrJÚ	ExceptionÚgetattrrV)rrrrÚattrr<r<r=ÚgetitemÂs

zEnvironment.getitem)rÚ	attributer9cCsRy
t||ƒStk
rYnXy||Stttfk
rL|j||dSXdS)z‰Get an item or attribute of an object but prefer the attribute.
        Unlike :meth:`getitem` the attribute *must* be a string.
        )rr‘N)r–r’r“r”rV)rrrr™r<r<r=r–Õs
zEnvironment.getattr)r‘r{r8ÚkwargsÚcontextÚeval_ctxÚ	is_filterr9cCsP|r|j}d}	n
|j}d}	|j|ƒ}
|
dkrd|	›d|›d}t|tƒrˆy|jƒWn2tk
r†}z|›d|›d}WYdd}~XnXt|ƒ‚|f|dk	r |nf•}|dk	r²|ni}tj	|
ƒ}
|
tj
krð|dkrâtd|	›d	ƒ‚|jd
|ƒnV|
tjkr.|dkr |dk	r|j
}nt|ƒ}|jd
|ƒn|
tjkrF|jd
|ƒ|
||ŽS)NÚfilterÚtestzNo z named Ú.z (z-; did you forget to quote the callable name?)zAttempted to invoke a context z without context.r)rnroÚgetrIr(Ú_fail_with_undefined_errorr•rr)Zfrom_objr›ÚinsertZeval_contextrœr$rG)rrr‘r{r8ršr›rœrZenv_mapÚ	type_nameÚfuncÚmsgÚeZpass_argr<r<r=Ú_filter_test_commonâs>


"



zEnvironment._filter_test_common)r‘r{r8ršr›rœr9cCs|j||||||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¨)rrr‘r{r8ršr›rœr<r<r=Úcall_filterszEnvironment.call_filtercCs|j||||||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
        F)r¨)rrr‘r{r8ršr›rœr<r<r=Ú	call_test-szEnvironment.call_test)Úsourcer‘Úfilenamer9cCs4y|j|||ƒStk
r.|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)rrr«r‘r¬r<r<r=ÚparseFszEnvironment.parsecCst||||ƒjƒS)z8Internal parsing function used by `parse` and `compile`.)r%r¯)rrr«r‘r¬r<r<r=r­ZszEnvironment._parsecCs>t|ƒ}y|jj|||ƒStk
r8|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)rJr‡Z	tokeniterrr®)rrr«r‘r¬r<r<r=Úlex`s
zEnvironment.lexcst‡‡fdd„|jƒ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|j|ˆˆƒS)N)Ú
preprocess)Úsr§)r¬r‘r<r=rŠ€sz(Environment.preprocess.<locals>.<lambda>)rrŽrJ)rrr«r‘r¬r<)r¬r‘r=r±us
zEnvironment.preprocess)r«r‘r¬Ústater9cCsV|j|||ƒ}|jj||||ƒ}x0|jƒD]$}|j|ƒ}t|tƒs*t|||ƒ}q*W|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_streamrIr#)rrr«r‘r¬r³ÚstreamÚextr<r<r=Ú	_tokenize…s


zEnvironment._tokenize)r«r‘r¬Ú
defer_initr9cCst||||||jdS)z|Internal hook that can be overridden to hook a different generate
        method in.

        .. versionadded:: 2.5
        )r¸re)rre)rrr«r‘r¬r¸r<r<r=Ú	_generatešszEnvironment._generate)r«r¬r9cCst||dƒS)z{Internal hook that can be overridden to hook a different compile
        method in.

        .. versionadded:: 2.5
        Úexec)Úcompile)rrr«r¬r<r<r=Ú_compile¯szEnvironment._compilezte.Literal[False])r«r‘r¬Úrawr¸r9cCsdS)Nr<)rrr«r‘r¬r½r¸r<r<r=r»·s	zEnvironment.compilezte.Literal[True]cCsdS)Nr<)rrr«r‘r¬r½r¸r<r<r=r»Âs	cCsxd}yNt|tƒr"|}|j|||ƒ}|j||||d}|r<|S|dkrHd}|j||ƒStk
rr|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«)rIrJr­r¹r¼rr®)rrr«r‘r¬r½r¸Zsource_hintr<r<r=r»Ís
ÚTemplateExpression)r«Úundefined_to_noner9c
Csšt||dd}y2|jƒ}|jjs4td|jjjddƒ‚|j|ƒWn tk
r`|j|dYnXt	j
t	jddƒ|dd	g}|j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 expressionN)r«rOÚstorer)Úlineno)r%Zparse_expressionrµZeosrÚcurrentrÂZset_environmentr®r	ÚAssignÚNameÚfrom_stringr?r¾)rrr«r¿ÚparserÚexprÚbodyÚtemplater<r<r=Úcompile_expression÷szEnvironment.compile_expressionÚdeflated)ÚtargetrHÚfilter_funcÚzipÚlog_functionÚ
ignore_errorsr9cs˜ddlm}|dkr$tddœdd„}|dk	s0t‚|jdk	sBtdƒ‚ttddœ‡‡‡‡fd	d
„}ˆdk	r¦ddlm}	m‰m}
m	}|	ˆd
t
|
|dˆƒ‰|dˆ›ƒn$tjj
ˆƒs¼tjˆƒ|dˆ›ƒz°xª|j||ƒD]š}|jj||ƒ\}
}}y|j|
||ddƒ}WnBtk
rJ}z$|s$‚|d|›d|›ƒwÚWYdd}~XnX|j|ƒ}|||ƒ|d|›d|›ƒqÚWWdˆrŠˆjƒ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‰r9cSsdS)Nr<)r‰r<r<r=rÐBsz3Environment.compile_templates.<locals>.log_functionzNo loader configured.)r¬Údatar9c
sTˆr ˆ|ƒ}d|_ˆj||ƒn0ttjjˆ|ƒdƒ}|j|jdƒƒWdQRXdS)NiíéÚwbÚutf8ií)Ú
external_attrÚwritestrÚopenÚosÚpathÚjoinÚwriteÚencode)r¬rÓÚinfoÚf)ÚZipInforÍrÏÚzip_filer<r=Ú
write_fileHs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ÒrJrWrhÚzipfilerärárårærDrÚrÛÚisdirÚmakedirsÚlist_templatesÚ
get_sourcer»rZget_module_filenameÚclose)rrrÍrHrÎrÏrÐrÑrÒrãrärårær‘r«r¬Ú_Úcoder§r<)rárÍrÏrâr=Úcompile_templates$s<	



zEnvironment.compile_templates)rHrÎr9csf|jdk	stdƒ‚|jjƒ}ˆ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
        NzNo loader configured.z<either extensions or filter_func can be passed, but not both)r‰r9csd|ko|jddƒdˆkS)Nr r)Úrsplit)r‰)rHr<r=rΏsz/Environment.list_templates.<locals>.filter_funccsg|]}ˆ|ƒr|‘qSr<r<)Ú.0r‘)rÎr<r=ú
<listcomp>“sz.Environment.list_templates.<locals>.<listcomp>)rhrWrìr“rJÚbool)rrrHrÎÚnamesr<)rHrÎr=rìrs
zEnvironment.list_templateszte.NoReturn)r«r9cCsddlm}||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_stack)r«N)Údebugr÷)rrr«r÷r<r<r=r®—szEnvironment.handle_exception)rÊÚparentr9cCs|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<)rrrÊrùr<r<r=Ú	join_pathŸs
zEnvironment.join_path)r‘rpr9cCs|jdkrtdƒ‚tj|jƒ|f}|jdk	rb|jj|ƒ}|dk	rb|jsN|jrb|r^|jj	|ƒ|S|jj
|||j|ƒƒ}|jdk	rŒ||j|<|S)Nz(no loader for this environment specified)rhr“ÚweakrefÚrefrBr¡rjÚ
is_up_to_daterprtÚloadÚmake_globals)rrr‘rpÚ	cache_keyrÊr<r<r=Ú_load_template«s



zEnvironment._load_template)r‘rùrpr9cCs.t|tƒr|S|dk	r"|j||ƒ}|j||ƒS)aÐLoad 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.
        :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)rIr?rúr)rrr‘rùrpr<r<r=Úget_templateÄs

zEnvironment.get_template)rörùrpr9c
Cs‚t|tƒr|jƒ|s tdd‚xT|D]L}t|tƒr8|S|dk	rL|j||ƒ}y|j||ƒSttfk
rpYq&Xq&Wt|ƒ‚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)	rIr(r¢rr?rúrrr )rrrörùrpr‘r<r<r=Úselect_templateçs#



zEnvironment.select_template)Útemplate_name_or_listrùrpr9cCs8t|ttfƒr|j|||ƒSt|tƒr*|S|j|||ƒ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
        )rIrJr(rr?r)rrrrùrpr<r<r=Úget_or_select_templates

z"Environment.get_or_select_template)r«rpÚtemplate_classr9cCs*|j|ƒ}|p|j}|j||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)rÿrÚ	from_coder»)rrr«rprZgsr7r<r<r=rÆ1s

zEnvironment.from_string)Údr9cCs|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)rrp)rrr	r<r<r=rÿFszEnvironment.make_globals)NNNN)NNNN)NN)NN)NN)NN)F)NNFF)NN.F)NNFF)T)NNrÌNT)NN)N)NN)NN)NN)NN)VÚ__name__Ú
__module__Ú__qualname__Ú__doc__Z	sandboxedr‚rƒrKÚOptionalr:r
Zcode_generator_classrMr&Z
context_classrr
rrrrrrrrrrrr(rJrõÚSequenceÚUnionÚCallableÚAnyÚintrsrur|r/r†Úpropertyr"r‡ÚIteratorrŽr˜r–ÚMappingr$r¨r©rªr-r	r?r¯r­ÚTupler°r±r#r·r¹rr¼ÚtypingZoverloadr»rËrÚÚPathLikeÚ
CollectionrñÚListrìr®rúrrÚIterablerrrÆÚMutableMappingrÿr<r<r<r=r4s"
x
ž5 Œ%1<< $$$#.PH$!*00<2c@s¶eZdZUdZeZejeeej	e
ejfej
e
ej
e
eje
ejegeje
ffejegeje
fej
de
ej
ejgefeeeeeee e!e"e#e$e%fde&dddfej'e
e(j)fe
e
e
e
e
e
ej
e
ej
e
eedeej*ej'e
ejdfeeje&ej
ejdejfej'eejej
e
geffeejd	œd
d„Z+e,d9ee-ej	e
ejfej
ejgefddœd
d„ƒZ.e,eej	e
ejfej	e
ejfddœdd„ƒZ/e,eej	e
ejfej	e
ejfddœdd„ƒZ0ejeje
dœdd„Z1ejeje
dœdd„Z2ejejddœdd„Z3ejejeje
dœdd„Z4ejejej5e
dœdd „Z6d:ej
eje
ejfeej
ej7e
ejfed!œd"d#„Z8d;ej
eje
ejfeej
ej7e
ejfdd!œd$d%„Z9d<ej
eje
ejfeej
ej7e
ejfdd!œd&d'„Z:e;d=ej
edd(œd)d*„ƒZ<d>ej
edd(œd+d,„Z=e>dd-œd.d/„ƒZ?e@e@d0œd1d2„ZAe>ed-œd3d4„ƒZBe>ejCejDe@e@fd-œd5d6„ƒZEe
d-œd7d8„ZFdS)?r?aoA 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.
    ÚTemplateModuleTNFzte.Literal['\n', '\r\n', '\r']r1.)r«rXr]rYr^rZr_r`rarbrcr[rdrHrerVrfrgrlr9cCsHt|j||||||||	|
|||
t|ƒ||||dddd|ƒ}|j||dS)NrF)r)r>Úenvironment_classÚ	frozensetrÆ)r7r«rXr]rYr^rZr_r`rarbrcr[rdrHrerVrfrgrlr;r<r<r=r|s2zTemplate.__new__)rGrðrpÚuptodater9cCs.||jdœ}t||ƒ|j|||ƒ}||_|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.
        )rGÚ__file__)Úco_filenamerºÚ_from_namespaceÚ	_uptodate)r7rGrðrpr!Ú	namespacer…r<r<r=r­s

zTemplate.from_code)rGÚmodule_dictrpr9cCs|j|||ƒ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$)r7rGr'rpr<r<r=Úfrom_module_dict¾szTemplate.from_module_dict)rGr&rpr9cCshtj|ƒ}||_||_|d|_|d|_|d|_|d|_d|_|d|_	d|_
||d<||d<|S)Nr‘r"ÚblocksÚrootÚ
debug_inforGZ__jinja_template__)r~rrGrpr‘r¬r)Úroot_render_funcÚ_moduleÚ_debug_infor%)r7rGr&rprKr<r<r=r$Ìs





zTemplate._from_namespace)r8ršr9cOsº|jjrxddl}d}tjdkr(|jƒ}n.y|jƒ}Wn tk
rT|jƒ}d}YnXz|j	|j
||ŽƒS|rv|jƒX|jt
||Žƒ}yt|j|ƒƒStk
r´|jjƒ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.
        rNFééT)r/r0)rGrqÚasyncioÚsysÚversion_infoÚget_event_loopZget_running_loopÚRuntimeErrorZnew_event_loopÚrun_until_completeÚrender_asyncrîr'rDr*r,r•r®)rrr8ršr1rîÚloopÚctxr<r<r=Úrenderès&




zTemplate.rendercÏsb|jjstdƒ‚|jt||Žƒ}y"tdd„|j|ƒ2dHƒIdHƒStk
r\|jjƒSXdS)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')
        z8The environment was not created with async mode enabled.c
Ós.g|y3dH}Wn
tk
s"X|‘qYS)N)ÚStopAsyncIteration)róÚnr<r<r=rôsz)Template.render_async.<locals>.<listcomp>N)	rGrqr5r'rDr*r,r•r®)rrr8ršr9r<r<r=r7
s	"zTemplate.render_asyncÚTemplateStreamcOst|j||ŽƒS)z[Works exactly like :meth:`generate` but returns a
        :class:`TemplateStream`.
        )r=r)rrr8ršr<r<r=rµ"szTemplate.streamc/s°ˆjjrfddl}tjtdœ‡‡‡fdd„}tjdkrL|jƒ}|j	|ƒƒ}n|j
|ƒƒ}|EdHdSˆjtˆˆŽƒ}yˆj
|ƒEdHWn tk
rªˆjjƒ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`.
        rN)r9c“s dd„ˆjˆˆŽ2dHƒIdHS)Nc
Ós.g|y3dH}Wn
tk
s"X|‘qYS)N)r;)rór‰r<r<r=rô4sz6Template.generate.<locals>.to_list.<locals>.<listcomp>)Úgenerate_asyncr<)r8ršrrr<r=Úto_list3sz"Template.generate.<locals>.to_listr/r0)r/r0)rGrqr1rKrrJr2r3r4r6Úrunr'rDr,r•r®)rrr8ršr1r?r8Úoutr9r<)r8ršrrr=r(s

zTemplate.generatecOs†|jjstdƒ‚|jt||Žƒ}y@x:|j|ƒ2dHy3dH}Wn
tk
sRX|Vq2YWWn tk
r€|jjƒVYnXdS)zsAn async version of :meth:`generate`.  Works very similarly but
        returns an async iterator instead.
        z8The environment was not created with async mode enabled.N)	rGrqr5r'rDr,r;r•r®)rrr8ršr9Úeventr<r<r=r>Fs(zTemplate.generate_async)Úvarsr:r}r9cCst|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'rGr‘r)rp)rrrCr:r}r<r<r=r'Ys
zTemplate.new_contextcCs|j|||ƒ}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'r)rrrCr:r}r9r<r<r=Úmake_modulejszTemplate.make_modulecÃs4|j|||ƒ}t||dd„|j|ƒ2dHƒ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
Ós.g|y3dH}Wn
tk
s"X|‘qYS)N)r;)rór‰r<r<r=rô†sz.Template.make_module_async.<locals>.<listcomp>N)r'rr,)rrrCr:r}r9r<r<r=Úmake_module_asyncyszTemplate.make_module_async)r9r9cs^|jjrtdƒ‚ˆdk	rDˆj|jjƒ}|rD|j‡fdd„|DƒƒS|jdkrX|jƒ|_|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)r9r<r=ú
<dictcomp>sz0Template._get_default_module.<locals>.<dictcomp>)rGrqr5Úglobals_keysrpÚkeysrDr-)rrr9rIr<)r9r=Ú_get_default_module‰s


zTemplate._get_default_modulecƒsZˆdk	r:ˆj|jjƒ}|r:|j‡fdd„|DƒƒIdHS|jdkrT|jƒIdH|_|jS)Ncsi|]}ˆj||“qSr<)rù)rórF)r9r<r=rG«sz6Template._get_default_module_async.<locals>.<dictcomp>)rHrprIrEr-)rrr9rIr<)r9r=Ú_get_default_module_async¤s
z"Template._get_default_module_async)r9cCs|jƒ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.
        )rJ)rrr<r<r=Úmodule²szTemplate.module)rÂr9cCs(x"t|jƒD]\}}||kr|SqWdS)zrReturn the source line number of a line number in the
        generated bytecode as they are not in sync.
        r)Úreversedr+)rrrÂZ
template_lineZ	code_liner<r<r=Úget_corresponding_linenoÂsz!Template.get_corresponding_linenocCs|jdkrdS|jƒS)z?If this variable is `False` there is a newer version available.NT)r%)rrr<r<r=rýËs
zTemplate.is_up_to_datecCs |jrdd„|jjdƒDƒSgS)zThe debug info mapping.cSs g|]}ttt|jdƒƒƒ‘qS)ú=)ÚtupleÚmaprÚsplit)rór‰r<r<r=rô×sz'Template.debug_info.<locals>.<listcomp>ú&)r.rR)rrr<r<r=r+ÒszTemplate.debug_infocCs>|jdkrdt|ƒd›}n
t|jƒ}dt|ƒj›d|›dS)Nzmemory:r‰ú<ú ú>)r‘ÚidÚreprrCr
)rrr‘r<r<r=Ú__repr__Ýs

zTemplate.__repr__)N)NFN)NFN)NFN)N)N)Gr
rrr
r4rrKrMrGrrJrrprr‘r¬ÚDictrr&rr)r,r-r.rõr%r
rrrrrrrrrrrr(rr	r?rrÚclassmethodrrr(r$r:r7rµrÚ
AsyncIteratorr>rr'rDrEr-rJrKrrLrrNrýrrr+rYr<r<r<r=r?]s’


 
Œ&
%,,,
	 
c@s\eZdZdZd
eeejeje	ddœdd„Z
edœdd„Ze	dœd	d
„Z
e	dœdd„ZdS)rzÁ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_streamr9cCsH|dkr&|jjrtdƒ‚t|j|ƒƒ}||_|jj|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.)rGrqr5Úlistr,Ú_body_streamrrtZget_exportedr‘r
)rrrÊr›r]r<r<r=rsëszTemplateModule.__init__)r9cCstt|jƒƒS)N)rr*r_)rrr<r<r=Ú__html__ÿszTemplateModule.__html__cCs
t|jƒS)N)r*r_)rrr<r<r=Ú__str__szTemplateModule.__str__cCs>|jdkrdt|ƒd›}n
t|jƒ}dt|ƒj›d|›dS)Nzmemory:r‰rTrUrV)r
rWrXrC)rrr‘r<r<r=rYs

zTemplateModule.__repr__)N)r
rrr
r?r&rKrrrJrsrr`rarYr<r<r<r=råsrc@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¿r9cCs||_||_dS)N)Ú	_templateÚ_undefined_to_none)rrrÊr¿r<r<r=rsszTemplateExpression.__init__)r8ršr9cOsD|jjt||Žƒ}t|jj|ƒƒ|jd}|jr@t|tƒr@d}|S)NrO)	rbr'rDr+r,rCrcrIr()rrr8ršr›r…r<r<r=Ú__call__s
zTemplateExpression.__call__)r
rrr
r?rõrsrKrrrdr<r<r<r=r¾
sr¾c@s¦eZdZdZejeddœdd„Zdejeej	fej
eej
eddœdd	„Zdd
œdd„Ze
ejed
œdd„Zde
dd
œdd„Zdd
œdd„Zed
œdd„ZdS)r=aû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)Úgenr9cCs||_|jƒdS)N)Ú_genÚdisable_buffering)rrrer<r<r=rs+szTemplateStream.__init__Ústrict)ÚfpÚencodingÚerrorsr9c
sd}t|tƒr(ˆdkrd‰t|dƒ}d}zTˆdk	rH‡‡fdd„|Dƒ}n|}t|dƒrb|j|ƒnx|D]}|j|ƒqhWWd|rŠ|jƒ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|]}|jˆˆƒVqdS)N)rÞ)rór‰)rjrkr<r=ú	<genexpr>Gsz&TemplateStream.dump.<locals>.<genexpr>Ú
writelines)rIrJrÙrxrmrÝrî)rrrirjrkrîÚiterableÚitemr<)rjrkr=Údump/s 



zTemplateStream.dump)r9cCstt|jƒ|_d|_dS)zDisable the output buffering.FN)rÚnextrfÚ_nextÚbuffered)rrr<r<r=rgTsz TemplateStream.disable_buffering)r@r9ccs~g}d}|j}xjy0x*||kr<t|jƒ}||ƒ|r|d7}qWWntk
r\|sXdSYnXt|ƒV|dd…=d}qWdS)Nrr)ÚappendrqrfÚ
StopIterationr*)rrr@ÚbufZc_sizeÚpushÚcr<r<r=Ú_buffered_generatorYs 




z"TemplateStream._buffered_generatorécCs,|dkrtdƒ‚d|_tt|j|ƒƒ|_dS)z<Enable buffering.  Buffer `size` items before yielding them.rzbuffer size too smallTN)Ú
ValueErrorrsrrqryrr)rrr@r<r<r=Úenable_bufferinglszTemplateStream.enable_bufferingcCs|S)Nr<)rrr<r<r=Ú__iter__tszTemplateStream.__iter__cCs|jƒS)N)rr)rrr<r<r=Ú__next__wszTemplateStream.__next__)Nrh)rz)r
rrr
rKrrJrsrZIOrrprgrryr|r}r~r<r<r<r=r= s	  r=)`r
rÚr2rrKrûÚcollectionsrÚ	functoolsrrrÚtypesrZ
markupsaferÚr	Úcompilerr
rÚdefaultsrr
rrrrrrrrrrrrrrÚ
exceptionsrrrrr r‡r!r"r#r$rÇr%Zruntimer&r'r(Úutilsr)r*r+r,r-r.r/Z
TYPE_CHECKINGZtyping_extensionsÚteZbccacher0r¶r1rèr2ZTypeVarr3rMrr>rrrrrürJrArFrrrZrQr\r4r?rr¾r=rr<r<r<r=Ú<module>s¤*
*U(]