/usr/lib64/python3.9/lib2to3/__pycache__
Edit: /usr/lib64/python3.9/lib2to3/__pycache__/main.cpython-39.pyc (8689B)
a
´iN. ã @ s€ d Z ddlmZmZ ddlZddlZddlZddlZddlZddl Z ddl
mZ dd„ ZG dd „ d ej
ƒZd
d„ Zddd
„ZdS )z
Main program for 2to3.
é )Úwith_statementÚprint_functionNé )Úrefactorc C s( | ¡ } | ¡ }tj| |||dddd�S )z%Return a unified diff of two strings.z
(original)z(refactored)Ú )Zlineterm)Ú
splitlinesÚdifflibZunified_diff)ÚaÚbÚfilename© r ú$/usr/lib64/python3.9/lib2to3/main.pyÚ
diff_texts s þr c s> e Zd ZdZd‡ fdd„ Zdd„ Z‡ fdd„Zd d
„ Z‡ ZS )Ú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 sP || _ || _|r&| tj¡s&|tj7 }|| _|| _|| _tt | ƒ
|||¡ dS )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__) ÚselfZfixersÚoptionsÚexplicitr r Úinput_base_dirÚ
output_dirÚ
append_suffix©Ú __class__r r
r $ s
zStdoutRefactoringTool.__init__c O s0 | j |||f¡ | jj|g|¢R i |¤Ž d S )N)ÚerrorsÚappendÚloggerÚerror)r ÚmsgÚargsÚkwargsr r r
Ú log_errorA s zStdoutRefactoringTool.log_errorc sZ |}| j rH| | j¡r6tj | j |t| jƒd … ¡}ntd|| jf ƒ‚| jrX|| j7 }||kr”tj |¡}tj
|¡s†|r†t |¡ | d||¡ | j
�s|d }tj |¡rÞzt |¡ W n tyÜ | d|¡ Y n0 zt ||¡ W n" t�y | d||¡ Y n0 tt| ƒj}|||||ƒ | j
�s@t ||¡ ||k�rVt ||¡ d S )Nz5filename %s does not start with the input_base_dir %szWriting converted %s to %s.z.bakzCan't remove backup %szCan'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 Znew_textr Zold_textÚencodingZ
orig_filenamer ZbackupÚwriter r r
r7 E sH
ÿÿÿ
ÿ
z StdoutRefactoringTool.write_filec C s¼ |r| d|¡ n¦| d|¡ | jr¸t|||ƒ}zd| jd ur€| j�, |D ]}t|ƒ qHtj ¡ W d ƒ q’1 st0 Y n|D ]}t|ƒ q„W n" ty¶ t d|f ƒ Y d S 0 d S )NzNo changes to %sz
Refactored %sz+couldn't encode %s's diff for your terminal)
r2 r r Zoutput_lockÚprintÚsysÚstdoutÚflushÚUnicodeEncodeErrorÚwarn)r ÚoldÚnewr ZequalZ
diff_linesÚliner r r
Úprint_outputl s$
*ÿz"StdoutRefactoringTool.print_output)r r r ) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r r) r7 rE Ú
__classcell__r r r r
r s
ÿ'r c C s t d| f tjd� d S )NzWARNING: %s©Úfile)r<