B ÍAÒ[úã@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_importÚprint_functionÚunicode_literalsN)ÚmainÚwarnÚStdoutRefactoringTool)Úrefactor)Ú __version__)Ú fix_namescsxtjdd}|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 rjt d/ƒxt|ƒD]}t |ƒqNW|sjd.S|st d0tjd1t d2tjd1d3Sd4|kr¸d*}|jr¸t d5tjd1d3S|jrÆtjntj}tjd6|d7tƒ} xš|jD]‰d8ˆkr|  ˆ¡nt‡fd9d:„|Dƒ} t| ƒdkrHt d;d< d=d>„| Dƒ¡tjd1d3St| ƒd.krht d?tjd1d3S|  | d.¡qèWtƒ} |jr¸d@} |  | dA¡|  | dB¡|  | dC¡tƒ} |jrÈd'}xª|jD] ‰ˆdDkræd*}nŠd8ˆkrü|  ˆ¡nt‡fdEd:„|Dƒ} t| ƒdkrBt d;d< dFd>„| Dƒ¡tjd1d3St| ƒd.krbt d?tjd1d3S|  | d.¡qÒWt| | @ƒd.kr²t dGd< dHd>„| | @Dƒ¡tjd1d3S|rÂ| | ¡n| }n | | ¡}|| | B}tt|ƒ|tƒ|j|j ƒ}|jsj|r|  ¡nPy| !||jdI|j"¡Wn6t!j#k r`|j"dksNt$‚t dJtjd1dSX| %¡t&t'|jƒƒS)KzBMain program. Returns a suggested exit status (0, 1, 2). z!pasteurize [options] file|dir ...)Zusagez-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 --processesZstoreéÚintzRun 2to3 concurrently)r rÚtyper z-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)ÚformatÚlevelz.fix_cs g|]}| d ˆ¡¡r|‘qS)zfix_{0})Úendswithr)Ú.0Úf)Úfix©úC/opt/alt/python37/lib/python3.7/site-packages/libpasteurize/main.pyú }szmain..zOAmbiguous fixer name. Choose a fully qualified module name instead from these: Ú css|]}d|VqdS)z Nr)rÚmyfrrrú ‚szmain..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_builtinsÚallcs g|]}| d ˆ¡¡r|‘qS)zfix_{0})rr)rr)rrrrŸscss|]}d|VqdS)z Nr)rr rrrr!¤sz[Conflicting usage: the following fixers have been simultaneously requested and disallowed: css|]}d|VqdS)z Nr)rr rrrr!¯sNz+Sorry, -j isn't supported on this platform.)(ÚoptparseZ OptionParserZ add_optionÚ parse_argsr ÚwriteZno_diffsrZ nobackupsÚerrorÚversionÚprintr Z list_fixesÚsortedÚsysÚstderrÚverboseÚloggingÚDEBUGÚINFOZ basicConfigÚsetZnofixÚaddÚlenÚjoinZ all_importsrÚunionrÚerrorsÚrefactor_stdinrZ processesZMultiprocessingUnsupportedÚAssertionErrorZ summarizerÚbool)ÚargsÚparserr6ÚflagsÚoptionsZ fixer_pkgZ avail_fixesZfixnamerZunwanted_fixesÚfoundZ extra_fixesÚprefixÚexplicitZ all_presentZ requestedÚ fixer_namesZrtr)rrr3sæ                                r)N)Ú__doc__Z __future__rrrr*r-r#Z lib2to3.mainrrrZlib2to3rZfuturer Zlibpasteurize.fixesr rrrrÚ%s