관리-도구
편집 파일: ast.cpython-37.pyc
B �C]� � @ s� d Z ddlZddlmZ ddlmZ ddlmZ G dd� de�ZG dd � d e�ZG d d� de�Z G dd � d e�Z G dd� de �ZdS )zjutilities for analyzing expressions and blocks of Python code, as well as generating Python from AST nodes� N)�compat)� exceptions)�pyparserc @ s e Zd ZdZdd� ZdS )� PythonCodez<represents information about a string containing Python codec K sX || _ t� | _t� | _t|tj�r8tj|� � df|�}n|}tj | f|�}|�|� d S )N�exec)�code�set�declared_identifiers�undeclared_identifiers� isinstancer �string_typesr �parse�lstripZFindIdentifiers�visit)�selfr �exception_kwargs�expr�f� r �9/opt/alt/python37/lib/python3.7/site-packages/mako/ast.py�__init__ s zPythonCode.__init__N)�__name__� __module__�__qualname__�__doc__r r r r r r s r c @ s e Zd ZdZdd� ZdS )�ArgumentListzBparses a fragment of code as a comma-separated list of expressionsc K s| g | _ g | _t� | _t� | _t|tj�rZt� d|�rHt� d|�sH|d7 }t j|df|�}n|}t j| t f|�}|�|� d S )Nz\Sz,\s*$�,r )Zcodeargs�argsr r r r r r �re�matchr r Z FindTupler r )r r r r r r r r r 7 s zArgumentList.__init__N)r r r r r r r r r r 3 s r c s e Zd ZdZ� fdd�Z� ZS )�PythonFragmentz�extends PythonCode to provide identifier lookups in partial control statements e.g.:: for x in 5: elif y==9: except (MyException, e): c s� t �d|�� t j�}|s*tjd| f|��|�d�rF|d |�d�� }|�dd�\}}|dkrh|d }nj|dkrz|d }nX|d ks�|dkr�d| d }n:|d kr�d| d }n$|dkr�|d }ntjd| f|��tt | �j |f|� d S )Nz^(\w+)(?:\s+(.*?))?:\s*(#|$)z0Fragment '%s' is not a partial control statement� � � )�for�if�while�pass�tryzpass except:pass�elif�elsezif False:pass �exceptz try:pass �withz!Unsupported control keyword: '%s')r r �strip�Sr �CompileException�group�start�superr r )r r r �m�keywordr )� __class__r r r V s, zPythonFragment.__init__)r r r r r � __classcell__r r )r5 r r I s r c @ s0 e Zd ZdZddd�Zddd�Zedd � �Zd S ) �FunctionDeclzfunction declarationTc K sp || _ tj|df|�}tj| f|�}|�|� t| d�sJtjd| f|��|sl| jrltjd| j d f|��d S )Nr �funcnamez'Code '%s' is not a function declarationz('**%s' keyword argument not allowed here���) r r r Z ParseFuncr �hasattrr r/ �kwargs� kwargnames)r r Zallow_kwargsr r r r r r r v s zFunctionDecl.__init__Fc C s> g }| j ddd� }| jddd� }| jddd� }| jddd� }| jr^|�d|�d� � xn|D ]f}|r�|�d||f � qd|r�|�d�}|dkr�|�|� q�|�d|t�|�� � f � qd|�|� qdW | j r�|�d|�d� � xH|D ]@}|s�|�s|�|� q�|�d�}|�d|t�|�� � f � q�W |�� |S )aE Return the argument declarations of this FunctionDecl as a printable list. By default the return value is appropriate for writing in a ``def``; set `as_call` to true to build arguments to be passed to the function instead (assuming locals with the same names as the arguments exist). Nr9 z**r z%s=%s�*)�argnamesr<