Ņō
$8Zc           @   s   d  Z  d d k l Z d d k l Z d d k l Z d d k l Z l Z l	 Z	 l
 Z
 l Z l Z d   Z d e i 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   sf   x_ t  |   D]Q \ } } | i t i j o2 | i d i d j o | |  | d f Vq^ q q Wd  S(   Ni    u   excepti   (   t	   enumeratet   typeR   t   except_clauset   childrent   value(   t   nodest   it   n(    (    s.   /usr/lib/python2.6/lib2to3/fixes/fix_except.pyt   find_excepts   s
     t	   FixExceptc           B   s   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   sO  |  i  } g  } | d D] } | | i   q ~ } g  } | d D] } | | i   qC ~ }	 x¤t |	  D]\ }
 } t |
 i  d j ot|
 i d d !\ } } } | i t d d d  | i t i	 j ot |  i
   d d } | i   } d | _ | i |  | i   } | i } x2 t |  D]$ \ } } t | t i  o Pq/q/Wt |  p t |  o" t | t | t d	    } n t | |  } x( t | |   D] } | i d
 |  qŗW| i | |  q| i d j o d | _ qql ql Wg  } | i d  D] } | | i   q~ |	 | } t i | i |  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   t   _[1]R   R   t   _[2]t   cht   try_cleanupR   t   e_suitet   Et   commat   Nt   new_Nt   targett   suite_stmtsR   t   stmtt   assignt   childt   _[3]t   cR   (    (    s.   /usr/lib/python2.6/lib2to3/fixes/fix_except.pyt	   transform.   s<    	++ 		 	" 6(   t   __name__t
   __module__t   PATTERNR2   (    (    (    s.   /usr/lib/python2.6/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.6/lib2to3/fixes/fix_except.pyt   <module>   s   .	