zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
U
Þ=®d‚ã@sæddlZddlmZddlmZddlmZddlmZddlm    Z    ddl
m Z dd    l m Z dd
l mZdd l mZdd lmZdd lmZejejejejdœdd„ZGdd„de ƒZGdd„deƒZGdd„deƒZee_dS)éN)Ú literal_eval)Úparse)Úchain)Úislice)Ú GeneratorTypeé)Únodes)Ú CodeGenerator)ÚFrame)Ú has_safe_repr)Ú Environment)ÚTemplate)ÚvaluesÚreturnc
Cs˜tt|dƒƒ}|sdSt|ƒdkr:|d}t|tƒsb|Sn(t|tƒrNt||ƒ}d dd„|Dƒ¡}ztt    |dd    ƒWSt
t t fk
r’|YSXdS)
anReturn a native Python type from the list of compiled nodes. If
    the result is a single node, its value is returned. Otherwise, the
    nodes are concatenated as strings. If the result can be parsed with
    :func:`ast.literal_eval`, the parsed value is returned. Otherwise,
    the string is returned.
 
    :param values: Iterable of outputs to concatenate.
    éNrrÚcSsg|] }t|ƒ‘qS©©Ústr©Ú.0ÚvrrúId:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\jinja2/nativetypes.pyÚ
<listcomp>%sz!native_concat.<locals>.<listcomp>Úeval)Úmode) ÚlistrÚlenÚ
isinstancerrrÚjoinrrÚ
ValueErrorÚ SyntaxErrorÚ MemoryError)rÚheadÚrawrrrÚ native_concats      
 
 
 
ür%c@sŠeZdZdZeejejdœdd„ƒZejeje    dœdd„Z
e j e ejejdœd    d
„Ze j e ejd dœd d „Ze j e ejd dœdd„Zd S)ÚNativeCodeGeneratorzaA code generator which renders Python types by not adding
    ``str()`` around output nodes.
    )ÚvaluercCs|S©Nr)r'rrrÚ_default_finalize7sz%NativeCodeGenerator._default_finalize)ÚgrouprcCstd dd„|Dƒ¡ƒS)NrcSsg|] }t|ƒ‘qSrrrrrrr<sz:NativeCodeGenerator._output_const_repr.<locals>.<listcomp>)Úreprr)Úselfr*rrrÚ_output_const_repr;sz&NativeCodeGenerator._output_const_repr)ÚnodeÚframeÚfinalizercCs6| |j¡}t|ƒst ¡‚t|tjƒr,|S| |¡Sr()Zas_constZeval_ctxr rZ
ImpossiblerZ TemplateDataÚconst)r,r.r/r0r1rrrÚ_output_child_to_const>s   z*NativeCodeGenerator._output_child_to_constNcCs|jdk    r| |j¡dSr(©ÚsrcÚwrite©r,r.r/r0rrrÚ_output_child_preKs
z%NativeCodeGenerator._output_child_precCs|jdk    r| d¡dS)Nú)r3r6rrrÚ_output_child_postQs
z&NativeCodeGenerator._output_child_post)Ú__name__Ú
__module__Ú __qualname__Ú__doc__Ú staticmethodÚtÚAnyr)ÚIterablerr-rZExprr
r    Z _FinalizeInfor2r7r9rrrrr&2s&þ þ þr&c@seZdZdZeZeeƒZdS)ÚNativeEnvironmentz=An environment that renders templates to native Python types.N)    r:r;r<r=r&Zcode_generator_classr>r%ÚconcatrrrrrBXsrBc@s@eZdZeZejejejdœdd„Zejejejdœdd„ZdS)ÚNativeTemplate)ÚargsÚkwargsrcOsH| t||Ž¡}z|j | |¡¡WStk
rB|j ¡YSXdS)aBRender the template to produce a native Python type. If the
        result is a single node, its value is returned. Otherwise, the
        nodes are concatenated as strings. If the result can be parsed
        with :func:`ast.literal_eval`, the parsed value is returned.
        Otherwise, the string is returned.
        N)Ú new_contextÚdictÚenvironment_classrCÚroot_render_funcÚ    ExceptionÚ environmentÚhandle_exception©r,rErFÚctxrrrÚrenderbsÿzNativeTemplate.rendercÏsh|jjstdƒ‚| t||Ž¡}z$|j dd„| |¡2ƒIdH¡WStk
rb|j     ¡YSXdS)Nz8The environment was not created with async mode enabled.cÓsg|z3dHW}|‘q6Sr(r)rÚnrrrr|sz/NativeTemplate.render_async.<locals>.<listcomp>)
rLZis_asyncÚ RuntimeErrorrGrHrIrCrJrKrMrNrrrÚ render_asyncrsÿÿzNativeTemplate.render_asyncN)    r:r;r<rBrIr?r@rPrSrrrrrD_srD)Útypingr?ÚastrrÚ    itertoolsrrÚtypesrrrÚcompilerr    r
r rLr r rAr@ÚOptionalr%r&rBrDZtemplate_classrrrrÚ<module>s             "&#