o
    à;ïjð  ã                   @   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d„ZdS )Ú
PythonCodez<represents information about a string containing Python coder   c                 K   sˆ   || _ tƒ | _tƒ | _t|tƒr2| ¡ }||d t|ƒt|ƒ …  d¡7 }t	j
|dfd|i|¤Ž}n|}t	j| fi |¤Ž}| |¡ d S )NÚ
ÚexecÚlineno_offset)ÚcodeÚsetÚdeclared_identifiersÚundeclared_identifiersÚ
isinstanceÚstrÚlstripÚlenÚcountr   ÚparseÚFindIdentifiersÚvisit)Úselfr   r   Úexception_kwargsÚstrippedÚexprÚf© r   úQ/home/hd29/karthikselvaraju/venvs/deluge/lib/python3.10/site-packages/mako/ast.pyÚ__init__   s"   
"þýüzPythonCode.__init__N)r   ©Ú__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   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   r   r   r   r   @   s   
zArgumentList.__init__Nr   r   r   r   r   r!   =   s    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}|dv r8|d }n7|d	krA|d
 }n.|dv rNd| d }d}n!|dkr[d| d }d}n|dkrd|d }ntjd| fi |¤Ž‚tƒ j	|fd|i|¤Ž d S )Nz^(\w+)(?:\s+(.*?))?:\s*(#|$)z0Fragment '%s' is not a partial control statementé   é   é   r   )ÚforÚifÚwhileÚpassÚtryzpass
except:pass)ÚelifÚelsezif False:pass
éÿÿÿÿÚexceptz	try:pass
Úwithz!Unsupported control keyword: '%s'r   )
r%   r&   ÚstripÚSr   ÚCompileExceptionÚgroupÚstartÚsuperr   )r   r   r   ÚmÚkeywordr   r   ©Ú	__class__r   r   r   ^   s:   ÿþ



ÿþzPythonFragment.__init__©r   r   r   r    r   Ú__classcell__r   r   r?   r   r)   R   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 herer4   )
r   r   r   Ú	ParseFuncr   Úhasattrr   r9   ÚkwargsÚ
kwargnames)r   r   Úallow_kwargsr   r   r   r   r   r   r   …   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).
        Nr4   z**r   z%s=%sÚ*)ÚargnamesrH   ÚdefaultsÚ
kwdefaultsrG   ÚappendÚpopr   ÚExpressionGeneratorÚvalueÚvarargsÚreverse)	r   Úas_callÚ	namedeclsrK   rH   rL   rM   ÚnameÚdefaultr   r   r   Úget_argument_expressions—   sB   	
ÿÿ
ÿÿz%FunctionDecl.get_argument_expressionsc                 C   s   t | jƒt | jƒ S )N)ÚtuplerK   rH   )r   r   r   r   ÚallargnamesÐ   s   zFunctionDecl.allargnamesN)T)F)r   r   r   r    r   rX   ÚpropertyrZ   r   r   r   r   rC   ‚   s    

9rC   c                       r(   )ÚFunctionArgsz.the argument portion of a function declarationc                    s   t ƒ jd| fi |¤Ž d S )Nzdef ANON(%s):pass)r<   r   )r   r   rG   r?   r   r   r   Ø   s   zFunctionArgs.__init__rA   r   r   r?   r   r\   Õ   s    r\   )
r    r%   Úmakor   r   r   r!   r)   rC   r\   r   r   r   r   Ú<module>   s   -0S