U a[@sddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z dd l m Z dd l mZdd l mZejejejejd d dZGddde ZGdddeZGdddeZee_dS)N) literal_eval)chain)islice)nodes) CodeGenerator)Frame) has_safe_repr) Environment)Template)valuesreturnc Cstt|d}|sdSt|dkr:|d}t|tsT|Sndddt||D}z t|WStt 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. NrrcSsg|] }t|qSstr.0vrrSC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-8gbwd15f\jinja2\nativetypes.py !sz!native_concat..) listrlen isinstancerjoinrr ValueError SyntaxError MemoryError)r headrawrrr native_concats    r!c@seZdZdZeejejdddZejeje dddZ e j e ejejdd d Ze j e ejd dd d Ze j e ejd dddZd S)NativeCodeGeneratorzaA code generator which renders Python types by not adding ``str()`` around output nodes. )valuer cCs|SNr)r#rrr_default_finalize.sz%NativeCodeGenerator._default_finalize)groupr cCstddd|DS)NrcSsg|] }t|qSrrrrrrr3sz:NativeCodeGenerator._output_const_repr..)reprr)selfr&rrr_output_const_repr2sz&NativeCodeGenerator._output_const_repr)nodeframefinalizer cCs6||j}t|stt|tjr,|S||Sr$)Zas_constZeval_ctxr rZ ImpossiblerZ TemplateDataconst)r(r*r+r,r-rrr_output_child_to_const5s   z*NativeCodeGenerator._output_child_to_constNcCs|jdk r||jdSr$srcwriter(r*r+r,rrr_output_child_preBs z%NativeCodeGenerator._output_child_precCs|jdk r|ddS)N)r/r2rrr_output_child_postHs z&NativeCodeGenerator._output_child_post)__name__ __module__ __qualname____doc__ staticmethodtAnyr%Iterablerr)rZExprrrZ _FinalizeInfor.r3r5rrrrr")s&  r"c@seZdZdZeZdS)NativeEnvironmentz=An environment that renders templates to native Python types.N)r6r7r8r9r"Zcode_generator_classrrrrr>Osr>c@s@eZdZeZejejejdddZejejejdddZdS)NativeTemplate)argskwargsr cOsD|t||}zt||WStk r>|jYSXdS)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_contextdictr!root_render_func Exception environmenthandle_exceptionr(r@rActxrrrrenderXs zNativeTemplate.rendercsd|jjstd|t||}z tdd||2IdHWStk r^|jYSXdS)Nz8The environment was not created with async mode enabled.csg|z3dHW}|q6Sr$r)rnrrrrpsz/NativeTemplate.render_async..) rFZis_async RuntimeErrorrBrCr!rDrErGrHrrr render_asyncfszNativeTemplate.render_asyncN) r6r7r8r>Zenvironment_classr;r<rJrMrrrrr?Usr?)typingr;astr itertoolsrrrrcompilerrrr rFr r r=r<Optionalr!r"r>r?Ztemplate_classrrrrs          &!