o
    à;ïjâ   ã                   @   s¨   d Z ddlZddlZddlmZ ddlmZ ddlmZ h d£Ze d¡Z	dZ
dd
d„Zdd„ ZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dƒZdS )zHandles parsing of Python code.é    N)Ú	_ast_util)Úcompat)Ú
exceptions>   ÚNoneÚTrueÚFalseÚprintÚargz	<unknown>Úexecc              
   K   sd   zt  | t|¡W S  ty1 } ztjdt ¡ jj	t ¡ | dd… f fi t
|||ƒ¤Ž|‚d}~ww )a;  Parse an expression into AST.

    ``lineno_offset`` is the line within the template on which ``code``
    begins, relative to the line given in ``exception_kwargs``.  It is used
    to report a syntax error against the line it occurred on, rather than
    against the start of the construct that contains it.

    z(%s) %s (%r)r   é2   N)r   ÚparseÚEXPRESSION_FILENAMEÚ	Exceptionr   ÚSyntaxExceptionr   Úexception_asÚ	__class__Ú__name__Ú_adjust_lineno)ÚcodeÚmodeÚlineno_offsetÚexception_kwargsÚe© r   úV/home/hd29/karthikselvaraju/venvs/deluge/lib/python3.10/site-packages/mako/pyparser.pyr      s"   


ýÿÿ
ùø€ÿr   c                 C   sF   |  d¡}t| ddƒ}|du s|du r|S i |¥d|| | d i¥S )zdReturn ``exception_kwargs`` with the line of ``exc`` within the parsed
    code applied to it.

    ÚlinenoNé   )ÚgetÚgetattr)Úexcr   r   r   Ú
exc_linenor   r   r   r   5   s   
ÿþr   c                   @   sŒ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
e
 ZZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS ) ÚFindIdentifiersc                 K   s$   d| _ d| _tƒ | _|| _|| _d S ©NF)Úin_functionÚin_assign_targetsÚsetÚlocal_ident_stackÚlistenerr   ©Úselfr'   r   r   r   r   Ú__init__H   s
   
zFindIdentifiers.__init__c                 C   s(   | j s| jj |¡ d S | j |¡ d S ©N)r#   r'   Údeclared_identifiersÚaddr&   )r)   Únamer   r   r   Ú_add_declaredO   s   zFindIdentifiers._add_declaredc                 C   s   |   |j¡ d S r+   )r/   r.   ©r)   Únoder   r   r   Úvisit_ClassDefU   ó   zFindIdentifiers.visit_ClassDefc                 C   s8   |   |j¡ | j}d| _|jD ]}|   |¡ q|| _d S ©NT)ÚvisitÚvaluer$   Útargets)r)   r1   Úin_aÚnr   r   r   Úvisit_AssignX   s   

zFindIdentifiers.visit_Assignc                 C   sF   |j d ur|  |j ¡ |jd ur|  |j¡ |jD ]}|  |¡ qd S r+   )r.   r/   Útyper5   Úbody©r)   r1   Ú	statementr   r   r   Úvisit_ExceptHandlerd   s   


ÿz#FindIdentifiers.visit_ExceptHandlerc                 G   s   |   |d¡ d S r4   )Ú_visit_function)r)   r1   Úargsr   r   r   Úvisit_Lambdal   r3   zFindIdentifiers.visit_Lambdac                 C   s   |   |j¡ |  |d¡ d S r"   )r/   r.   r@   r0   r   r   r   Úvisit_FunctionDefo   ó   z!FindIdentifiers.visit_FunctionDefc                 C   ó<   | j r|jD ]}|  |j¡ |  |j¡ qd S |  |¡ d S r+   ©r#   Ú
generatorsr5   ÚtargetÚiterÚgeneric_visit©r)   r1   Úcompr   r   r   Úvisit_ListComps   ó   
þzFindIdentifiers.visit_ListCompc                 C   rE   r+   rF   rK   r   r   r   Úvisit_DictComp}   rN   zFindIdentifiers.visit_DictCompc                 c   s0   � |D ]}t |tjƒr|jE d H  q|V  qd S r+   )Ú
isinstanceÚ_astÚTupleÚelts)r)   rA   r	   r   r   r   Ú_expand_tuples…   s   €üzFindIdentifiers._expand_tuplesc                 C   sj   | j }d| _ | j}| dd„ |  |jj¡D ƒ¡| _|r"|  |j¡ n|jD ]}|  |¡ q%|| _ || _d S )NTc                 S   ó   g | ]}t |ƒ‘qS r   ©Úarg_id©Ú.0r	   r   r   r   Ú
<listcomp>˜   ó    z3FindIdentifiers._visit_function.<locals>.<listcomp>)r#   r&   ÚunionrT   rA   r5   r<   )r)   r1   ÚislambdaÚinfr&   r9   r   r   r   r@   Œ   s   ÿ

zFindIdentifiers._visit_functionc                 C   sH   |   |j¡ |   |j¡ |jD ]}|   |¡ q|jD ]}|   |¡ qd S r+   )r5   rI   rH   r<   Úorelser=   r   r   r   Ú	visit_For¢   s   

ÿzFindIdentifiers.visit_Forc                 C   sb   t |jtjƒr|  |j¡ d S |jtvr+|j| jjvr-|j| j	vr/| jj
 |j¡ d S d S d S d S r+   )rP   ÚctxrQ   ÚStorer/   ÚidÚreservedr'   r,   r&   Úundeclared_identifiersr-   r0   r   r   r   Ú
visit_Name¬   s   
üzFindIdentifiers.visit_Namec                 C   s>   |j D ]}|jd ur|  |j¡ q|  |j d¡d ¡ qd S )NÚ.r   )ÚnamesÚasnamer/   r.   Úsplit©r)   r1   r.   r   r   r   Úvisit_Import¸   s
   

üzFindIdentifiers.visit_Importc                 C   sR   |j D ]#}|jd ur|  |j¡ q|jdkr tj	di | j¤Ž‚|  |j¡ qd S )NÚ*ú£'import *' is not supported, since all identifier names must be explicitly declared.  Please use the form 'from <modulename> import <name1>, <name2>, ...' instead.)rn   )rh   ri   r/   r.   r   ÚCompileExceptionr   rk   r   r   r   Úvisit_ImportFrom¿   s   


ÿûôz FindIdentifiers.visit_ImportFromN)r   Ú
__module__Ú__qualname__r*   r/   r2   r:   r?   rB   rC   rM   Úvisit_SetCompÚvisit_GeneratorExprO   rT   r@   r`   rf   rl   rp   r   r   r   r   r!   G   s"    
r!   c                   @   ó   e Zd Zdd„ Zdd„ ZdS )Ú	FindTuplec                 K   s   || _ || _|| _d S r+   )r'   r   Úcode_factory)r)   r'   rw   r   r   r   r   r*   Ð   s   
zFindTuple.__init__c                 C   sx   |j D ]6}| j|fi | j¤Ž}| jj |¡ | jj t|ƒ ¡ ¡ | jj	}| 
|j	¡| j_	| jj}| 
|j¡| j_qd S r+   )rS   rw   r   r'   ÚcodeargsÚappendrA   ÚExpressionGeneratorr6   r,   r\   re   )r)   r1   r9   ÚpÚldiÚluir   r   r   Úvisit_TupleÕ   s   
ÿ
ÿ÷zFindTuple.visit_TupleN)r   rq   rr   r*   r~   r   r   r   r   rv   Ï   s    rv   c                   @   ru   )Ú	ParseFuncc                 K   s   || _ || _d S r+   )r'   r   r(   r   r   r   r*   å   s   
zParseFunc.__init__c                 C   s¢   |j | j_dd„ |jjD ƒ}|jjr| |jjj¡ dd„ |jjD ƒ}|jjr/| |jjj¡ || j_	|jj
| j_
|| j_|jj| j_|jj| j_|jj| j_d S )Nc                 S   rU   r   rV   rX   r   r   r   rZ   ì   r[   z/ParseFunc.visit_FunctionDef.<locals>.<listcomp>c                 S   rU   r   rV   rX   r   r   r   rZ   ð   r[   )r.   r'   ÚfuncnamerA   Úvarargry   r	   Ú
kwonlyargsÚkwargÚargnamesÚdefaultsÚ
kwargnamesÚkw_defaultsÚ
kwdefaultsÚvarargsÚkwargs)r)   r1   r„   r†   r   r   r   rC   é   s   
zParseFunc.visit_FunctionDefN)r   rq   rr   r*   rC   r   r   r   r   r   ä   ó    r   c                   @   ru   )rz   c                 C   s   t  d¡| _| j |¡ d S )Nz    )r   ÚSourceGeneratorÚ	generatorr5   )r)   Úastnoder   r   r   r*   ü   rD   zExpressionGenerator.__init__c                 C   s   d  | jj¡S )NÚ )Újoinr�   Úresult)r)   r   r   r   r6      s   zExpressionGenerator.valueN)r   rq   rr   r*   r6   r   r   r   r   rz   û   r‹   rz   )r
   r   )Ú__doc__rQ   ÚoperatorÚmakor   r   r   rd   Ú
attrgetterrW   r   r   r   ÚNodeVisitorr!   rv   r   rz   r   r   r   r   Ú<module>   s    

 	