o
    bc	                     @   sJ   d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
 G d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                       s<   e Zd ZdZdZdZ fddZ fddZdd Z  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__ 1/usr/lib/python3.10/lib2to3/fixes/fix_exitfunc.pyr      s   zFixExitfunc.__init__c                    s   t t| || d | _d S r   )r   r
   
start_tree
sys_import)r   treefilenamer   r   r   r   !   s   
zFixExitfunc.start_treec                 C   s(  d|v r| j d u r|d | _ d S |d  }d|_ttjttdtd}t	||g|j}|
| | j d u rA| |d d S | j jd }|jtjkr]|t  |tdd d S | j j}|j| j }|j}	ttjtd	tddg}
ttj|
g}||d t  ||d
 | d S )Nr   func atexitregisterzKCan't find sys import; Please add an atexit import at the top of your file.    import   )r   cloneprefixr   Noder	   powerr   r   r   replacewarningchildrentypedotted_as_namesappend_childr   parentindeximport_namesimple_stmtinsert_childr   )r   noderesultsr   r   callnamescontaining_stmtpositionstmt_container
new_importnewr   r   r   	transform%   s6   



zFixExitfunc.transform)
__name__
__module____qualname__keep_line_orderBM_compatiblePATTERNr   r   r8   __classcell__r   r   r   r   r
      s    r
   N)__doc__lib2to3r   r   lib2to3.fixer_utilr   r   r   r   r   r	   BaseFixr
   r   r   r   r   <module>   s     