ó
è¾bc           @   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 d e j f d „  ƒ  YZ d S(	   s[  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.
i   (   t   pytree(   t   token(   t
   fixer_base(   t   Namet   Callt   Attrt   ArgListt   is_tuplet   FixRaisec           B   s   e  Z e Z d  Z d „  Z RS(   sB   
    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g  | j d d !D] } | j ƒ  ^ qô }	 n d	 | _ | g }	 d
 | k rÖ| d
 j ƒ  }
 d	 |
 _ | } | j t j k sm| j d k r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(   Nt   excs+   Python 3 does not support string exceptionsi   i    u    t   valu   raiseiÿÿÿÿu    t   tbu   Noneu   with_tracebackt   prefix(   t   symst   clonet   typeR   t   STRINGt   cannot_convertR   t   childrenR   R    t   Nodet
   raise_stmtR   t   NAMEt   valueR   R   R   t   simple_stmt(   t   selft   nodet   resultsR   R	   t   msgt   newR
   t   ct   argsR   t   et   with_tb(    (    s-   /usr/lib/python2.7/lib2to3/fixes/fix_raise.pyt	   transform&   s@    	!,			!%"(   t   __name__t
   __module__t   Truet   BM_compatiblet   PATTERNR!   (    (    (    s-   /usr/lib/python2.7/lib2to3/fixes/fix_raise.pyR      s   N(   t   __doc__t    R    t   pgen2R   R   t
   fixer_utilR   R   R   R   R   t   BaseFixR   (    (    (    s-   /usr/lib/python2.7/lib2to3/fixes/fix_raise.pyt   <module>   s
   (