o
    1)hr                     @   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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)GeneratorType   )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t| tr't|| } ddd | D }z	tt	|dd	W S  t
ttfyH   | 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   QC:\Users\User\Downloads\Proyecto_IoT\venv\Lib\site-packages\jinja2/nativetypes.py
<listcomp>%       z!native_concat.<locals>.<listcomp>eval)mode)listr   len
isinstancer   r   r   joinr   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_finalize7   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   <   r   z:NativeCodeGenerator._output_const_repr.<locals>.<listcomp>)reprr!   )selfr,   r   r   r   _output_const_repr;   s   z&NativeCodeGenerator._output_const_reprnodeframefinalizec                 C   s6   | |j}t|st t|tjr|S ||S r*   )Zas_constZeval_ctxr   r   Z
Impossibler    ZTemplateDataconst)r.   r0   r1   r2   r3   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.   r0   r1   r2   r   r   r   _output_child_preK   s   
z%NativeCodeGenerator._output_child_prec                 C   s   |j d ur| d d S d S )N)r5   r8   r   r   r   _output_child_postQ   s   
z&NativeCodeGenerator._output_child_post)__name__
__module____qualname____doc__staticmethodtAnyr+   Iterabler   r/   r   Exprr
   r	   Z_FinalizeInfor4   r9   r;   r   r   r   r   r(   2   s@    

r(   c                   @   s   e Zd ZdZeZeeZdS )NativeEnvironmentz=An environment that renders templates to native Python types.N)	r<   r=   r>   r?   r(   Zcode_generator_classr@   r'   concatr   r   r   r   rE   X   s    rE   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   sF   |  t|i |}z
| j| |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dictenvironment_classrF   root_render_func	Exceptionenvironmenthandle_exceptionr.   rH   rI   ctxr   r   r   renderb   s   zNativeTemplate.renderc                    sh   | j js	td| t|i |}z| jdd | |2 I d H W S  ty3   | 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   |   s    z/NativeTemplate.render_async.<locals>.<listcomp>)
rO   is_asyncRuntimeErrorrJ   rK   rL   rF   rM   rN   rP   rQ   r   r   r   render_asyncr   s   zNativeTemplate.render_asyncN)	r<   r=   r>   rE   rL   rA   rB   rS   rW   r   r   r   r   rG   _   s     rG   )typingrA   astr   r   	itertoolsr   r   typesr   r   r   compilerr	   r
   r   rO   r   r   rC   rB   Optionalr'   r(   rE   rG   Ztemplate_classr   r   r   r   <module>   s"    ""&
#