o
     JAf.  ã                   @   sZ   d Z ddlmZ ddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZ G dd„ dejƒZdS )	zÖFixer for generator.throw(E, V, T).

g.throw(E)       -> g.throw(E)
g.throw(E, V)    -> g.throw(E(V))
g.throw(E, V, T) -> g.throw(E(V).with_traceback(T))

g.throw("foo"[, V[, T]]) will warn about string exceptions.é   )Úpytree)Útoken)Ú
fixer_base)ÚNameÚCallÚArgListÚAttrÚis_tuplec                   @   s   e Zd ZdZdZdd„ ZdS )ÚFixThrowTzÉ
    power< any trailer< '.' 'throw' >
           trailer< '(' args=arglist< exc=any ',' val=any [',' tb=any] > ')' >
    >
    |
    power< any trailer< '.' 'throw' > trailer< '(' exc=any ')' > >
    c                 C   sì   | j }|d  ¡ }|jtju r|  |d¡ d S | d¡}|d u r"d S | ¡ }t|ƒr7dd„ |jdd… D ƒ}nd|_	|g}|d	 }d
|v rl|d
  ¡ }d|_	t
||ƒ}	t|	tdƒƒt|gƒg }
| t |j|
¡¡ d S | t
||ƒ¡ d S )NÚexcz+Python 3 does not support string exceptionsÚvalc                 S   s   g | ]}|  ¡ ‘qS © )Úclone)Ú.0Úcr   r   ú./usr/lib/python3.10/lib2to3/fixes/fix_throw.pyÚ
<listcomp>)   s    z&FixThrow.transform.<locals>.<listcomp>é   éÿÿÿÿÚ ÚargsÚtbÚwith_traceback)Úsymsr   Útyper   ÚSTRINGZcannot_convertÚgetr	   ÚchildrenÚprefixr   r   r   r   Úreplacer   ZNodeZpower)ÚselfZnodeÚresultsr   r   r   r   Z
throw_argsr   ÚeZwith_tbr   r   r   Ú	transform   s*   

zFixThrow.transformN)Ú__name__Ú
__module__Ú__qualname__ZBM_compatibleZPATTERNr#   r   r   r   r   r
      s    r
   N)Ú__doc__r   r   Zpgen2r   r   Z
fixer_utilr   r   r   r   r	   ZBaseFixr
   r   r   r   r   Ú<module>   s    
