U
    \g%i                     @   sr   d Z ddlZddlmZ ddlmZ G dd dZG dd dZG d	d
 d
eZG dd dZG dd deZ	dS )zjutilities for analyzing expressions and blocks of Python
code, as well as generating Python from AST nodes    N)
exceptions)pyparserc                   @   s   e Zd ZdZdd ZdS )
PythonCodez<represents information about a string containing Python codec                 K   sV   || _ t | _t | _t|tr6tj| df|}n|}tj	| f|}|
| d S )Nexec)codesetdeclared_identifiersundeclared_identifiers
isinstancestrr   parselstripZFindIdentifiersvisitselfr   exception_kwargsexprf r   G/var/www/html/api-medvista/venv/lib/python3.8/site-packages/mako/ast.py__init__   s    
zPythonCode.__init__N__name__
__module____qualname____doc__r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZdd ZdS )ArgumentListzBparses a fragment of code as a comma-separated list of expressionsc                 K   sz   g | _ g | _t | _t | _t|trXtd|rFtd|sF|d7 }t	j
|df|}n|}t	j| tf|}|| d S )Nz\Sz,\s*$,r   )Zcodeargsargsr   r   r	   r
   r   rematchr   r   Z	FindTupler   r   r   r   r   r   r   6   s    
zArgumentList.__init__Nr   r   r   r   r   r   2   s   r   c                       s    e Zd ZdZ fddZ  ZS )PythonFragmentzextends 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*tjd| f||drF|d |d }|dd\}}|dkrh|d }nb|dkrz|d	 }nP|d
krd| d }n:|dkrd| d }n$|dkr|d }ntjd| f|t j	|f| d S )Nz^(\w+)(?:\s+(.*?))?:\s*(#|$)z0Fragment '%s' is not a partial control statement         )forifwhilepasstryzpass
except:pass)elifelsezif False:pass
exceptz	try:pass
withz!Unsupported control keyword: '%s')
r   r    stripSr   CompileExceptiongroupstartsuperr   )r   r   r   mkeywordr   	__class__r   r   r   U   s4    



zPythonFragment.__init__r   r   r   r   r   __classcell__r   r   r6   r   r!   H   s   r!   c                   @   s0   e Zd ZdZdddZdddZedd	 Zd
S )FunctionDeclzfunction declarationTc                 K   sp   || _ tj|df|}tj| f|}|| t| dsJtjd| f||sl| jrltjd| 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   r0   kwargs
kwargnames)r   r   Zallow_kwargsr   r   r   r   r   r   r   u   s$    


zFunctionDecl.__init__Fc           	      C   s6  g }| j ddd }| jddd }| jddd }| jddd }| jr^|d|d  |D ]f}|r~|d||f  qb|r|d}|dkr|| q|d|t|	 f  qb|| qb| j
r|d|d  |D ]@}|s|s|| q|d}|d|t|	 f  q|  |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).
        Nr<   z**r   z%s=%s*)argnamesr?   defaults
kwdefaultsr>   appendpopr   ZExpressionGeneratorvaluevarargsreverse)	r   Zas_callZ	namedeclsrA   r?   rB   rC   namedefaultr   r   r   get_argument_expressions   sB    	


z%FunctionDecl.get_argument_expressionsc                 C   s   t | jt | j S )N)tuplerA   r?   )r   r   r   r   allargnames   s    zFunctionDecl.allargnamesN)T)F)r   r   r   r   r   rK   propertyrM   r   r   r   r   r:   q   s
   

9r:   c                       s    e Zd ZdZ fddZ  ZS )FunctionArgsz.the argument portion of a function declarationc                    s   t  jd| f| d S )Nzdef ANON(%s):pass)r3   r   )r   r   r>   r6   r   r   r      s    zFunctionArgs.__init__r8   r   r   r6   r   rO      s   rO   )
r   r   makor   r   r   r   r!   r:   rO   r   r   r   r   <module>   s   ")T