Your IP : 3.16.130.96


Current Path : /opt/alt/python37/lib/python3.7/site-packages/libfuturize/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/libfuturize/__pycache__/main.cpython-37.pyc

B

�A�[�5�@s�dZddlmZmZmZddlZddlmZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZddlmZddlmZmZmZmZdZdd	d
�ZdS)a�
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.)

�)�absolute_import�print_function�unicode_literalsN)�__version__)�warn�StdoutRefactoringTool)�refactor)�lib2to3_fix_names_stage1�lib2to3_fix_names_stage2�libfuturize_fix_names_stage1�libfuturize_fix_names_stage2zlibfuturize.fixescs�tjdd�}|jddddd�|jdd	dd
d�|jdddd
d�|jddddd�|jddddd�|jddddd�|jdddgdd�|jddddd d!d"�|jd#d$dgd%d�|jd&d'dd(d�|jd)d*dd+d�|jd,d-dd.d�|jd/dd0d�|jd1d2dd3d�|jd4d5dd6d7d�|jd8d9dd:d;d<d=�|jd>d?dd@d�|jdAdd:d;dBd=�i}d6}|�|�\}}|j�r�dC|dD<|j�s�tdE�dC|_|j�r�|j�s�|�	dF�|j
�r�|j�s�|�	dG�|j�s�|j�r�tdH�|j�s|j�r|�	dI�dJ|k�r(dC}|j�r(tdKt
jdL�dMS|j�r8dC|dN<|j�rFtjntj}tjdO|dP�t�dQ�}|j�st|j�r�|jdRk�s�t�d6|_ndC|_t�}|j�s�|j�r�|�t�|�t�|j�s�|j�r�|�t�|�t�|j �r�|�!dS�|j"�rtt#�dTS|j$�r<tdU�xt%|�D]}t|��q W|�s<dTS|�sbtdVt
jdL�tdWt
jdL�dMSt�}	x�|j&D]��dX�k�r�|	�!��nt�fdYdZ�|D�}
t'|
�dk�r�td[d\�(d]d^�|
D��t
jdL�dMSt'|
�dTk�r�td_t
jdL�dMS|	�!|
dT��qpWt�}|j)�r\|j�r.d`}|�!|da�n.db}|�!|dc�|�!|dd�|�!|de�t�}
|j*�rld6}x�|j*D]���dfk�r�dC}n�dX�k�r�|
�!��nt�fdgdZ�|D�}
t'|
�dk�r�td[d\�(dhd^�|
D��t
jdL�dMSt'|
�dTk�rtd_t
jdL�dMS|
�!|
dT��qvWt'|
|	@�dTk�rVtdid\�(djd^�|
|	@D��t
jdL�dMS|�rf|�+|
�n|
}n
|�+|
�}||B|	}t,j-�.|�}|�r�|�/t,j0��s�t,j-�1|��s�t,j-�2|�}|j�r�|�3t,j0�}|�4dk|j|�t5j6j7�r�i}n|j
|j|dl�}t8t%|�|t%|
�|j|jf|�}|j9�s�|�r:|�:�nPy|�;||jdR|j<�Wn6t;j=k
�r�|j<dk�svt�tdmt
jdL�dSX|�>�t?t@|j9��S)nz�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).
    zfuturize [options] file|dir ...)�usagez-Vz	--version�
store_truez%Report the version number of futurize)�action�helpz-az
--all-importsz4Add all __future__ and future imports to each modulez-1z--stage1zZModernize Python 2 code only; no compatibility with Python 3 (or dependency on ``future``)z-2z--stage2z^Take modernized (stage1) code and add a dependency on ``future`` to provide Py3 compatibility.z-0z
--both-stageszApply both stages 1 and 2z-uz--unicode-literalsz{Add ``from __future__ import unicode_literals`` to implicitly convert all unadorned string literals '' into unicode stringsz-fz--fix�appendz�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')r�defaultrz-jz--processes�store��intzRun 2to3 concurrently)rr�typerz-xz--nofixzPrevent a fixer from being run.z-lz--list-fixeszList available transformationsz-pz--print-functionz0Modify the grammar so that print() is a functionz-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.z-oz--output-dir�str�zpPut output files in this directory instead of overwriting the input files.  Requires -n. For Python >= 2.7 only.)rrrrz-Wz--write-unchanged-fileszYAlso write files even if no changes were required (useful with --output-dir); implies -w.z--add-suffixz�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.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 usefulzCan't use -n without -w�-zCan't write to stdin.)�file�rz%(name)s: %(message)s)�format�levelzlibfuturize.mainNz-libfuturize.fixes.fix_unicode_literals_importrz2Available transformations for the -f/--fix option:z1At least one file or directory argument required.zUse --help to show usage.z.fix_cs g|]}|�d����r|�qS)zfix_{0})�endswithr)�.0�f)�fix��A/opt/alt/python37/lib/python3.7/site-packages/libfuturize/main.py�
<listcomp>�szmain.<locals>.<listcomp>zOAmbiguous fixer name. Choose a fully qualified module name instead from these:
�
css|]}d|VqdS)z  Nr#)r �myfr#r#r$�	<genexpr>�szmain.<locals>.<genexpr>z1Unknown fixer. Use --list-fixes or -l for a list.zlibfuturize.fixes.Z0fix_add__future__imports_except_unicode_literalszlibpasteurize.fixes.Zfix_add_all__future__importsZ&fix_add_future_standard_library_importZfix_add_all_future_builtins�allcs g|]}|�d����r|�qS)zfix_{0})rr)r r!)r"r#r$r%�scss|]}d|VqdS)z  Nr#)r r'r#r#r$r(sz[Conflicting usage: the following fixers have been simultaneously requested and disallowed:
css|]}d|VqdS)z  Nr#)r r'r#r#r$r(sz7Output in %r will mirror the input directory %r layout.)Z
append_suffix�
output_dir�input_base_dirz+Sorry, -j isn't supported on this platform.)A�optparse�OptionParser�
add_option�
parse_argsr�writerr*Z	nobackups�errorZ
add_suffixZno_diffs�print�sys�stderrr�verbose�logging�DEBUG�INFO�basicConfig�	getLoggerZstage1Zstage2Zboth_stages�AssertionError�set�updater	rr
rr�add�versionrZ
list_fixes�sortedZnofix�len�joinZall_importsr"�union�os�path�commonprefixr�sep�isdir�dirname�rstrip�info�future�utilsZPY26r�errors�refactor_stdinrZ	processesZMultiprocessingUnsupportedZ	summarizer�bool)�args�parser�flagsrO�optionsr�loggerZavail_fixesZfixnameZunwanted_fixes�foundZextra_fixes�prefix�explicitZall_presentZ	requested�fixer_namesr+Zextra_kwargs�rtr#)r"r$�mainTsX





































r[)N)�__doc__�
__future__rrrZfuture.utilsrLrr3r6r,rDZlib2to3.mainrrZlib2to3rZlibfuturize.fixesr	r
rrZ	fixer_pkgr[r#r#r#r$�<module>>s

?>