o
    èÇhò  ã                   @   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                   @   ó   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ƒrtj| ¡ dfi |¤Ž}n|}tj	| fi |¤Ž}| 
|¡ d S )NÚexec)ÚcodeÚsetÚdeclared_identifiersÚundeclared_identifiersÚ
isinstanceÚstrr   ÚparseÚlstripÚFindIdentifiersÚvisit©Úselfr   Úexception_kwargsÚexprÚf© r   ú\/var/www/html/construction_image-detection-poc/venv/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ƒ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   ÚreÚmatchr   r   Ú	FindTupler   r   r   r   r   r   r   6   s   
zArgumentList.__init__Nr   r   r   r   r   r   2   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 }n3|dkr?|d	 }n*|d
v rJd| d }n|dkrUd| d }n|dkr^|d }ntjd| fi |¤Ž‚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   ÚmÚkeywordr   ©Ú	__class__r   r   r   U   s4   ÿþ



ÿþzPythonFragment.__init__©r   r   r   r   r   Ú__classcell__r   r   r<   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   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   r6   ÚkwargsÚ
kwargnames)r   r   Úallow_kwargsr   r   r   r   r   r   r   u   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).
        NrB   z**r   z%s=%sÚ*)ÚargnamesrF   ÚdefaultsÚ
kwdefaultsrE   ÚappendÚpopr   ÚExpressionGeneratorÚvalueÚvarargsÚreverse)	r   Úas_callÚ	namedeclsrI   rF   rJ   rK   ÚnameÚdefaultr   r   r   Úget_argument_expressions‡   sB   	
ÿÿ
ÿÿz%FunctionDecl.get_argument_expressionsc                 C   s   t | jƒt | jƒ S )N)ÚtuplerI   rF   )r   r   r   r   ÚallargnamesÀ   s   zFunctionDecl.allargnamesN)T)F)r   r   r   r   r   rV   ÚpropertyrX   r   r   r   r   r@   q   s    

9r@   c                       r&   )ÚFunctionArgsz.the argument portion of a function declarationc                    s   t ƒ jd| fi |¤Ž d S )Nzdef ANON(%s):pass)r9   r   )r   r   rE   r<   r   r   r   É   s   zFunctionArgs.__init__r>   r   r   r<   r   rZ   Å   s    rZ   )
r   r#   Úmakor   r   r   r   r'   r@   rZ   r   r   r   r   Ú<module>   s   ")T