bg5dZddlmZmZmZddlZddlmZddlZddl Z ddl Z ddl Z ddl m Z mZddlmZddlmZmZmZmZdZd 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_importprint_functionunicode_literalsN) __version__)warnStdoutRefactoringTool)refactor)lib2to3_fix_names_stage1lib2to3_fix_names_stage2libfuturize_fix_names_stage1libfuturize_fix_names_stage2zlibfuturize.fixescttjd}|dddd|dd dd |d d dd |dddd|dddd|dddd|dddgd|ddddd d!"|d#d$dgd%|d&d'dd(|d)d*dd+|d,d-dd.|d/dd0|d1d2dd3|d4d5dd6d7|d8d9dd:d;d<=|d>d?dd@|dAdd:d;dB=i}d6}||\}}|jr"dC|dD<|jst dEdC|_|jr|js| dF|j r|js| dG|js|j rt dH|js|jr| dIdJ|vr&dC}|jrtdKtjLdMS|jrdC|dN<|jr t"jn t"j}t#jdO|Pt#jdQ}|js|jr|jJd6|_ndC|_t3}|js|jr4|t6|t8|js|jr4|t:|t<|jr| dS|j!rttDdTS|j#r4tdUtI|D]}t||sdTS|s8tdVtjLtdWtjLdMSt3} |j%D]NJdXvr| fdY|D} tM| dkr>tdZd['d\| DztjLdMStM| dTkrtd]tjLdMS| | dTt3} |j(rl|jrd^} | | d_znJd`} | | daz| | dbz| | dczt3} |j)rJd6}|j)D]ЊddkrdC} dXvr| %fde|D} tM| dkr>tdZd['df| DztjLdMStM| dTkrtd]tjLdMS| | dTtM| | zdTkr@tdgd['dh| | zDztjLdMS|r|*| n| }n|*| }|| z| z }tVj,-|}|r]|.tVj/s>tVj,0|stVj,1|}|jr;|2tVj/}|3di|j|thj5j6ri}n|j |j|dj}totI||tI| |j|j fi|}|j8s|r|9nb |:||jdR|j;n>#ttj<$r,|j;dksJtdktjLYdSwxYw|=t}t|j8S)lzMain 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)actionhelpz-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--fixappendzEach 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')rdefaultrz-jz --processesstoreintzRun 2to3 concurrently)rrtyperz-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-dirstrzpPut 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-suffixzAppend this string to all output filenames. Requires -n if non-empty. For Python >= 2.7 only.ex: --add-suffix='3' will generate .py3 files.Twrite_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.)filerz%(name)s: %(message)s)formatlevelzlibfuturize.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_cdg|],}|d*|-Szfix_{0}endswithr.0ffixs a/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/libfuturize/main.py zmain..sG;;;1 9#3#3C#8#899;Q;;;zOAmbiguous fixer name. Choose a fully qualified module name instead from these:  c3 K|] }d|zV dSz Nr&myfs r) zmain..s&<.sNCCC1 ! 9+;+;C+@+@ A ACQCCCr+c3 K|] }d|zV dSr.r/r0s r)r2zmain..s&'D'Dss 'D'D'D'D'D'Dr+z[Conflicting usage: the following fixers have been simultaneously requested and disallowed: c3 K|] }d|zV dSr.r/r0s r)r2zmain..s&NN3D3JNNNNNNr+z7Output in %r will mirror the input directory %r layout.) append_suffix output_dirinput_base_dirz+Sorry, -j isn't supported on this platform.)@optparse OptionParser add_option parse_argsrwriterr< nobackupserror add_suffixno_diffsprintsysstderrrverboseloggingDEBUGINFO basicConfig getLoggerstage1stage2 both_stagessetupdater r r r raddversionr list_fixessortednofixlenjoin all_importsr(unionospath commonprefixr$sepisdirdirnamerstripinfofutureutilsPY26rerrorsrefactor_stdinr processesMultiprocessingUnsupported summarizerbool)argsparserflagsrjoptionsr logger avail_fixesfixnameunwanted_fixesfound extra_fixesprefixexplicit all_present requested fixer_namesr= extra_kwargsrtr(s @r)mainrTs  ")J K K KF dK BDDD dOLQSSS dJ|wyyy dJ|{}}} dOL6888 d0YZZZ dGHbijjj dM'1 '>@@@ dIh<>>> dN<;=== d.|MOOO dK 1333 l<@BBB dIl6888 dM,DFFF dN7 (0111 d5lABBB nW5"GHHH EN%%d++MGT$)-%&} ; 9 : : : >'"3> <===;'"3; 9::: =QW-Q OPPP =0W.0 ./// d{{ =  ) ; ; ; ;1'"&%_ >GMM',E 6eDDDD  1 2 2F~##"***#"%%K~9,934447888~9,934447888IGHHH kq BCCCk**  G 'NNNN 1  A:     ) ;;;;qUUN})) c>>   s # # # # ;;;; ;;;E5zzA~~:ii< D)F OOFNO P P P P,F OOF%CC D D D OOF%MM N N N OOF%BB C C CuuH{!0 ; + +Ce||" c>>LL%%%% CCCC CCCE5zzA~~B"ii'D'De'D'D'DDDE$'://// !qqUqQ#&://// qqLLq**** x.( ) )A - - ?))NN8n3LNNNNNOz # # # #13>LK%%h///H %%h// {*n>9 n--9 888'..rv66 M& 8 8 8| *1);&-&8*8  ;  x(8(8  7#33    B 9            D'-#-////6   (1,,,,4:=*FFFFqq    tBI  s$"c7dd)N)__doc__ __future__rrr future.utilsrfrrHrKr>r^ lib2to3.mainrrlib2to3r libfuturize.fixesr r r r fixer_pkgrr/r+r)rs==~KJJJJJJJJJ  44444444============ n n n n n n r+