← Back
Editing: nativetypes.cpython-38.pyc
U sݨ\� � @ s� d dl Z d dlmZ d dlmZmZ d dlmZ d dlm Z d dl mZmZ d dl mZmZ d dlmZmZ d d � ZG dd� de�ZG d d� de�ZG dd� de�ZdS )� N)�literal_eval)�islice�chain)�nodes�� text_type)� CodeGenerator� has_safe_repr)�Environment�Template)�concat�escapec C st t t| d��}|sdS t|�dkr,|d }nd�dd� t|| �D ��}z t|�W S tttfk rn | Y S X dS )a6 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. � N� r � c S s g | ]}t |��qS � r )�.0�vr r �4/usr/lib/python3/dist-packages/jinja2/nativetypes.py� <listcomp> s z!native_concat.<locals>.<listcomp>) �listr �len�joinr r � ValueError�SyntaxError�MemoryError)r �head�outr r r � native_concat s r c @ s e Zd ZdZdd� ZdS )�NativeCodeGeneratorzA code generator which avoids injecting ``to_string()`` calls around the internal code Jinja uses to render templates. c s �j r|jrdS �jj� t� dd�}t� dd�}t� dd�}� dk rl|sL|rRd}qt|rf� �fdd�}qt� }ndd� }d}|jr���d � ��� d }g }|jD ]�} z0|dkr�t�� �| � |j �} t| �s�t�� �W n$ tjk r� |�| � Y q�Y nX z4|j j �r"t| d��r| �� } nt| �} || �} W n$ tk �rP |�| � Y q�Y nX |�rxt|d t��rx|d �| � q�|�| g� q�t|�d k �s�|jdk �r�|jdk �r�t|�dk�r̈�d|j � n��d|j � ��� |D ]�}t|t��r0tt|��}|jdk�r ��d| � n��|d � n�|jdk�rJ��d|� n ��|� d} � dk �r���d� |�r|��d� | d7 } ��||� | dk�r���d| � |jdk �r��d� �q�|jdk �r��� ��t|�dk�r�d�p�d� �ng }g }|D ]>}t|t��r,|�t|��dd�� n|�d� |�|� �q��d� ��tt|��d � ��� |D ]�}��|� d} � dk �r҈�d� |�r���d� n"|�r���d� n|�rʈ�d� | d7 } ��||� ��d| d � �qp��� ��d� |�r��� dS )z}Same as :meth:`CodeGenerator.visit_Output`, but do not call ``to_string`` on output nodes in generated code. NZcontextfunctionFZevalcontextfunctionZenvironmentfunctionc s � �j | �S �N)�environment��x��finalize�selfr r �const_finalize7 s z8NativeCodeGenerator.visit_Output.<locals>.const_finalizec S s | S r r r"