
Bf³UI  ã               @   s¥   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                sá  t  j d d ƒ } | j d d d d d d ƒ| j d	 d
 d d d d ƒ| j d d d d d g  d d ƒ| j d d d d d d d d d d ƒ| j d d d d d g  d d ƒ| j d d d d d d ƒ| j d d d d d d  ƒ| j d! d d d d" ƒ| j d# d$ d d d d% ƒ| j d& d' d d d d( d d) ƒd( } i  } | j |  ƒ \ } }  d* ‰  t } d+ | d, <| j r™| j r™t d- ƒ | j r¹| j r¹| j	 d. ƒ | j
 rÐt t ƒ d/ S| j rt d0 ƒ x t | ƒ D] } t | ƒ qðW|  sd/ S|  s>t d1 d2 t j ƒt d3 d2 t j ƒd4 Sd5 |  k rpd+ } | j rpt d6 d2 t j ƒd4 S| j r‚t j n t j } t j d7 d8 d9 | ƒ t ‡  f d: d; †  | j Dƒ ƒ } t ƒ  }	 | j rd< }
 |	 j |
 d= ƒ |	 j |
 d> ƒ |	 j |
 d? ƒ | |	 | B} t t | ƒ | t ƒ  | j | j ƒ } | j sÎ| r`| j ƒ  nd y  | j |  | j d@ | j ƒ WnA t j k
 rÃ| j d k s¨t  ‚ t dA d2 t j ƒd SYn X| j! ƒ  t" t# | j ƒ ƒ S)BzBMain program.

    Returns a suggested exit status (0, 1, 2).
    Zusagez!pasteurize [options] file|dir ...z-Vz	--versionÚactionÚ
store_trueÚhelpz'Report the version number of pasteurizez-az--all-importsz5Adds all __future__ and future imports to each modulez-fz--fixÚappendÚdefaultz1Each FIX specifies a transformation; default: allz-jz--processesZstoreé   ÚtypeÚintzRun 2to3 concurrentlyz-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.Úformatz%(name)s: %(message)sÚlevelc             3   s   |  ] } ˆ  d  | Vq d S)z.fix_N© )Ú.0Zfix)Ú	fixer_pkgr   ú4/usr/lib/python3/dist-packages/libpasteurize/main.pyú	<genexpr>v   s    zmain.<locals>.<genexpr>zlibpasteurize.fixes.Zfix_add_all__future__importsZ&fix_add_future_standard_library_importZfix_add_all_future_builtinsNz+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nofixZall_importsÚaddr   ÚerrorsÚrefactor_stdinr   Z	processesZMultiprocessingUnsupportedÚAssertionErrorZ	summarizer   Úbool)ÚargsÚparserr-   ÚflagsZoptionsZavail_fixesZfixnamer   Zunwanted_fixesZextra_fixesÚprefixZfixer_namesZrtr   )r   r   r   3   s–    

	
	
	
	"				
	
r   )Ú__doc__Z
__future__r   r   r   r$   r'   r   Zlib2to3.mainr   r   r   Zlib2to3r   Zfuturer	   Zlibpasteurize.fixesr
   r   r   r   r   Ú<module>%   s   