î
\á[\n  ã               @   s{   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 Gd d „  d e j ƒ Z d S)	a[  Fixer for 'raise E, V, T'

raise         -> raise
raise E       -> raise E
raise E, V    -> raise E(V)
raise E, V, T -> raise E(V).with_traceback(T)
raise E, None, T -> raise E.with_traceback(T)

raise (((E, E'), E''), E'''), V -> raise E(V)
raise "foo", V, T               -> warns about string exceptions


CAVEATS:
1) "raise E, V" will be incorrectly translated if V is an exception
   instance. The correct Python 3 idiom is

        raise E from V

   but since we can't detect instance-hood by syntax alone and since
   any client code would have to be changed as well, we don't automate
   this.
é   )Úpytree)Útoken)Ú
fixer_base)ÚNameÚCallÚAttrÚArgListÚis_tuplec               @   s(   e  Z d  Z d Z d Z d d „  Z d S)ÚFixRaiseTzB
    raise_stmt< 'raise' exc=any [',' val=any [',' tb=any]] >
    c             C   s  |  j  } | d j ƒ  } | j t j k rE d } |  j | | ƒ d  St | ƒ rŠ x* t | ƒ r} | j d j d j ƒ  } qT Wd | _ n  d | k rÇ t	 j
 | j t d ƒ | g ƒ } | j | _ | S| d j ƒ  } t | ƒ rd d	 „  | j d d … Dƒ } n d
 | _ | g } d | k rÍ| d j ƒ  }	 d
 |	 _ | }
 | j t j k sd| j d k rvt | | ƒ }
 n  t |
 t d ƒ ƒ t |	 g ƒ g } t	 j
 | j t d ƒ g | ƒ } | j | _ | St	 j
 | j t d ƒ t | | ƒ g d | j ƒSd  S)NÚexcz+Python 3 does not support string exceptionsé   é    ú ÚvalÚraisec             S   s   g  |  ] } | j  ƒ  ‘ q S© )Úclone)Ú.0Úcr   r   ú-/usr/lib/python3.4/lib2to3/fixes/fix_raise.pyú
<listcomp>D   s   	 z&FixRaise.transform.<locals>.<listcomp>Ú ÚtbÚNoneÚwith_tracebackÚprefixéÿÿÿÿ)Úsymsr   Útyper   ÚSTRINGZcannot_convertr	   Zchildrenr   r   ZNodeZ
raise_stmtr   ÚNAMEÚvaluer   r   r   Zsimple_stmt)ÚselfZnodeZresultsr   r   ÚmsgÚnewr   Úargsr   ÚeZwith_tbr   r   r   Ú	transform&   s@    	!#			!%"zFixRaise.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
   (