î
\á[\Á	  ã               @   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
 Gd d „  d e j ƒ Z d S)z7
Convert use of sys.exitfunc to use the atexit module.
é    )ÚpytreeÚ
fixer_base)ÚNameÚAttrÚCallÚCommaÚNewlineÚsymsc                   sR   e  Z d  Z d Z d Z d Z ‡  f d d †  Z ‡  f d d †  Z d d „  Z ‡  S)	ÚFixExitfuncTa”  
              (
                  sys_import=import_name<'import'
                      ('sys'
                      |
                      dotted_as_names< (any ',')* 'sys' (',' any)* >
                      )
                  >
              |
                  expr_stmt<
                      power< 'sys' trailer< '.' 'exitfunc' > >
                  '=' func=any >
              )
              c                s   t  t |  ƒ j | Œ  d  S)N)Úsuperr
   Ú__init__)ÚselfÚargs)Ú	__class__© ú0/usr/lib/python3.4/lib2to3/fixes/fix_exitfunc.pyr      s    zFixExitfunc.__init__c                s&   t  t |  ƒ j | | ƒ d  |  _ d  S)N)r   r
   Ú
start_treeÚ
sys_import)r   ZtreeÚfilename)r   r   r   r   !   s    zFixExitfunc.start_treec             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   ÚfuncÚ ÚatexitÚregisterzKCan't find sys import; Please add an atexit import at the top of your file.é   ú Úimporté   )r   ZcloneÚprefixr   ZNoder	   Zpowerr   r   r   ÚreplaceZwarningZchildrenÚtypeZdotted_as_namesZappend_childr   ÚparentÚindexZimport_nameZsimple_stmtZinsert_childr   )r   ZnodeZresultsr   r   ÚcallÚnamesZcontaining_stmtZpositionZstmt_containerZ
new_importÚnewr   r   r   Ú	transform%   s2    		zFixExitfunc.transform)	Ú__name__Ú
__module__Ú__qualname__Zkeep_line_orderZBM_compatibleZPATTERNr   r   r%   r   r   )r   r   r
      s   r
   N)Ú__doc__Zlib2to3r   r   Zlib2to3.fixer_utilr   r   r   r   r   r	   ZBaseFixr
   r   r   r   r   Ú<module>   s   .