a 97a@svdZddlmZmZmZddlZddlZddlZddlm Z m Z m Z ddl m Z ddlmZddlmZd dd Z dS) a pasteurize: automatic conversion of Python 3 code to clean 2/3 code =================================================================== ``pasteurize`` attempts to convert existing Python 3 code into source-compatible Python 2 and 3 code. Use it like this on Python 3 code: $ pasteurize --verbose mypython3script.py This removes any Py3-only syntax (e.g. new metaclasses) and adds these import lines: from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals from future import standard_library standard_library.install_hooks() from builtins import * To write changes to the files, use the -w flag. It also adds any other wrappers needed for Py2/3 compatibility. Note that separate stages are not available (or needed) when converting from Python 3 with ``pasteurize`` as they are when converting from Python 2 with ``futurize``. The --all-imports option forces adding all ``__future__`` imports, ``builtins`` imports, and standard library aliases, even if they don't seem necessary for the current state of each module. (This can simplify testing, and can reduce the need to think about Py2 compatibility when editing the code further.) )absolute_importprint_functionunicode_literalsN)mainwarnStdoutRefactoringTool)refactor) __version__) fix_namescsttjdd}|jddddd|jdd dd d|jd d d gdd|jddddddd|jddd gdd|jddddd|jddddd|jd dd!d|jd"d#dd$d|jd%d&dd'd(dd'}i}||\}}d)}t}d*|d+<|js|jrtd,|js |jr | d-|j r4t t d.S|j rft d/t|D]}t |qL|sfd.S|st d0tjd1t d2tjd1d3Sd4|vrd*}|jrt d5tjd1d3S|jrtjntj}tjd6|d7t} |jD]d8vr| nxfd9d:|D} t| dkrDt d;d<d=d>| Dtjd1d3St| d.krft d?tjd1d3S| | d.qt} |jrd@} | | dA| | dB| | dCt} |jrd'}|jD]dDkrd*}nd8vr| nxfdEd:|D} t| dkr>t d;d<dFd>| Dtjd1d3St| d.kr`t d?tjd1d3S| | d.qt| | @d.krt dGd<dHd>| | @Dtjd1d3S|r|| n| }n || }|| | B}tt||t|j|j }|jsf|r| nPz|!||jdI|j"Wn6t!j#y\|j"dksHJt dJtjd1YdS0|$t%t&|jS)KzBMain program. Returns a suggested exit status (0, 1, 2). z!pasteurize [options] file|dir ...)usagez-Vz --version store_truez'Report the version number of pasteurize)actionhelpz-az --all-importsz5Adds all __future__ and future imports to each modulez-fz--fixappendz1Each FIX specifies a transformation; default: all)r defaultrz-jz --processesstoreintzRun 2to3 concurrently)r rtyperz-xz--nofixzPrevent a fixer from being run.z-lz --list-fixeszList available transformationsz-vz --verbosezMore verbose loggingz --no-diffsz#Don't show diffs of the refactoringz-wz--writezWrite back modified filesz-nz --nobackupsFz'Don't write backups for modified files.zlibpasteurize.fixesTrz@not writing files and not printing diffs; that's not very usefulzCan't use -n without -wrz2Available transformations for the -f/--fix option:z1At least one file or directory argument required.)filezUse --help to show usage.-zCan't write to stdin.z%(name)s: %(message)s)formatlevelz.fix_cs g|]}|dr|qSzfix_{0}endswithr.0ffixm/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/lib/python/libpasteurize/main.py }szmain..zOAmbiguous fixer name. Choose a fully qualified module name instead from these:  css|]}d|VqdSz Nr"rZmyfr"r"r# zmain..z1Unknown fixer. Use --list-fixes or -l for a list.zlibpasteurize.fixes.Zfix_add_all__future__importsZ&fix_add_future_standard_library_importZfix_add_all_future_builtinsallcs g|]}|dr|qSrrrr r"r#r$scss|]}d|VqdSr&r"r'r"r"r#r(r)z[Conflicting usage: the following fixers have been simultaneously requested and disallowed: css|]}d|VqdSr&r"r'r"r"r#r(r)Nz+Sorry, -j isn't supported on this platform.)'optparse OptionParser add_option parse_argsr writeZno_diffsrZ nobackupserrorversionprintr Z list_fixessortedsysstderrverboseloggingDEBUGINFO basicConfigsetZnofixaddlenjoinZ all_importsr!unionrerrorsrefactor_stdinrZ processesZMultiprocessingUnsupportedZ summarizerbool)argsparserrAflagsoptionsZ fixer_pkgZ avail_fixesZfixnamerZunwanted_fixesfoundZ extra_fixesprefixexplicitZ all_present requested fixer_namesrtr"r r#r3s                          r)N)__doc__ __future__rrrr4r7r+Z lib2to3.mainrrrZlib2to3rfuturer Zlibpasteurize.fixesr r"r"r"r#s&