o
    4³c…  ã                   @   s„   d Z ddlZddlmZ ddlmZ ddlmZ G dd„ deƒZG dd	„ d	eƒZG d
d„ deƒZ	G dd„ deƒ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)Úcompat)Ú
exceptions)Úpyparserc                   @   ó   e Zd ZdZdd„ ZdS )Ú
PythonCodez<represents information about a string containing Python codec                 K   s`   || _ tƒ | _tƒ | _t|tjƒrtj| 	¡ dfi |¤Ž}n|}tj
| fi |¤Ž}| |¡ d S )NÚexec)ÚcodeÚsetÚdeclared_identifiersÚundeclared_identifiersÚ
isinstancer   Ústring_typesr   ÚparseÚlstripÚFindIdentifiersÚvisit©Úselfr   Úexception_kwargsÚexprÚf© r   ú>/var/www/html/gps/gps/lib/python3.10/site-packages/mako/ast.pyÚ__init__   s   zPythonCode.__init__N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      ó    r   c                   @   r   )ÚArgumentListzBparses a fragment of code as a comma-separated list of expressionsc                 K   s„   g | _ g | _tƒ | _tƒ | _t|tjƒr/t 	d|¡r$t 	d|¡s$|d7 }t
j|dfi |¤Ž}n|}t
j| tfi |¤Ž}| |¡ d S )Nz\Sz,\s*$ú,r   )ÚcodeargsÚargsr	   r
   r   r   r   r   ÚreÚmatchr   r   Ú	FindTupler   r   r   r   r   r   r   7   s   zArgumentList.__init__Nr   r   r   r   r   r    3   r   r    c                       ó    e Zd ZdZ‡ fdd„Z‡  ZS )Ú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tjd| fi |¤Ž‚| d¡r%|d | d¡… }| dd¡\}}|dv r6|d }n7|dkr?|d	 }n.|d
ksG|dkrNd| d }n|dkrYd| d }n|dkrb|d }ntjd| fi |¤Ž‚tt	| ƒj
|fi |¤Ž 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   r   ÚmÚkeywordr   ©Ú	__class__r   r   r   V   s4   ÿþ



ÿþzPythonFragment.__init__©r   r   r   r   r   Ú__classcell__r   r   r=   r   r(   I   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   s„   || _ tj|dfi |¤Ž}tj| fi |¤Ž}| |¡ t| dƒs+tjd| fi |¤Ž‚|s>| jr@tjd| j	d  fi |¤Ž‚d S d S )Nr   Úfuncnamez'Code '%s' is not a function declarationz('**%s' keyword argument not allowed hereéÿÿÿÿ)
r   r   r   Ú	ParseFuncr   Úhasattrr   r7   ÚkwargsÚ
kwargnames)r   r   Úallow_kwargsr   r   r   r   r   r   r   v   s&   

ÿþ
ÿÿýÿzFunctionDecl.__init__Fc           	      C   s4  g }| j ddd… }| jddd… }| jddd… }| jddd… }| jr/| d| d¡ ¡ |D ]3}|r?| d||f ¡ q1|r_| d¡}|du rP| |¡ q1| d|t |¡ 	¡ f ¡ q1| |¡ q1| j
rr| d| d¡ ¡ |D ]}|sz|s€| |¡ qt| d¡}| d|t |¡ 	¡ f ¡ qt| ¡  |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).
        NrC   z**r   z%s=%sÚ*)ÚargnamesrG   ÚdefaultsÚ
kwdefaultsrF   ÚappendÚpopr   ÚExpressionGeneratorÚvalueÚvarargsÚreverse)	r   Úas_callÚ	namedeclsrJ   rG   rK   rL   ÚnameÚdefaultr   r   r   Úget_argument_expressionsˆ   sB   	
ÿÿ
ÿÿz%FunctionDecl.get_argument_expressionsc                 C   s   t | jƒt | jƒ S )N)ÚtuplerJ   rG   )r   r   r   r   ÚallargnamesÁ   s   zFunctionDecl.allargnamesN)T)F)r   r   r   r   r   rW   ÚpropertyrY   r   r   r   r   rA   r   s    

9rA   c                       r'   )ÚFunctionArgsz.the argument portion of a function declarationc                    s    t t| ƒjd| fi |¤Ž d S )Nzdef ANON(%s):pass)r:   r[   r   )r   r   rF   r=   r   r   r   Ê   s
   
ÿ
ÿzFunctionArgs.__init__r?   r   r   r=   r   r[   Æ   s    r[   )r   r$   Úmakor   r   r   Úobjectr   r    r(   rA   r[   r   r   r   r   Ú<module>   s   ")T