ó
8Ŝ	Pc           @   sg   d  Z  d d l m Z m Z d d l m Z m Z m Z m Z m	 Z	 m
 Z
 d e j f d     YZ d S(   s7   
Convert use of sys.exitfunc to use the atexit module.
i˙˙˙˙(   t   pytreet
   fixer_base(   t   Namet   Attrt   Callt   Commat   Newlinet   symst   FixExitfuncc           B   s5   e  Z e Z e Z d  Z d   Z d   Z d   Z RS(   s  
              (
                  sys_import=import_name<'import'
                      ('sys'
                      |
                      dotted_as_names< (any ',')* 'sys' (',' any)* >
                      )
                  >
              |
                  expr_stmt<
                      power< 'sys' trailer< '.' 'exitfunc' > >
                  '=' func=any >
              )
              c         G   s   t  t |   j |   d  S(   N(   t   superR   t   __init__(   t   selft   args(    (    s0   /usr/lib/python2.7/lib2to3/fixes/fix_exitfunc.pyR
      s    c         C   s&   t  t |   j | |  d  |  _ d  S(   N(   R	   R   t
   start_treet   Nonet
   sys_import(   R   t   treet   filename(    (    s0   /usr/lib/python2.7/lib2to3/fixes/fix_exitfunc.pyR   !   s    c         C   s   d | k r/ |  j  d  k r+ | d |  _  n  d  S| d j   } d | _ t j t j t t	 d  t	 d    } t
 | | g | j  } | j |  |  j  d  k rş |  j | d  d  S|  j  j d } | j t j k r| j t    | j t	 d d   n |  j  j } | j j |  j   } | j }	 t j t j t	 d	  t	 d d  g  }
 t j t j |
 g  } | j | d t    | j | d
 |  d  S(   NR   t   funcu    u   atexitu   registersK   Can't find sys import; Please add an atexit import at the top of your file.i   u    u   importi   (   R   R   t   clonet   prefixR    t   NodeR   t   powerR   R   R   t   replacet   warningt   childrent   typet   dotted_as_namest   append_childR   t   parentt   indext   import_namet   simple_stmtt   insert_childR   (   R   t   nodet   resultsR   t   registert   callt   namest   containing_stmtt   positiont   stmt_containert
   new_importt   new(    (    s0   /usr/lib/python2.7/lib2to3/fixes/fix_exitfunc.pyt	   transform%   s2    		(	   t   __name__t
   __module__t   Truet   keep_line_ordert   BM_compatiblet   PATTERNR
   R   R,   (    (    (    s0   /usr/lib/python2.7/lib2to3/fixes/fix_exitfunc.pyR      s   		N(   t   __doc__t   lib2to3R    R   t   lib2to3.fixer_utilR   R   R   R   R   R   t   BaseFixR   (    (    (    s0   /usr/lib/python2.7/lib2to3/fixes/fix_exitfunc.pyt   <module>   s   .