
    dsk                     @   d Z dZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZmZmZ ddlmZ ddlmZmZ dd	lmZ ddZ G d de          Zd Zd Zd Zd Zd Z G d de          Z G d de          Z  G d de          Z! G d de           Z"dS )zRefactoring framework.

Used as a main program, this can refactor any number of files and/or
recursively descend down directories.  Imported as a module, this
provides infrastructure to write your own refactoring tool.
z#Guido van Rossum <guido@python.org>    N)chain   )drivertokenizetoken)	find_root)pytreepygram)btm_matcherTc                     t          | g g dg          }g }t          j        |j                  D ]<\  }}}|                    d          r!|r
|dd         }|                    |           =|S )zEReturn a sorted list of all available fix names in the given package.*fix_   N)
__import__pkgutiliter_modules__path__
startswithappend)	fixer_pkgremove_prefixpkg	fix_namesfindernameispkgs          "  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/lib2to3/refactor.pyget_all_fix_namesr      s    
YB
.
.CI&3CLAA # #e??6"" 	#  ABBxT"""    c                       e Zd ZdS )
_EveryNodeN__name__
__module____qualname__ r   r   r!   r!   +           Dr   r!   c                    t          | t          j        t          j        f          r| j        t
          | j        hS t          | t          j                  r"| j        rt          | j                  S t
          t          | t          j	                  rAt                      }| j        D ])}|D ]$}|                    t          |                     %*|S t          d| z            )zf Accepts a pytree Pattern Node and returns a set
        of the pattern types which will match first. Nz$Oh no! I don't understand pattern %s)
isinstancer	   NodePatternLeafPatterntyper!   NegatedPatterncontent_get_head_typesWildcardPatternsetupdate	Exception)patrpxs       r   r/   r/   /   s     #*F,>?@@  8z#v,-- ; 	0"3;///#v-.. EE 	- 	-A - -++,,,,-
:SA
B
BBr   c                 Z   t          j        t                    }g }| D ]}|j        r[	 t	          |j                  }|D ]}||                             |           ?# t          $ r |                    |           Y `w xY w|j        !||j                                     |           |                    |           t          t          j
        j                                        t          j
        j                  D ]}||                             |           t          |          S )z^ Accepts a list of fixers and returns a dictionary
        of head node type --> fixer list.  )collectionsdefaultdictlistpatternr/   r   r!   _accept_typer   r
   python_grammarsymbol2numbervaluestokensextenddict)
fixer_list
head_nodeseveryfixerheads	node_types         r   _get_headnode_dictrJ   K   sL    (..JE $ $= 	$8'66 "' 8 8Iy)0077778  $ $ $U#####$ !-5-.55e<<<<U####60>EEGG!079 9 , ,	9$$U++++
s   AA?>A?c                 <      fdt           d          D             S )zN
    Return the fully qualified names for fixers in the package pkg_name.
    c                      g | ]
}d z   |z   S .r&   ).0fix_namepkg_names     r   
<listcomp>z+get_fixers_from_package.<locals>.<listcomp>h   s8     @ @ @ sNX% @ @ @r   F)r   )rQ   s   `r   get_fixers_from_packagerS   d   s@    @ @ @ @-h>>@ @ @ @r   c                     | S Nr&   )objs    r   	_identityrW   k   s    Jr   c                 h   d}t          j        t          j        |           j                  fd}t          t          j        t           j        t          j	        h          }t                      }	 	  |            \  }}||v r|t          j        k    r|rnd}n|t          j        k    r|dk    r |            \  }}|t          j        k    s|dk    rn |            \  }}|t          j        k    s|dk    rn |            \  }}|t          j        k    r|dk    r |            \  }}|t          j        k    rV|                    |            |            \  }}|t          j        k    s|dk    rn |            \  }}|t          j        k    Vnn n# t          $ r Y nw xY wt          |          S )	NFc                  B    t                    } | d         | d         fS )Nr   r   )next)tokgens    r   advancez(_detect_future_features.<locals>.advancer   s     3ii1vs1v~r   Tfrom
__future__import(,)r   generate_tokensioStringIOreadline	frozensetr   NEWLINENLCOMMENTr1   STRINGNAMEOPaddStopIteration)sourcehave_docstringr]   ignorefeaturestpvaluer\   s          @r   _detect_future_featuresrv   o   s   N

"2;v#6#6#?
@
@C     x{EMBCCFuuH			IBV||u|##! !%uz!!evoo#GII	E##u'<'<#GII	E##u'8'8#GII	E>>esll '		IBEJ&&LL''' '		IBUX~~# '		IB EJ&& 3	4    Xs   3D!F 
F"!F"c                       e Zd ZdZdS )
FixerErrorzA fixer could not be loaded.N)r#   r$   r%   __doc__r&   r   r   rx   rx      s        &&&&r   rx   c                       e Zd ZddddZdZdZddZd Zd Zd	 Z	d
 Z
d ZddZddZd ZddZd Zd dZd Zd Z	 	 d!dZd"dZdZdZd Zd Zd Zd Zd Zd ZdS )#RefactoringToolF)print_functionexec_functionwrite_unchanged_filesFixr   Nc                 P   || _         |pg | _        | j                                        | _        || j                            |           t          j                                        | _        | j        d         r| j        j	        d= n| j        d         r| j        j	        d= | j        
                    d          | _        g | _        t          j        d          | _        g | _        d| _        t%          j        | j        t(          j        | j        	          | _        |                                 \  | _        | _        g | _        t5          j                    | _        g | _        g | _        t?          | j        | j                  D ]k}|j         r| j        !                    |           $|| j        v r| j        "                    |           H|| j        v r| j        "                    |           ltG          | j                  | _$        tG          | j                  | _%        dS )
zInitializer.

        Args:
            fixer_names: a list of fixers to import
            options: a dict with configuration.
            explicit: a list of fixers to run even if they are explicit.
        Nr|   printr}   execr~   r{   F)convertlogger)&fixersexplicit_default_optionscopyoptionsr2   r
   r>   grammarkeywordsgetr~   errorslogging	getLoggerr   	fixer_logwroter   Driverr	   r   
get_fixers	pre_order
post_orderfilesbmBottomMatcherBMbmi_pre_orderbmi_post_orderr   BM_compatible	add_fixerr   rJ   bmi_pre_order_headsbmi_post_order_heads)selffixer_namesr   r   rG   s        r   __init__zRefactoringTool.__init__   s    " B,1133L(((,1133<() 	.%g..\/* 	.%f-
 &*\%5%56M%N%N"'(9::
mDL,2N+/;8 8 8 +///*;*;' 
"$$ 4?DN;; 	2 	2E" 2!!%(((( $.(("))%0000$/))#**5111#5d6H#I#I $6t7J$K$K!!!r   c                    g }g }| j         D ]}t          |i i dg          }|                    dd          d         }|                    | j                  r|t          | j                  d         }|                    d          }| j        d                    d |D                       z   }	 t          ||          }n$# t          $ r t          d	|d|          dw xY w || j        | j                  }	|	j        r*| j        d
ur!|| j        vr|                     d|           !|                     d|           |	j        dk    r|                    |	           Y|	j        dk    r|                    |	           {t          d|	j        z            t'          j        d          }
|                    |
           |                    |
           ||fS )a  Inspects the options to load the requested patterns and handlers.

        Returns:
          (pre_order, post_order), where pre_order is the list of fixers that
          want a pre-order AST traversal, and post_order is the list that want
          post-order traversal.
        r   rN   r   N_ c                 6    g | ]}|                                 S r&   )title)rO   r6   s     r   rR   z.RefactoringTool.get_fixers.<locals>.<listcomp>   s     5O5O5OAaggii5O5O5Or   zCan't find TzSkipping optional fixer: %szAdding transformation: %sprepostzIllegal fixer order: %r	run_orderkey)r   r   rsplitr   FILE_PREFIXlensplitCLASS_PREFIXjoingetattrAttributeErrorrx   r   r   r   log_message	log_debugorderr   operator
attrgettersort)r   pre_order_fixerspost_order_fixersfix_mod_pathmodrP   parts
class_name	fix_classrG   key_funcs              r   r   zRefactoringTool.get_fixers   s"     K 	J 	JL\2rC599C#**32226H""4#344 <#C(8$9$9$:$:;NN3''E*RWW5O5O5O5O5O-P-PPJX#C44		! X X X jxxx!LMMSWWXIdlDN;;E~ $-t";"; 55  !>IIINN6AAA{e## ''....&&!((//// !:U[!HIII&{33(+++8,,, "344s   1C!C#c                       )zCalled when an error occurs.r&   )r   msgargskwdss       r   	log_errorzRefactoringTool.log_error  s    r   c                 H    |r||z  }| j                             |           dS )zHook to log a message.N)r   infor   r   r   s      r   r   zRefactoringTool.log_message  s/     	*Cr   c                 H    |r||z  }| j                             |           d S rU   )r   debugr   s      r   r   zRefactoringTool.log_debug  s/     	*C#r   c                     dS )zTCalled with the old version, new version, and filename of a
        refactored file.Nr&   )r   old_textnew_textfilenameequals        r   print_outputzRefactoringTool.print_output  s	     	r   c                     |D ]P}t           j                            |          r|                     |||           9|                     |||           QdS )z)Refactor a list of files and directories.N)ospathisdirrefactor_dirrefactor_file)r   itemswritedoctests_onlydir_or_files        r   refactorzRefactoringTool.refactor  sn     ! 	F 	FKw}}[)) F!!+umDDDD"";}EEEE		F 	Fr   c                    t           j        dz   }t          j        |          D ]\  }}}|                     d|           |                                 |                                 |D ]w}|                    d          s`t           j                            |          d         |k    r7t           j                            ||          }	| 	                    |	||           xd |D             |dd<   dS )zDescends down a directory and refactor every Python file found.

        Python files are assumed to have a .py extension.

        Files and subdirectories starting with '.' are skipped.
        pyzDescending into %srN   r   c                 <    g | ]}|                     d           |S rM   )r   )rO   dns     r   rR   z0RefactoringTool.refactor_dir.<locals>.<listcomp>2  s)    KKK"c8J8JK2KKKr   N)
r   extsepwalkr   r   r   r   splitextr   r   )
r   dir_namer   r   py_extdirpathdirnames	filenamesr   fullnames
             r   r   zRefactoringTool.refactor_dir   s    T!,.GH,=,= 
	L 
	L(GXyNN/999MMOOONN! G G,, GG$$T**1-77!w||GT::H&&xFFFKKKKKHQQQKK
	L 
	Lr   c                    	 t          |d          }n/# t          $ r"}|                     d||           Y d}~dS d}~ww xY w	 t          j        |j                  d         }|                                 n# |                                 w xY wt          j         |d|d          5 }|                                |fcddd           S # 1 swxY w Y   dS )	zG
        Do our best to decode a Python source file correctly.
        rbzCan't open %s: %sNNNr   r5   r   encodingnewline)	openOSErrorr   r   detect_encodingrf   closerd   read)r   r   ferrr   s        r   _read_python_sourcez#RefactoringTool._read_python_source4  s"   	Xt$$AA 	 	 	NN.#>>>:::::		/
;;A>HGGIIIIAGGIIIIWXsXrBBB 	&a6688X%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s.    
?:?A7 7B(CCCc                    |                      |          \  }}|dS |dz  }|rl|                     d|           |                     ||          }| j        s||k    r|                     |||||           dS |                     d|           dS |                     ||          }| j        s	|r7|j        r0|                     t          |          dd         |||           dS |                     d|           dS )zRefactors a file.N
zRefactoring doctests in %szNo doctest changes in %sr   )r   r   zNo changes in %s)r   r   refactor_docstringr~   processed_filerefactor_stringwas_changedstr)r   r   r   r   inputr   outputtrees           r   r   zRefactoringTool.refactor_fileD  s@   228<<x=F 	=NN7BBB,,UH==F) EVu__##FHeUHMMMMM98DDDDD''x88D) =d =t7G =##CIIcrcNH*/( $ D D D D D 18<<<<<r   c                    t          |          }d|v rt          j        | j        _        	 | j                            |          }nK# t          $ r>}|                     d||j        j	        |           Y d}~| j        | j        _        dS d}~ww xY w	 | j        | j        _        n# | j        | j        _        w xY w||_
        |                     d|           |                     ||           |S )aF  Refactor a given input string.

        Args:
            data: a string holding the code to be refactored.
            name: a human-readable name for use in error/log messages.

        Returns:
            An AST corresponding to the refactored input stream; None if
            there were errors during the parse.
        r|   zCan't parse %s: %s: %sNzRefactoring %s)rv   r
   !python_grammar_no_print_statementr   r   parse_stringr3   r   	__class__r#   future_featuresr   refactor_tree)r   datar   rs   r  r   s         r   r   zRefactoringTool.refactor_string[  s
    +400x''"("JDK	/;++D11DD 	 	 	NN3!7> > >FFF"&,DK	  #',DK$,DK....''...4&&&s/   A B$ 
B"B	2B$ 	BB$ $B7c                    t           j                                        }|rh|                     d           |                     |d          }| j        s||k    r|                     |d|           d S |                     d           d S |                     |d          }| j        s	|r-|j        r&|                     t          |          d|           d S |                     d           d S )NzRefactoring doctests in stdinz<stdin>zNo doctest changes in stdinzNo changes in stdin)
sysstdinr   r   r   r~   r   r   r   r   )r   r   r  r  r  s        r   refactor_stdinzRefactoringTool.refactor_stdinv  s    	   	6NN:;;;,,UI>>F) >Vu__##FIu=====<=====''y99D) 6d 6t7G 6##CIIy%@@@@@455555r   c                    t          | j        | j                  D ]}|                    ||           |                     | j        |                                           |                     | j        |                                           | j                            |	                                          }t          |                                          r| j        j        D ]}||v r||         r||                             t          j        j        d           |j        r+||                             t          j        j                   t'          ||                   D ]8}|||         v r||                             |           	 t+          |           n# t,          $ r Y Ew xY w|j        r
||j        v rZ|                    |          }|r|                    ||          }||                    |           |                                D ]*}|j        sg |_        |j                            |           +| j                            |	                                          }|D ],}	|	|vrg ||	<   ||	                             ||	                    -:t          |                                          t          | j        | j                  D ]}|                    ||           |j        S )a  Refactors a parse tree (modifying the tree in place).

        For compatible patterns the bottom matcher module is
        used. Otherwise the tree is traversed node-to-node for
        matches.

        Args:
            tree: a pytree.Node instance representing the root of the tree
                  to be refactored.
            name: a human-readable name for this tree.

        Returns:
            True if the tree was modified, False otherwise.
        T)r   reverser   )r   r   r   
start_treetraverse_byr   r   r   runleavesanyr@   r   r   r	   Basedepthkeep_line_order
get_linenor;   remover   
ValueErrorfixers_appliedmatch	transformreplacer   rB   finish_treer   )
r   r  r   rG   	match_setnoderesultsnewnew_matchesfxrs
             r   r	  zRefactoringTool.refactor_tree  s%     4>4?;; 	) 	)ET4(((( 	14>>3C3CDDD2DOO4E4EFFF GKK..	)""$$%% /	L .L .LI%%)E*:%e$))fk.?)NNN, J "%(--&+2H-III $Yu%5 6 6 $L $L9U#333%e,33D999%%dOOOO) % % % %H%
  . %5D<O3O3O$"'++d"3"3" L"'//$"@"@C" $S 1 1 1,/NN,<,< !F !FD ,0+> %A>@(;$($7$>$>u$E$E$E$E /3gkk#**,,.G.G+6 !L !LC+.)+;+;79	#$-cN$9$9+c:J$K$K$K$K_ )""$$%% /	Lb 4>4?;; 	* 	*EdD))))s   F%%
F21F2c                     |sdS |D ]X}||j                  D ]H}|                    |          }|r/|                    ||          }||                    |           |}IYdS )a  Traverse an AST, applying a set of fixers to each node.

        This is a helper method for refactor_tree().

        Args:
            fixers: a list of fixer instances.
            traversal: a generator that yields AST nodes.

        Returns:
            None
        N)r,   r  r  r  )r   r   	traversalr"  rG   r#  r$  s          r   r  zRefactoringTool.traverse_by  s      	F 	# 	#D	* # #++d++ #//$88CS)))"#	# 	#r   c                 ^   | j                             |           ||                     |          d         }|dS ||k    }|                     ||||           |r|                     d|           | j        sdS |r|                     ||||           dS |                     d|           dS )zR
        Called when a file has been refactored and there may be changes.
        Nr   zNo changes to %szNot writing changes to %s)r   r   r   r   r   r~   
write_file)r   r   r   r   r   r   r   s          r   r   zRefactoringTool.processed_file  s    
 	
(###//99!<HH$(Hh>>> 	NN-x888-  	BOOHh(CCCCCNN6AAAAAr   c                    	 t          j        |d|d          }n/# t          $ r"}|                     d||           Y d}~dS d}~ww xY w|5  	 |                    |           n.# t          $ r!}|                     d||           Y d}~nd}~ww xY wddd           n# 1 swxY w Y   |                     d|           d| _        dS )	zWrites a string to a file.

        It first shows a unified diff between the old text and the new text, and
        then rewrites the file; the latter is only done if the write option is
        set.
        wr   r   zCan't create %s: %sNzCan't write %s: %szWrote changes to %sT)rd   r   r   r   r   r   r   )r   r   r   r   r   fpr   s          r   r*  zRefactoringTool.write_file  sX   	32FFFBB 	 	 	NN0(C@@@FFFFF	  	D 	DD"""" D D D3XsCCCCCCCCD	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D
 	,h777


sP    
AAABA$#B$
B.B
B
BBB"%B"z>>> z... c           	         g }d}d}d}d}|                     d          D ])}|dz  }|                                                    | j                  rW|+|                    |                     ||||                     |}|g}|                    | j                  }	|d|	         }|V|                    || j        z             s#||| j                                        z   dz   k    r|	                    |           |+|                    |                     ||||                     d}d}|	                    |           +|+|                    |                     ||||                     d
                    |          S )a  Refactors a docstring, looking for doctests.

        This returns a modified version of the input string.  It looks
        for doctests, which start with a ">>>" prompt, and may be
        continued with "..." prompts, as long as the "..." is indented
        the same as the ">>>".

        (Unfortunately we can't use the doctest module's parser,
        since, like most parsers, it is not geared towards preserving
        the original source.)
        Nr   Tkeependsr   r   r   )
splitlineslstripr   PS1rB   refactor_doctestfindPS2rstripr   r   )
r   r  r   resultblockblock_linenoindentlinenolineis
             r   r   z"RefactoringTool.refactor_docstring  s    $$d$33 	$ 	$DaKF{{}}''11 $$MM$"7"7|8>#J #J K K K%IIdh''bqb$??6DH#455 %6DHOO$5$55<<<T""""$MM$"7"7|8>#J #J K K Kd####MM$//|06B B C C Cwwvr   c                     	                       ||          }n# t          $ r} j                            t          j                  r.|D ]+}                     d|                    d                     ,                     d|||j	        j
        |           |cY d}~S d}~ww xY w                     ||          rt          |                              d          }|d|dz
           ||dz
  d         }}	|	dg|dz
  z  k    s
J |	            |d                             d          s|dxx         dz  cc<    j        z   |                    d	          z   g}|r| fd
|D             z  }|S )zRefactors one doctest.

        A doctest is given as a block of lines, the first of which starts
        with ">>>" (possibly indented), while the remaining lines start
        with "..." (identically indented).

        z
Source: %sr   z+Can't parse docstring in %s line %s: %s: %sNTr/  r   r   r   c                 *    g | ]}j         z   |z   S r&   )r6  )rO   r=  r;  r   s     r   rR   z4RefactoringTool.refactor_doctest.<locals>.<listcomp>^  s%    CCCt&48+d2CCCr   )parse_blockr3   r   isEnabledForr   DEBUGr   r7  r   r  r#   r	  r   r1  endswithr3  pop)
r   r9  r<  r;  r   r  r   r=  r$  clippeds
   `  `      r   r4  z RefactoringTool.refactor_doctestD  s   	##E66::DD 	 	 	{''66 D! D DDNN<T1B1BCCCCNNH#VS]-CSJ J JLLLLLL	 dH-- 		Dd))&&&55Cyqy>3vaxyy>SGtfq11117111r7##D))  B4dh&34E DCCCCCsCCCCs    
B'A6B"B'"B'c                 6   | j         rd}nd}| j        s|                     d|           n5|                     d|           | j        D ]}|                     |           | j        r4|                     d           | j        D ]}|                     |           | j        rut          | j                  dk    r|                     d           n(|                     dt          | j                             | j        D ]\  }}} | j        |g|R i | d S d S )	Nwerez
need to bezNo files %s modified.zFiles that %s modified:z$Warnings/messages while refactoring:r   zThere was 1 error:zThere were %d errors:)r   r   r   r   r   r   )r   rH  filemessager   r   r   s          r   	summarizezRefactoringTool.summarizea  sk   : 	 DDDz 	'4d;;;;6===
 ' '  &&&&> 	*CDDD> * *  )))); 	54;1$$  !56666  !8#dk:J:JKKK#'; 5 5T4  4t444t4444	5 	5
5 5r   c                     | j                             |                     |||                    }t                      |_        |S )zParses a block into a tree.

        This is necessary to get correct line number / offset information
        in the parser diagnostics and embedded into the parse tree.
        )r   parse_tokens	wrap_toksrg   r  )r   r9  r<  r;  r  s        r   rA  zRefactoringTool.parse_blockx  s:     {''uff(M(MNN({{r   c              #      K   t          j        |                     ||          j                  }|D ]+\  }}\  }}\  }	}
}||dz
  z  }|	|dz
  z  }	||||f|	|
f|fV  ,dS )z;Wraps a tokenize stream to systematically modify start/end.r   N)r   rc   	gen_lines__next__)r   r9  r<  r;  rA   r,   ru   line0col0line1col1	line_texts               r   rN  zRefactoringTool.wrap_toks  s      )$..*G*G*PQQDJ 	G 	G@D%%yVaZEVaZE t}udmYFFFFF	G 	Gr   c              #     K   || j         z   }|| j        z   }|}|D ]h}|                    |          r|t          |          d         V  n5||                                dz   k    rdV  nt          d|d|          |}i	 dV  )zGenerates lines as expected by tokenize from a list of lines.

        This strips the first len(indent + self.PS1) characters off each line.
        Nr   zline=z	, prefix=Tr   )r3  r6  r   r   r7  AssertionError)r   r9  r;  prefix1prefix2prefixr=  s          r   rP  zRefactoringTool.gen_lines  s      
 48#48# 	 	Dv&& L3v;;<<(((((4///



$nTTT66%JKKKFF	HHH	r   r   )FF)F)NFNrU   )r#   r$   r%   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r   r*  r3  r6  r   r4  rK  rA  rN  rP  r&   r   r   r{   r{      s       +0).279 9 LK3L 3L 3L 3Ln&5 &5 &5P      
  
F F F FL L L L(& & & = = = =.  66 6 6 6 M  M  M ^# # #. GL $B B B B*   * C
C) ) )V  :5 5 5.  G G G    r   r{   c                       e Zd ZdS )MultiprocessingUnsupportedNr"   r&   r   r   r]  r]    r'   r   r]  c                   B     e Zd Z fdZ	 	 d fd	Z fdZ fdZ xZS )MultiprocessRefactoringToolc                 d     t          t          |           j        |i | d | _        d | _        d S rU   )superr_  r   queueoutput_lockr   r   kwargsr  s      r   r   z$MultiprocessRefactoringTool.__init__  s;    9)40094J6JJJ
r   Fr   c                     |dk    r*t          t                                         |||          S 	 dd ln# t          $ r t
          w xY w j        t          d                                           _        	                                 _
         fdt          |          D             }	 |D ]}|                                 t          t                                         |||            j                                         t          |          D ]} j                            d            |D ]*}|                                r|                                 +d  _        d S #  j                                         t          |          D ]} j                            d            |D ]*}|                                r|                                 +d  _        w xY w)Nr   r   z already doing multiple processesc                 F    g | ]}                     j                   S ))target)Process_child)rO   r>  multiprocessingr   s     r   rR   z8MultiprocessRefactoringTool.refactor.<locals>.<listcomp>  s<     4 4 4 %,,DK,@@ 4 4 4r   )ra  r_  r   rk  ImportErrorr]  rb  RuntimeErrorJoinableQueueLockrc  rangestartr   putis_alive)
r   r   r   r   num_processes	processesr6   r>  rk  r  s
   `       @r   r   z$MultiprocessRefactoringTool.refactor  s/   A4d;;DDum- - -	-""""" 	- 	- 	-,,	-:!ABBB$2244
*//114 4 4 4 4#M224 4 4		  				-t44==eU>KM M M JOO=)) % %
t$$$$  ::<< FFHHHDJJJ JOO=)) % %
t$$$$  ::<< FFHHHDJs   : A4AE2 2A;G-c                 4   | j                                         }|{|\  }}	  t          t          |           j        |i | | j                                          n# | j                                          w xY w| j                                         }|yd S d S rU   )rb  r   ra  r_  r   	task_done)r   taskr   re  r  s       r   rj  z"MultiprocessRefactoringTool._child  s    z~~LD&'F1488F%#% % % 
$$&&&&
$$&&&&:>>##D s    A A8c                     | j         | j                             ||f           d S  t          t          |           j        |i |S rU   )rb  rr  ra  r_  r   rd  s      r   r   z)MultiprocessRefactoringTool.refactor_file  sV    :!JNND&>*****I54d;;I!! ! !r   )FFr   )r#   r$   r%   r   r   rj  r   __classcell__)r  s   @r   r_  r_    s                 
 :?      :	$ 	$ 	$ 	$ 	$! ! ! ! ! ! ! ! !r   r_  )T)#ry   
__author__rd   r   r   r  r   r   r9   	itertoolsr   pgen2r   r   r   
fixer_utilr   r   r	   r
   r   r   r   r3   r!   r/   rJ   rS   rW   rv   rx   objectr{   r]  r_  r&   r   r   <module>r     s    3
 
			 				  



             + * * * * * * * * * ! ! ! ! ! !              	 	 	 		 	 	 	 	 	 	 	C C C8  2@ @ @  % % %P' ' ' ' ' ' ' 'F F F F Ff F F FR	 	 	 	 	 	 	 	4! 4! 4! 4! 4!/ 4! 4! 4! 4! 4!r   