Spade
Mini Shell
| Directory:~$ /proc/self/root/lib/python2.7/site-packages/libfuturize/ |
| [Home] [System Details] [Kill Me] |
�
,�]c@@s�dZddlmZmZmZddlZddlmZddlZddl Z ddl
Z
ddlZddlm
Z
mZddlmZddlmZmZmZmZdZdd �ZdS(
u�
futurize: automatic conversion to clean 2/3 code using ``python-future``
======================================================================
Like Armin Ronacher's modernize.py, ``futurize`` attempts to produce
clean
standard Python 3 code that runs on both Py2 and Py3.
One pass
--------
Use it like this on Python 2 code:
$ futurize --verbose mypython2script.py
This will attempt to port the code to standard Py3 code that also
provides Py2 compatibility with the help of the right imports from
``future``.
To write changes to the files, use the -w flag.
Two stages
----------
The ``futurize`` script can also be called in two separate stages. First:
$ futurize --stage1 mypython2script.py
This produces more modern Python 2 code that is not yet compatible with
Python
3. The tests should still run and the diff should be uncontroversial to
apply to
most Python projects that are willing to drop support for Python 2.5 and
lower.
After this, the recommended approach is to explicitly mark all strings that
must
be byte-strings with a b'' prefix and all text (unicode) strings
with a u''
prefix, and then invoke the second stage of Python 2 to 2/3 conversion
with::
$ futurize --stage2 mypython2script.py
Stage 2 adds a dependency on ``future``. It converts most remaining Python
2-specific code to Python 3 code and adds appropriate imports from
``future``
to restore Py2 support.
The command above leaves all unadorned string literals as native strings
(byte-strings on Py2, unicode strings on Py3). If instead you would like
all
unadorned string literals to be promoted to unicode, you can also pass this
flag:
$ futurize --stage2 --unicode-literals mypython2script.py
This adds the declaration ``from __future__ import unicode_literals`` to
the
top of each file, which implicitly declares all unadorned string literals
to be
unicode strings (``unicode`` on Py2).
All imports
-----------
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.)
i(tabsolute_importtprint_functiontunicode_literalsN(t__version__(twarntStdoutRefactoringTool(trefactor(tlib2to3_fix_names_stage1tlib2to3_fix_names_stage2tlibfuturize_fix_names_stage1tlibfuturize_fix_names_stage2ulibfuturize.fixescC@sO tjdd�}|jdddddd�|jd d
dddd�|jdd
dddd�|jdddddd�|jdddddd�|jdddddd�|jdddddgdd�|jdddddd
d!d"dd#�|jd$d%dddgdd&�|jd'd(dddd)�|jd*d+dddd,�|jd-d.dddd/�|jd0dddd1�|jd2d3dddd4�|jd5d6dddtdd7�|jd8d9ddd!d:dd;dd<�|jd=d>dddd?�|jd@ddd!d:dd;ddA�i}t}|j|�\}}|jr�t|dB<|js�tdC�nt|_n|j r�|j
r�|jdD�n|jr�|j
r�|jdE�n|jr�|j
r�tdF�n|jr|j
r|jdG�ndH|krNt}|jrNtdIdJtj�dKSn|jrdt|dL<n|jrvtjntj}tjdMdNdO|�tjdP�}|js�|jr�|jdkks�t�t|_n t|_t�}|js�|jr|jt�|jt
�n|js*|jrG|jt!�|jt"�n|j#r`|j$dQ�n|j%rwtt&�dRS|j'r�tdS�xt(|�D]}t|�q�W|s�dRSn|s�tdTdJtj�tdUdJtj�dKSt�} x�|j)D]�}
dV|
kr| j$|
�q�g|D]$}|j*dWj+|
��r$|^q$}t,|�d
kr�tdXdYj-dZ�|D��dJtj�dKSt,|�dRkr�td[dJtj�dKS| j$|dR�q�Wt�}
|j.r=|jrd\}|
j$|d]�q=d^}|
j$|d_�|
j$|d`�|
j$|da�nt�}|j/r�t}x�|j/D]�}
|
dbkrzt}q_dV|
kr�|j$|
�q_g|D]$}|j*dWj+|
��r�|^q�}t,|�d
krtdXdYj-dc�|D��dJtj�dKSt,|�dRkr0td[dJtj�dKS|j$|dR�q_Wt,|| @�dRkr�tdddYj-de�|| @D��dJtj�dKS|r�|j0|�n|}n|j0|�}||
B| }t1j2j3|�}|r|j*t1j4�rt1j2j5|�rt1j2j6|�}n|j rO|j7t1j4�}|j8df|j |�nt9j:j;rdi}n!i|jdg6|j dh6|di6}t<t(|�|t(|�|j
|j
|�}|j=s< |r�|j>�n`y |j?||jdk|j@�Wn=t?jAk
r. |j@d ks t�tdjdJtj�d
SX|jB�ntCtD|j=��S(lu�Main 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).
tusageufuturize [options] file|dir ...u-Vu --versiontactionu
store_truethelpu%Report the version number of
futurizeu-au
--all-importsu4Add all __future__ and future imports to each
moduleu-1u--stage1uZModernize Python 2 code only; no compatibility with
Python 3 (or dependency on ``future``)u-2u--stage2u^Take modernized
(stage1) code and add a dependency on ``future`` to provide Py3
compatibility.u-0u
--both-stagesuApply both stages 1 and
2u-uu--unicode-literalsu{Add ``from __future__ import unicode_literals``
to implicitly convert all unadorned string literals '' into
unicode stringsu-fu--fixuappendtdefaultu�Each FIX specifies a
transformation; default: all.
Either use '-f division -f metaclass' etc. or use the
fully-qualified module name: '-f lib2to3.fixes.fix_types -f
libfuturize.fixes.fix_unicode_keep_u'u-ju--processesustoreittypeuintuRun
2to3 concurrentlyu-xu--nofixuPrevent a fixer from being
run.u-lu--list-fixesuList available
transformationsu-pu--print-functionu0Modify the grammar so that print()
is a functionu-vu --verboseuMore verbose loggingu
--no-diffsu#Don't show diffs of the refactoringu-wu--writeuWrite
back modified filesu-nu--nobackupsu'Don't write backups for
modified files.u-ou--output-dirustruupPut output files in this directory
instead of overwriting the input files. Requires -n. For Python >= 2.7
only.u-Wu--write-unchanged-filesuYAlso write files even if no changes
were required (useful with --output-dir); implies
-w.u--add-suffixu�Append this string to all output filenames. Requires
-n if non-empty. For Python >= 2.7 only.ex: --add-suffix='3'
will generate .py3
files.uwrite_unchanged_filesu&--write-unchanged-files/-W implies
-w.u%Can't use --output-dir/-o without -n.u"Can't use
--add-suffix without -n.u@not writing files and not printing diffs;
that's not very usefuluCan't use -n without -wu-uCan't
write to stdin.tfileiuprint_functiontformatu%(name)s:
%(message)stlevelulibfuturize.mainu-libfuturize.fixes.fix_unicode_literals_importiu2Available
transformations for the -f/--fix option:u1At least one file or directory
argument required.uUse --help to show usage.u.fix_ufix_{0}uOAmbiguous
fixer name. Choose a fully qualified module name instead from these:
u
cs@s|]}d|VqdS(u
N((t.0tmyf((s4/usr/lib/python2.7/site-packages/libfuturize/main.pys <genexpr>�su1Unknown
fixer. Use --list-fixes or -l for a
list.ulibfuturize.fixes.u0fix_add__future__imports_except_unicode_literalsulibpasteurize.fixes.ufix_add_all__future__importsu&fix_add_future_standard_library_importufix_add_all_future_builtinsuallcs@s|]}d|VqdS(u
N((RR((s4/usr/lib/python2.7/site-packages/libfuturize/main.pys <genexpr>su[Conflicting
usage: the following fixers have been simultaneously requested and
disallowed:
cs@s|]}d|VqdS(u
N((RR((s4/usr/lib/python2.7/site-packages/libfuturize/main.pys <genexpr>su7Output
in %r will mirror the input directory %r layout.u
append_suffixu
output_diruinput_base_diru+Sorry, -j isn't supported on this
platform.N(EtoptparsetOptionParsert
add_optiontFalset
parse_argstwrite_unchanged_filestTruetwriteRt
output_dirt nobackupsterrort
add_suffixtno_diffstprinttsyststderrRtverbosetloggingtDEBUGtINFOtbasicConfigt getLoggertstage1tstage2tboth_stagestNonetAssertionErrortsettupdateRR RR
RtaddtversionRt
list_fixestsortedtnofixtendswithRtlentjointall_importstfixtuniontostpathtcommonprefixtseptisdirtdirnametrstriptinfotfuturetutilstPY26Rterrorstrefactor_stdinRt processestMultiprocessingUnsupportedt summarizetinttbool(targstparsertflagsRItoptionsRtloggertavail_fixestfixnametunwanted_fixesR;tftfoundtextra_fixestprefixtexplicittall_presentt requestedtfixer_namestinput_base_dirtextra_kwargstrt((s4/usr/lib/python2.7/site-packages/libfuturize/main.pytmainTs^
$
$
(t__doc__t
__future__RRRtfuture.utilsRERR#R&RR=tlib2to3.mainRRtlib2to3Rtlibfuturize.fixesRRR R
t fixer_pkgR.Rb(((s4/usr/lib/python2.7/site-packages/libfuturize/main.pyt<module>>s"