ofc@sdZddlmZddlZddlZddlZddlZddlZddlZddl m Z dZ de j fdYZ d Zdd ZdS( s Main program for 2to3. i(twith_statementNi(trefactorc Cs:|j}|j}tj||||ddddS(s%Return a unified diff of two strings.s (original)s (refactored)tlinetermt(t splitlinestdifflibt unified_diff(tatbtfilename((s$/usr/lib64/python2.7/lib2to3/main.pyt diff_textss    tStdoutRefactoringToolcBs;eZdZddddZdZdZdZRS(s2 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. Rc Csv||_||_|r;|jtj r;|tj7}n||_||_||_tt |j |||dS(sF 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( t nobackupst show_diffstendswithtostsept_input_base_dirt _output_dirt_append_suffixtsuperR t__init__( tselftfixerstoptionstexplicitR R tinput_base_dirt output_dirt append_suffix((s$/usr/lib64/python2.7/lib2to3/main.pyR$s     cOs3|jj|||f|jj|||dS(N(terrorstappendtloggerterror(Rtmsgtargstkwargs((s$/usr/lib64/python2.7/lib2to3/main.pyt log_errorAsc Cs|}|jre|j|jrItjj|j|t|j}qetd||jfn|jr~||j7}n||krtjj |}tjj |stj |n|j d||n|j sy|d}tjj|r6ytj|Wq6tjk r2}|j d|q6Xnytj||Wqytjk ru}|j d||qyXntt|j} | |||||j stj||n||krtj||ndS(Ns5filename %s does not start with the input_base_dir %ssWriting converted %s to %s.s.baksCan't remove backup %ssCan't rename %s to %s(Rt startswithRRtpathtjointlent ValueErrorRtdirnametisdirtmakedirst log_messageR tlexiststremoveR trenameRR t write_filetshutiltcopymode( Rtnew_textR told_texttencodingt orig_filenameRtbackupterrtwrite((s$/usr/lib64/python2.7/lib2to3/main.pyR1Es@         cCs|r|jd|n|jd||jrt|||}y_|jdk r|j(x|D] }|GHqgWtjjWdQXnx|D] }|GHqWWqtk rt d|fdSXndS(NsNo changes to %ss Refactored %ss+couldn't encode %s's diff for your terminal( R-R R t output_locktNonetsyststdouttflushtUnicodeEncodeErrortwarn(RtoldtnewR tequalt diff_linestline((s$/usr/lib64/python2.7/lib2to3/main.pyt print_outputls"        (t__name__t __module__t__doc__RR$R1RG(((s$/usr/lib64/python2.7/lib2to3/main.pyR s   'cCstjd|fIJdS(Ns WARNING: %s(R=tstderr(R!((s$/usr/lib64/python2.7/lib2to3/main.pyRAscstjdd}|jdddddd|jd d dd d gdd |jddddd ddddd|jdddd d gdd|jdddddd|jdddddd|jdddddd |jd!dddd"|jd#d$dddd%|jd&d'ddd tdd(|jd)d*dddd+d d,dd-|jd.d/dddd0|jd1dddd+d d,dd2t}i}|j|\}}|jrt|d3<|jstd4nt|_n|j r'|j r'|j d5n|j rJ|j rJ|j d6n|j rj|j rjtd7n|j r|j r|j d8n|jrd9GHxtjD] }|GHqW|sd:Sn|stjd;IJtjd<IJd=Sd>|krt}|jrtjd?IJd=Sn|jr0t|d@stalls.fix_s7Output in %r will mirror the input directory %r layout.RRRs+Sorry, -j isn't supported on this platform.(5toptparset OptionParsert add_optiontFalset parse_argsRUtTrueR:RARR R t add_suffixtno_diffst list_fixesRtget_all_fix_namesR=RKRWtverbosetloggingtDEBUGtINFOt basicConfigt getLoggertsettget_fixers_from_packagetnofixR[taddtuniont differenceRR&t commonprefixRRR+R*trstriptinfoR tsortedRtrefactor_stdint doctests_onlyt processestMultiprocessingUnsupportedtAssertionErrort summarizeRStbool(R\R"tparserRxtflagsRtfixnameRYRt avail_fixestunwanted_fixesRt all_presentR[t requestedt fixer_namesRtrt((R\s$/usr/lib64/python2.7/lib2to3/main.pytmains                              (RJt __future__RR=RRRiR2R^RRR tMultiprocessRefactoringToolR RAR<R(((s$/usr/lib64/python2.7/lib2to3/main.pyts       h