o
    F­Ša�  ã                   @   sÜ   d dl 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l
mZ dd	l
mZ dd
l
mZ ddlmZ ddlmZ dejej dejej fdd„ZG dd„ deƒZG dd„ deƒZG dd„ deƒZee_dS )é    N)Úliteral_eval)Úparse)Úchain)Úisliceé   )Únodes)ÚCodeGenerator)ÚFrame)Úhas_safe_repr)ÚEnvironment)ÚTemplateÚvaluesÚreturnc              
   C   s„   t t| dƒƒ}|sdS t|ƒdkr|d }t|tƒs|S nd dd„ t|| ƒD ƒ¡}z	tt|dd	�ƒW S  t	t
tfyA   | Y S w )
an  Return 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.
    é   Nr   r   Ú c                 S   ó   g | ]}t |ƒ‘qS © ©Ústr©Ú.0Úvr   r   ú4/usr/lib/python3/dist-packages/jinja2/nativetypes.pyÚ
<listcomp>"   ó    z!native_concat.<locals>.<listcomp>Úeval)Úmode)Úlistr   ÚlenÚ
isinstancer   Újoinr   r   r   Ú
ValueErrorÚSyntaxErrorÚMemoryError)r   ÚheadÚrawr   r   r   Únative_concat   s    	
ÿ
üÿr&   c                   @   s    e Zd ZdZedejdejfdd„ƒZdejej de	fdd„Z
d	ejd
edejdejfdd„Zd	ejd
edejddfdd„Zd	ejd
edejddfdd„ZdS )ÚNativeCodeGeneratorzaA code generator which renders Python types by not adding
    ``str()`` around output nodes.
    Úvaluer   c                 C   s   | S ©Nr   )r(   r   r   r   Ú_default_finalize4   s   z%NativeCodeGenerator._default_finalizeÚgroupc                 C   s   t d dd„ |D ƒ¡ƒS )Nr   c                 S   r   r   r   r   r   r   r   r   9   r   z:NativeCodeGenerator._output_const_repr.<locals>.<listcomp>)Úreprr    )Úselfr+   r   r   r   Ú_output_const_repr8   s   z&NativeCodeGenerator._output_const_reprÚnodeÚframeÚfinalizec                 C   s6   |  |j¡}t|ƒst ¡ ‚t|tjƒr|S | |¡S r)   )Úas_constÚeval_ctxr
   r   Ú
Impossibler   ÚTemplateDataÚconst)r-   r/   r0   r1   r6   r   r   r   Ú_output_child_to_const;   s   
z*NativeCodeGenerator._output_child_to_constNc                 C   s   |j d ur|  |j ¡ d S d S r)   ©ÚsrcÚwrite©r-   r/   r0   r1   r   r   r   Ú_output_child_preH   s   
ÿz%NativeCodeGenerator._output_child_prec                 C   s   |j d ur|  d¡ d S d S )Nú)r8   r;   r   r   r   Ú_output_child_postN   s   
ÿz&NativeCodeGenerator._output_child_post)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstaticmethodÚtÚAnyr*   ÚIterabler   r.   r   ÚExprr	   r   Ú_FinalizeInfor7   r<   r>   r   r   r   r   r'   /   s@    ÿÿÿ
þÿÿÿ
þÿÿÿþr'   c                   @   s   e Zd ZdZeZdS )ÚNativeEnvironmentz=An environment that renders templates to native Python types.N)r?   r@   rA   rB   r'   Úcode_generator_classr   r   r   r   rI   U   s    rI   c                   @   sH   e Zd ZeZdejdejdejfdd„Zdejdejdejfdd„ZdS )	ÚNativeTemplateÚargsÚkwargsr   c                 O   sB   |   t|i |¤Ž¡}zt|  |¡ƒW S  ty    | j ¡  Y S w )aB  Render 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.
        )Únew_contextÚdictr&   Úroot_render_funcÚ	ExceptionÚenvironmentÚhandle_exception©r-   rL   rM   Úctxr   r   r   Úrender^   s   ÿzNativeTemplate.renderc                 Ï   sd   �| j js	tdƒ‚|  t|i |¤Ž¡}ztdd„ |  |¡2 ƒI d H ƒW S  ty1   | j  ¡  Y S w )Nz8The environment was not created with async mode enabled.c                 Ó   s   �g | z3 d H W }|‘q6 S r)   r   )r   Únr   r   r   r   v   s   € z/NativeTemplate.render_async.<locals>.<listcomp>)	rR   Úis_asyncÚRuntimeErrorrN   rO   r&   rP   rQ   rS   rT   r   r   r   Úrender_asyncl   s   €ÿÿÿzNativeTemplate.render_asyncN)	r?   r@   rA   rI   Úenvironment_classrD   rE   rV   rZ   r   r   r   r   rK   [   s     rK   )ÚtypingrD   Úastr   r   Ú	itertoolsr   r   r   r   Úcompilerr   r	   r
   rR   r   r   rF   rE   ÚOptionalr&   r'   rI   rK   Útemplate_classr   r   r   r   Ú<module>   s     " &
!