
    dN.                         d Z ddlmZm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 Z G d dej                  Zd	 Zdd
ZdS )z
Main program for 2to3.
    )with_statementprint_functionN   )refactorc           	          |                                  } |                                 }t          j        | |||ddd          S )z%Return a unified diff of two strings.z
(original)z(refactored) )lineterm)
splitlinesdifflibunified_diff)abfilenames        /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/main.py
diff_textsr      sF    	A	A1h ,n)+- - - -    c                   <     e Zd ZdZ	 d fd	Zd Z fdZd Z xZS )StdoutRefactoringToola2  
    A refactoring tool that can avoid overwriting its input files.
    Prints output to stdout.

    Output files can optionally be written to a different directory and or
    have an extra file suffix appended to their name for use in situations
    where you do not want to replace the input files.
    r   c	                    || _         || _        |r.|                    t          j                  s|t          j        z  }|| _        || _        || _        t          t          |           
                    |||           dS )aF  
        Args:
            fixers: A list of fixers to import.
            options: A dict with RefactoringTool configuration.
            explicit: A list of fixers to run even if they are explicit.
            nobackups: If true no backup '.bak' files will be created for those
                files that are being refactored.
            show_diffs: Should diffs of the refactoring be printed to stdout?
            input_base_dir: The base directory for all input files.  This class
                will strip this path prefix off of filenames before substituting
                it with output_dir.  Only meaningful if output_dir is supplied.
                All files processed by refactor() must start with this path.
            output_dir: If supplied, all converted files will be written into
                this directory tree instead of input_base_dir.
            append_suffix: If supplied, all files output by this tool will have
                this appended to their filename.  Useful for changing .py to
                .py3 for example by passing append_suffix='3'.
        N)	nobackups
show_diffsendswithossep_input_base_dir_output_dir_append_suffixsuperr   __init__)
selffixersoptionsexplicitr   r   input_base_dir
output_dirappend_suffix	__class__s
            r   r   zStdoutRefactoringTool.__init__$   s    ( #$ 	%."9"9"&"A"A 	%bf$N-%+#T**33FGXNNNNNr   c                 l    | j                             |||f            | j        j        |g|R i | d S N)errorsappendloggererror)r    msgargskwargss       r   	log_errorzStdoutRefactoringTool.log_errorA   sJ    Cv.///#/////////r   c                    |}| j         rt|                    | j                  r@t          j                            | j         |t          | j                  d                    }nt          d|d| j                  | j        r
|| j        z  }||k    rkt          j        	                    |          }t          j        
                    |          s|rt          j        |           |                     d||           | j        s|dz   }t          j                            |          r<	 t          j        |           n&# t           $ r |                     d|           Y nw xY w	 t          j        ||           n'# t           $ r |                     d||           Y nw xY wt%          t&          |           j        } |||||           | j        st+          j        ||           ||k    rt+          j        ||           d S d S )Nz	filename z( does not start with the input_base_dir zWriting converted %s to %s.z.bakzCan't remove backup %szCan't rename %s to %s)r   
startswithr   r   pathjoinlen
ValueErrorr   dirnameisdirmakedirslog_messager   lexistsremoveOSErrorrenamer   r   
write_fileshutilcopymode)
r    new_textr   old_textencodingorig_filenamer%   backupwriter'   s
            r   r@   z StdoutRefactoringTool.write_fileE   sd     	J""4#788 J7<<(8(0T5I1J1J1K1K(LN N !j)143G3G"I J J J  	,++HH$$22J7==,, ( (J''':M%' ' '~ 	L&Fwv&& GGIf%%%% G G G$$%=vFFFFFGL	(F++++ L L L  !8(FKKKKKL +T22=h(H555~ 	.OFH---H$$OM844444 %$s$   -E  E%$E%)E? ?!F#"F#c                    |r|                      d|           d S |                      d|           | j        rt          |||          }	 | j        U| j        5  |D ]}t	          |           t
          j                                         d d d            n# 1 swxY w Y   d S d S |D ]}t	          |           d S # t          $ r t          d|d           Y d S w xY wd S )NzNo changes to %szRefactored %szcouldn't encode z's diff for your terminal)
r;   r   r   output_lockprintsysstdoutflushUnicodeEncodeErrorwarn)r    oldnewr   equal
diff_lineslines          r   print_outputz"StdoutRefactoringTool.print_outputl   s|    	/:::::_h777 'S(;;
'3!- / /(2 , , %dJ,,.../ / / / / / / / / / / / / / / / / / /
 %/ ( (D!$KKKK( ()   D"((% & & &FF s<   
B< 3BB< BB< BB< &B< <CC)r   r   r   )	__name__
__module____qualname____doc__r   r1   r@   rV   __classcell__)r'   s   @r   r   r      s          BDO O O O O O:0 0 0%5 %5 %5 %5 %5N      r   r   c                 B    t          d| t          j                   d S )Nz	WARNING: file)rK   rL   stderr)r.   s    r   rP   rP      s$    	E33
 sz222222r   c           
          t          j        d          }|                    dddd           |                    dd	d
g d           |                    dddddd           |                    ddd
g d           |                    dddd           |                    dddd           |                    dddd           |                    d d!dd"           |                    d#dd$           |                    d%d&dd'           |                    d(d)dd*d+           |                    d,d-dd.d/d01           |                    d2d3dd4           |                    d5dd.d/d61           d*}i }|                    |          \  }}|j        r"d7|d8<   |j        st          d9           d7|_        |j        r|j        s|	                    d:           |j
        r|j        s|	                    d;           |j        s|j        rt          d<           |j        s|j        r|	                    d=           |j        r9t          d>           t          j                   D ]}t          |           |sd?S |s8t          d@t           j        A           t          dBt           j        A           dCS dD|v r&d7}|j        rt          dEt           j        A           dCS |j        rd7|dF<   |j        rd7|dG<   |j        rt*          j        nt*          j        }t+          j        dH|I           t+          j        dJ          }t5          t          j                             }	t5           fdK|j        D                       }
t5                      }|j        rJd*}|j        D ]&}|dLk    rd7}|                     dMz   |z              '|r|	                    |          n|}n|	                    |          }|                     |
          }tB          j"        #                    |          }|r]|$                    tB          j%                  s>tB          j"        &                    |          stB          j"        '                    |          }|j        r;|(                    tB          j%                  }|)                    dN|j        |           tU          tW          |          |tW          |          |j        |j         ||j        |j
        O          }|j,        s|r|-                                 ng	 |                    ||j        |j.        |j/                   n># t          j0        $ r, |j/        dk    sJ t          dPt           j        A           Y dS w xY w|1                                 te          tg          |j,                            S )QzMain program.

    Args:
        fixer_pkg: the name of a package where the fixers are located.
        args: optional; a list of command line arguments. If omitted,
              sys.argv[1:] is used.

    Returns a suggested exit status (0, 1, 2).
    z2to3 [options] file|dir ...)usagez-dz--doctests_only
store_truezFix up doctests only)actionhelpz-fz--fixr+   z1Each FIX specifies a transformation; default: all)rc   defaultrd   z-jz--processesstorer   intzRun 2to3 concurrently)rc   re   typerd   z-xz--nofixz'Prevent a transformation from being runz-lz--list-fixeszList available transformationsz-pz--print-functionz0Modify the grammar so that print() is a functionz-ez--exec-functionz/Modify the grammar so that exec() is a functionz-vz	--verbosezMore verbose loggingz
--no-diffsz#Don't show diffs of the refactoringz-wz--writezWrite back modified filesz-nz--nobackupsFz&Don't write backups for modified filesz-oz--output-dirstrr   zXPut output files in this directory instead of overwriting the input files.  Requires -n.)rc   rh   re   rd   z-Wz--write-unchanged-fileszYAlso write files even if no changes were required (useful with --output-dir); implies -w.z--add-suffixzuAppend this string to all output filenames. Requires -n if non-empty.  ex: --add-suffix='3' will generate .py3 files.Twrite_unchanged_filesz&--write-unchanged-files/-W implies -w.z%Can't use --output-dir/-o without -n.z"Can't use --add-suffix without -n.z@not writing files and not printing diffs; that's not very usefulzCan't use -n without -wz2Available transformations for the -f/--fix option:r   z1At least one file or directory argument required.r]   zUse --help to show usage.   -zCan't write to stdin.r   exec_functionz%(name)s: %(message)s)formatlevelzlib2to3.mainc              3   (   K   | ]}d z   |z   V  dS ).fix_N ).0fix	fixer_pkgs     r   	<genexpr>zmain.<locals>.<genexpr>   s-      LLsW,s2LLLLLLr   allrq   z7Output in %r will mirror the input directory %r layout.)r$   r%   r&   z+Sorry, -j isn't supported on this platform.)4optparseOptionParser
add_option
parse_argsrj   rH   rP   r%   r   r-   
add_suffixno_diffs
list_fixesrK   r   get_all_fix_namesrL   r_   r   rm   verboseloggingDEBUGINFObasicConfig	getLoggersetget_fixers_from_packagenofixrt   addunion
differencer   r4   commonprefixr   r   r9   r8   rstripinfor   sortedr*   refactor_stdindoctests_only	processesMultiprocessingUnsupported	summarizerg   bool)ru   r/   parserr   flagsr"   fixnamero   r,   avail_fixesunwanted_fixesr#   all_presentrt   	requestedfixer_namesr$   rts   `                 r   mainr      s!    ")FGGGF
d-l1  3 3 3
dGHbN  P P P
dM'1 '>  @ @ @
dIhD  F F F
dN<;  = = =
d.|M  O O O
d-lL  N N N
dK1  3 3 3
l<@  B B B
dIl6  8 8 8
dM,C  E E E
dN7  (N  O O O d5lA  B B B nW5"G  H H H NE%%d++MGT$ )-%&} 	;9:::  >'"3 ><=== ;'"3 ;9:::= QW- QOPPP= 0W. 0./// BCCC1)<< 	 	G'NNNN 	1 A
SSSS)
;;;;q
d{{= 	)
;;;;1 '"& &!%o %_>GMM',E6eDDDD~..F h6yAABBKLLLLgmLLLLLNuuH{ 	0; 	8 	8Ce||"Y03677773>LK%%h///H		%%h//	&&~66KW))$//N 9~66rv>> 9n--9
 88 8'..rv66M&	8 	8 	8	;x(8(87#33))!,
. 
. 
.B 9  
	D'-1F#-/ / / /6   (1,,,,C:' ' ' 'qq	
 	 tBIs   ;'U# #7VVr)   )rZ   
__future__r   r   rL   r   r   r   rA   rx   r   r   r   MultiprocessRefactoringToolr   rP   r   rr   r   r   <module>r      s     6 5 5 5 5 5 5 5 



 				          - - -e e e e eH@ e e eN3 3 3L  L  L  L  L  L r   