ó
è¾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 m Z d „  Z d e j f d „  ƒ  YZ d	 S(
   sª  Fixer for except statements with named exceptions.

The following cases will be converted:

- "except E, T:" where T is a name:

    except E as T:

- "except E, T:" where T is not a name, tuple or list:

        except E as t:
            T = t

    This is done because the target of an "except" clause must be a
    name.

- "except E, T:" where T is a tuple or list literal:

        except E as t:
            T = t.args
i   (   t   pytree(   t   token(   t
   fixer_base(   t   Assignt   Attrt   Namet   is_tuplet   is_listt   symsc         c   sb   x[ t  |  ƒ D]M \ } } | j t j k r | j d j d k rZ | |  | d f VqZ q q Wd  S(   Ni    u   excepti   (   t	   enumeratet   typeR   t   except_clauset   childrent   value(   t   nodest   it   n(    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_except.pyt   find_excepts   s    t	   FixExceptc           B   s   e  Z e Z d  Z d „  Z RS(   s1  
    try_stmt< 'try' ':' (simple_stmt | suite)
                  cleanup=(except_clause ':' (simple_stmt | suite))+
                  tail=(['except' ':' (simple_stmt | suite)]
                        ['else' ':' (simple_stmt | suite)]
                        ['finally' ':' (simple_stmt | suite)]) >
    c         C   s,  |  j  } g  | d D] } | j ƒ  ^ q } g  | d D] } | j ƒ  ^ q7 } x™t | ƒ D]‹\ } }	 t | j ƒ d k r\ | j d d !\ }
 } } | j t d d d ƒƒ | j t j	 k rÉt |  j
 ƒ  d d ƒ} | j ƒ  } d | _ | j | ƒ | j ƒ  } |	 j } x0 t | ƒ D]" \ } } t | t j ƒ rPqqWt | ƒ s[t | ƒ r|t | t | t d	 ƒ ƒ ƒ } n t | | ƒ } x( t | |  ƒ D] } |	 j d
 | ƒ qœW|	 j | | ƒ qç| j d k rçd | _ qçq\ q\ Wg  | j d  D] } | j ƒ  ^ qù| | } t j | j | ƒ S(   Nt   tailt   cleanupi   i   u   ast   prefixu    u    u   argsi    i   (   R   t   cloneR   t   lenR   t   replaceR   R
   R   t   NAMEt   new_nameR   R	   t
   isinstanceR    t   NodeR   R   R   R   t   reversedt   insert_child(   t   selft   nodet   resultsR   R   R   t   cht   try_cleanupR   t   e_suitet   Et   commat   Nt   new_Nt   targett   suite_stmtsR   t   stmtt   assignt   childt   cR   (    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_except.pyt	   transform/   s6    	##		!.(   t   __name__t
   __module__t   Truet   BM_compatiblet   PATTERNR/   (    (    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_except.pyR   $   s   N(   t   __doc__t    R    t   pgen2R   R   t
   fixer_utilR   R   R   R   R   R   R   t   BaseFixR   (    (    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_except.pyt   <module>   s   .	