o
    4c[                     @   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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)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|W S  tt	t
fy=   | 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   H/var/www/html/gps/gps/lib/python3.10/site-packages/jinja2/nativetypes.py
<listcomp>!       z!native_concat.<locals>.<listcomp>)listr   len
isinstancer   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_finalize.   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   3   r   z:NativeCodeGenerator._output_const_repr.<locals>.<listcomp>)reprr   )selfr(   r   r   r   _output_const_repr2   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,   r-   r.   r3   r   r   r   _output_child_to_const5   s   
z*NativeCodeGenerator._output_child_to_constNc                 C   s   |j d ur| |j  d S d S r&   srcwriter*   r,   r-   r.   r   r   r   _output_child_preB   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_postH   s   
z&NativeCodeGenerator._output_child_post)__name__
__module____qualname____doc__staticmethodtAnyr'   Iterabler   r+   r   Exprr   r   _FinalizeInfor4   r9   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=   r>   r?   r$   code_generator_classr   r   r   r   rF   O   s    rF   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*   rI   rJ   ctxr   r   r   renderX   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   p   s    z/NativeTemplate.render_async.<locals>.<listcomp>)	rO   is_asyncRuntimeErrorrK   rL   r#   rM   rN   rP   rQ   r   r   r   render_asyncf   s   zNativeTemplate.render_asyncN)	r<   r=   r>   rF   environment_classrA   rB   rS   rW   r   r   r   r   rH   U   s     rH   )typingrA   astr   	itertoolsr   r   r   r   compilerr   r   r	   rO   r
   r   rC   rB   Optionalr#   r$   rF   rH   template_classr   r   r   r   <module>   s    "&
!