U
    ,]                     @   sv   d Z ddlmZmZmZ ddlZddlZddlZddlm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ d
dd	Z	dS )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_importprint_functionunicode_literalsN)mainwarnStdoutRefactoringTool)refactor)__version__)	fix_namesc                    sv  t jdd}|jddddd |jdd	dd
d |jdddg dd |jddddddd |jdddg dd |jddddd |jddddd |jd dd!d |jd"d#dd$d |jd%d&dd'd(d d'}i }|| \}} d)}t}d*|d+< |js|jrtd, |js |jr |	d- |j
r4tt d.S |jrftd/ t|D ]}t| qL| sfd.S | std0tjd1 td2tjd1 d3S d4| krd*}|jrtd5tjd1 d3S |jrtjntj}tjd6|d7 t }	|jD ] d8 kr|	  nx fd9d:|D }
t|
dkrDtd;d<d=d> |
D  tjd1  d3S t|
d.krftd?tjd1  d3S |	|
d.  qt }|jrd@}||dA  ||dB  ||dC  t }|jrd'}|jD ]  dDkrd*}nd8 kr|  nx fdEd:|D }
t|
dkr>td;d<dFd> |
D  tjd1  d3S t|
d.kr`td?tjd1  d3S ||
d.  qt||	@ d.krtdGd<dHd> ||	@ D  tjd1 d3S |r||n|}n
||}|||	 B }tt||t |j|j }|jsh|r|   nRz|!| |jdI|j" W n8 t!j#k
r^   |j"dksJt$tdJtjd1 Y dS X |%  t&t'|jS )KzBMain program.

    Returns a suggested exit status (0, 1, 2).
    z!pasteurize [options] file|dir ...)Zusagez-Vz	--version
store_truez'Report the version number of pasteurize)actionhelpz-az--all-importsz5Adds all __future__ and future imports to each modulez-fz--fixappendz1Each FIX specifies a transformation; default: all)r   defaultr   z-jz--processesZstore   intzRun 2to3 concurrently)r   r   typer   z-xz--nofixzPrevent a fixer from being run.z-lz--list-fixeszList available transformationsz-vz	--verbosezMore verbose loggingz
--no-diffsz#Don't show diffs of the refactoringz-wz--writezWrite back modified filesz-nz--nobackupsFz'Don't write backups for modified files.zlibpasteurize.fixesTr   z@not writing files and not printing diffs; that's not very usefulzCan't use -n without -wr   z2Available transformations for the -f/--fix option:z1At least one file or directory argument required.)filezUse --help to show usage.   -zCan't write to stdin.z%(name)s: %(message)s)formatlevelz.fix_c                    s    g | ]}| d  r|qS zfix_{0}endswithr   .0ffix 4/usr/lib/python3/dist-packages/libpasteurize/main.py
<listcomp>}   s    zmain.<locals>.<listcomp>zOAmbiguous fixer name. Choose a fully qualified module name instead from these:

c                 s   s   | ]}d | V  qdS z  Nr    r   Zmyfr    r    r!   	<genexpr>   s     zmain.<locals>.<genexpr>z1Unknown fixer. Use --list-fixes or -l for a list.zlibpasteurize.fixes.Zfix_add_all__future__importsZ&fix_add_future_standard_library_importZfix_add_all_future_builtinsallc                    s    g | ]}| d  r|qS r   r   r   r   r    r!   r"      s    c                 s   s   | ]}d | V  qdS r$   r    r%   r    r    r!   r&      s     z[Conflicting usage: the following fixers have been simultaneously requested and disallowed:
c                 s   s   | ]}d | V  qdS r$   r    r%   r    r    r!   r&      s     Nz+Sorry, -j isn't supported on this platform.)(optparseZOptionParserZ
add_option
parse_argsr
   writeZno_diffsr   Z	nobackupserrorversionprintr	   Z
list_fixessortedsysstderrverboseloggingDEBUGINFOZbasicConfigsetZnofixaddlenjoinZall_importsr   unionr   errorsrefactor_stdinr   Z	processesZMultiprocessingUnsupportedAssertionErrorZ	summarizer   bool)argsparserr;   flagsZoptionsZ	fixer_pkgZavail_fixesZfixnamer   Zunwanted_fixesfoundZextra_fixesprefixZexplicitZall_presentZ	requestedZfixer_namesZrtr    r   r!   r   3   s   

 










 
r   )N)__doc__Z
__future__r   r   r   r/   r2   r(   Zlib2to3.mainr   r   r   Zlib2to3r   Zfuturer	   Zlibpasteurize.fixesr
   r    r    r    r!   <module>   s   &