
    hr                     L   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Z G d de      Z G d de      Z G d de      Zee_        y)    N)literal_eval)parse)chain)islice)GeneratorType   )nodes)CodeGenerator)Frame)has_safe_repr)Environment)Templatevaluesreturnc                 t   t        t        | d            }|syt        |      dk(  r|d   }t        |t              sF|S t        | t
              rt        ||       } dj                  | D cg c]  }t	        |       c}      }	 t        t        |d            S c c}w # t        t        t        f$ r |cY S w xY 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    eval)mode)listr   len
isinstancestrr   r   joinr   r   
ValueErrorSyntaxErrorMemoryError)r   headrawvs       ;D:\EasyAligner\venv\Lib\site-packages\jinja2/nativetypes.pynative_concatr"      s     vq!"D
4yA~1g#s#Jfm,4(Fggv.v!s1vv./ #F#	
 	
 / [1 
s   )BB B76B7c                   d   e Zd ZdZedej                  dej                  fd       Zdej                  ej                     de	fdZ
dej                  ded	ej                  dej                  fd
Zdej                  ded	ej                  ddfdZdej                  ded	ej                  ddfdZy)NativeCodeGeneratorzaA code generator which renders Python types by not adding
    ``str()`` around output nodes.
    valuer   c                     | S N )r%   s    r!   _default_finalizez%NativeCodeGenerator._default_finalize7   s        groupc           
      n    t        dj                  |D cg c]  }t        |       c}            S c c}w )Nr   )reprr   r   )selfr+   r    s      r!   _output_const_reprz&NativeCodeGenerator._output_const_repr;   s,    BGGU3USVU34553s   2nodeframefinalizec                     |j                  |j                        }t        |      st        j                         t        |t        j                        r|S |j                  |      S r'   )as_consteval_ctxr   r	   
Impossibler   TemplateDataconst)r.   r0   r1   r2   r8   s        r!   _output_child_to_constz*NativeCodeGenerator._output_child_to_const>   sQ     enn-U#""$$dE../L~~e$$r*   Nc                 T    |j                   | j                  |j                          y y r'   srcwriter.   r0   r1   r2   s       r!   _output_child_prez%NativeCodeGenerator._output_child_preK   s#     <<#JJx||$ $r*   c                 @    |j                   | j                  d       y y )N)r;   r>   s       r!   _output_child_postz&NativeCodeGenerator._output_child_postQ   s     <<#JJsO $r*   )__name__
__module____qualname____doc__staticmethodtAnyr)   Iterabler   r/   r	   Exprr   r
   _FinalizeInfor9   r?   rB   r(   r*   r!   r$   r$   2   s      155  6

155(9 6c 6%JJ%',%8E8S8S%	
%%JJ%',%8E8S8S%	%JJ',8E8S8S	r*   r$   c                   $    e Zd ZdZeZ ee      Zy)NativeEnvironmentz=An environment that renders templates to native Python types.N)	rC   rD   rE   rF   r$   code_generator_classrG   r"   concatr(   r*   r!   rN   rN   X   s    G.-(Fr*   rN   c                       e Zd ZeZdej                  dej                  dej                  fdZdej                  dej                  dej                  fdZy)NativeTemplateargskwargsr   c                     | j                  t        |i |      }	 | j                  j                  | j	                  |            S # t
        $ r | j                  j                         cY S w xY 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_classrP   root_render_func	Exceptionenvironmenthandle_exception)r.   rS   rT   ctxs       r!   renderzNativeTemplate.renderb   sp     tT4V45	7))00%%c*   	7##4466	7s   )A #A,+A,c                 `  K   | j                   j                  st        d      | j                  t	        |i |      }	 | j
                  j                  | j                  |      2 cg c3 d {   }|7 6 nc c}w c}      S # t        $ r | j                   j                         cY S w xY ww)Nz8The environment was not created with async mode enabled.)
r[   is_asyncRuntimeErrorrV   rW   rX   rP   rY   rZ   r\   )r.   rS   rT   r]   ns        r!   render_asynczNativeTemplate.render_asyncr   s     ((J  tT4V45	7))00"&"7"7"<==Q===   	7##4466	7sX   <B.(B 'A9)A7
-A5.A7
1A95A7
7A98B B.#B+(B.*B++B.N)	rC   rD   rE   rN   rX   rH   rI   r^   rc   r(   r*   r!   rR   rR   _   sT    )7AEE 7QUU 7quu 7 7 7 7155 7r*   rR   )typingrH   astr   r   	itertoolsr   r   typesr   r   r	   compilerr
   r   r   r[   r   r   rJ   rI   Optionalr"   r$   rN   rR   template_classr(   r*   r!   <module>rk      s           #  # $ !!**QUU+ 

1550A D#- #L) ) 7X  7F $2   r*   