bg_l|dZddlmZmZmZddlZddlZddlZddlZddl Z ddl Z ddl Z ej dZ ejejZejZeee ee ejddlmZmZegdZddd d d d d ddddddd ZeeeeezdksJgdZGdde Z!Gdde Z"er=eeeeej#zdksJdZ$dZ%dZ&Gdde Z'dZ(d Z)d!Z*d"Z+d/d$Z,d%Z-d&Z.e/ed'sie_0d(Z1d/d)Z2d*Z3Gd+d,e Z4gd-Z5d.Z6dS)0a Python 3 reorganized the standard library (PEP 3108). This module exposes several standard library modules to Python 2 under their new Python 3 names. It is designed to be used as follows:: from future import standard_library standard_library.install_aliases() And then these normal Py3 imports work on both Py3 and Py2:: import builtins import copyreg import queue import reprlib import socketserver import winreg # on Windows only import test.support import html, html.parser, html.entites import http, http.client, http.server import http.cookies, http.cookiejar import urllib.parse, urllib.request, urllib.response, urllib.error, urllib.robotparser import xmlrpc.client, xmlrpc.server import _thread import _dummy_thread import _markupbase from itertools import filterfalse, zip_longest from sys import intern from collections import UserDict, UserList, UserString from collections import OrderedDict, Counter, ChainMap # even on Py2.6 from subprocess import getoutput, getstatusoutput from subprocess import check_output # even on Py2.6 (The renamed modules and functions are still available under their old names on Python 2.) This is a cleaner alternative to this idiom (see http://docs.pythonsprints.com/python3_porting/py-porting.html):: try: import queue except ImportError: import Queue as queue Limitations ----------- We don't currently support these modules, but would like to:: import dbm import dbm.dumb import dbm.gnu import collections.abc # on Py33 import pickle # should (optionally) bring in cPickle on Python 2 )absolute_importdivisionprint_functionN future_stdlib)PY2PY3)testurllibpickledbmbuiltinscopyregqueue socketserver configparserreprlibwinreg_thread _dummy_threadxmlrpchtmlhttp _markupbase) __builtin__copy_regQueuezfuture.moves.socketserver ConfigParserrepr_winregthread dummy_threadzfuture.moves.xmlrpczfuture.moves.htmlzfuture.moves.httpzfuture.moves._markupbase)) collectionsUserListr#r#)r"UserDictr$r$)r" UserStringr%r%r"ChainMapfuture.backports.miscr') itertools filterfalser) ifilterfalse)r) zip_longestr) izip_longest)sysinternrr/)reASCIIstatST_MODE)base64 encodebytesr4 encodestring)r4 decodebytesr4 decodestring) subprocess getoutputcommandsr:)r9getstatusoutputr;r<)r9 check_outputr(r=)mathceilr(r?)r" OrderedDictr(r@)r"Counterr(rAr&)r)countr(rB)rrecursive_reprr(rC) functools cmp_to_keyr(rEc2eZdZdZdZdZddZdZddZdS) RenameImportzX A class for import hooks mapping Py3 module names etc. to the Py2 equivalents. Tc||_t|t|z}t |dkrQt t|t |ks Jdt d|D|_dS)z Pass in a dictionary-like object mapping from old names to new names. E.g. {'ConfigParser': 'configparser', 'cPickle': 'pickle'} rz/Ambiguity in renaming (handler not implemented)c3$K|] \}}||fV dSN).0oldnews W/opt/cloudlinux/venv/lib64/python3.11/site-packages/future/standard_library/__init__.py z(RenameImport.__init__..s*OOjsCSzOOOOOON) old_to_newsetkeysvalueslendictitems new_to_old)selfrRboths rO__init__zRenameImport.__init__s %:??$$%%J,=,=,?,?(@(@@D QC ))++,,--Z5F5F5H5H1I1IIII@JIJOOJz,RenameImport.find_module..s&GGG!aggcll1oGGGrQ)rSrY)rZfullnamepathnew_base_namess rO find_modulezRenameImport.find_modules5GGtGGGHH ~ % %KtrQcd}|tjvrtj|S||jvr#|j|}||}n||}|tj|<|SrJ)r.modulesrY_find_and_load_module)rZnamerdoldnamemodules rO load_modulezRenameImport.load_module su 3;  ;t$ $ T_ $ $od+G//88FF//55F" D rQc0|d}t|dkr|d}|||} |j}ny#t $rlt d||tj vrtj |cYSt dYnwxYwt|dk|d}tj ||}tj |g|RS)zb Finds and loads it. But if there's a . in the name, handles it properly. r_rzPackage {0} has no __path__.zWhat to do here?)r`rVpopri__path__AttributeErrorflogdebugformatr.rhimprfrm)rZrjrdbits packagenamepackage module_infos rOriz"RenameImport._find_and_load_modules zz#$ii!mm((1++K00dCCG /'! / / / 9@@IIJJJ3;&&;t,,,, -.....  / $ii!mmAwodD11 t2k2222sAAC6CCrJ) __name__ __module__ __qualname____doc__RENAMERr\rfrmrirKrQrOrGrGsnG P P P   333333rQrGceZdZdZdZdZdS)hooksa Acts as a context manager. Saves the state of sys.modules and restores it after the 'with' block. Use like this: >>> from future import standard_library >>> with standard_library.hooks(): ... import http.client >>> import requests For this to work, http.client will be scrubbed from sys.modules after the 'with' block. That way the modules imported in the 'with' block will continue to be accessible in the current namespace but not from any imported modules (like requests). ctjtj|_t |_t |SrJ)copyr.rhold_sys_modules detect_hookshooks_were_installed install_hooksrZs rO __enter__zhooks.__enter__As0#y55$0NN! rQc4|jstdSdSrJ)r remove_hooksrZargss rO__exit__zhooks.__exit__Is&(  NNNNN  rQNr{r|r}r~rrrKrQrOrr0s< rQrc$trdSdtjvr~tjt jt jg}d|D}tt|dkst d|z|dt_ |j tjvrdSt|drUt j|j}|dtj r d |dvrdSdS) z Tries to infer whether the module m is from the Python 2 standard library. This may not be reliable on all systems. F stdlib_pathcXg|]'}tj|d(S)r)osrdr`)rLfs rOrbz(is_py2_stdlib_module.._s+BBB a((+BBBrQroz>> from future import standard_library >>> standard_library.install_hooks() >>> import http.client >>> # ... >>> with standard_library.suspend_hooks(): >>> import requests # incompatible with ``future``'s standard library hooks If the hooks were disabled before the context, they are not installed when the context is left. cHt|_t|SrJ)rrrrs rOrzsuspend_hooks.__enter__s$0NN! rQc4|jrtdSdSrJ)rrrs rOrzsuspend_hooks.__exit__s$  $  OOOOO  rQNrrKrQrOrrs<   rQrc*ttjt|z}t|dkr7t |d}t d|tj|dS)zp Add any previously scrubbed modules back to the sys.modules cache, but only if it's safe to do so. rz(future module {} clashes with Py2 moduleN)rSr.rhrVlist ImportErrorruupdate)rclashfirsts rOrestore_sys_modulesrsx   s8}} ,E 5zzQU AD!6%==** *Kx     rQctrdStD]j\}}}}t|tj|}t|tj|}t ||}t |||kddl}ddlm }ddlm } ddlm } ddlm } ddlm } ||_ | |_ | |_ | |_ | |_ |tjd<| tjd <| tjd <| tjd <| tjd < ddl} n#t$rYnwxYw dd lm}|| _|tjd<n#t$rYnwxYw ddl}ddlm}||_|tjd< ddlm}||_|tjd<n#t$rYnwxYw ddlm}||_|tjd<dS#t$rYdSwxYw#t$rYdSwxYw)zm Monkey-patches the standard library in Py2.6/7 to provide aliases for better Py3 compatibility. Nr)request)response)parse)error) robotparserzurllib.requestzurllib.responsez urllib.parsez urllib.errorzurllib.robotparser)supportz test.support)dumbzdbm.dumb)gnuzdbm.gnu)ndbmzdbm.ndbm)rMOVES __import__r.rhgetattrsetattrr future.backports.urllibrrrrrr rfuture.moves.testrr future.moves.dbmrrr) newmodname newobjname oldmodname oldobjnamenewmodoldmodobjr rrrrrr rr rrrs rOinstall_aliasesrs  =B ) )8ZZ:Z( :Z(fj)) C((((MMM//////000000------------333333FNFOFLFL$F$+CK !%-CK!""'CK"'CK(3CK$%       .------ &- N##      +  *)))))"& J ) , , , , , ,CG%(CK " "     D   + - - - - - -CH&*CK # # #     DD       sZ D DD#E E  E G2F FF F>> G  G  GGctrdSttdt jtdtt}tst j |tdt jdS)z` This function installs the future.standard_library import hook into sys.meta_path. Nzsys.meta_path was: {0}zInstalling hooks ...zsys.meta_path is now: {0}) rrrsrtrur. meta_pathrGrrappend)newhooks rOrr s  JJ'..s}==>>>JJ%&&&7##G >>& W%%%JJ*11#-@@AAAAArQc"tdS)z_ Deprecated. Use install_hooks() instead. This will be removed by ``future`` v1.0. N)rrKrQrO enable_hooksrs OOOOOrQFctrdStdtt t jdddD]"\}}t|dr t j|=#|rtdSdS)zC This function removes the import hook from sys.meta_path. NzUninstalling hooks ...r) rrsrtr enumerater.rrr)scrub_sys_modulesihooks rOrr's JJ'((( #-0011$$B$7!!4 4 # # ! a # """""##rQc"tdS)z^ Deprecated. Use remove_hooks() instead. This will be removed by ``future`` v1.0. N)rrKrQrO disable_hooksr;s NNNNNrQctdtdtjD}|rtdntd|S)zG Returns True if the import hooks are installed, False if not. zDetecting hooks ...c.g|]}t|dS)r)r)rLrs rOrbz detect_hooks..Hs"FFF74++FFFrQz Detected.z Not detected.)rsrtanyr.r)presents rOrrCsi JJ$%%%FF FFFGGG$ ; ?### NrQ py2_modulescttjdkrdStrJddl}|tjd<ddl}|tjd<ddl}|tjd<dS)z Currently this function is unneeded, as we are not attempting to provide import hooks for modules with ambiguous names: email, urllib, pickle. rNr emailr )rVr.rrr rr )r rr s rOcache_py2_modulesrXss  3?q  ~~ MMM &COHLLL$COGMMM &COHrQcddl}trt|S|rd}nd}|d|dz}g}t |D]M\}}d|d|dz}|||Nttt |D]-\}}|dkrn!t||dz |||.|dS)a Pass a (potentially dotted) module name of a Python 3 standard library module. This function imports the module compatibly on Py2 and Py3 and returns the top-level module. Example use: >>> http = import_('http.client') >>> http = import_('http.server') >>> urllib = import_('urllib.request') Then: >>> conn = http.client.HTTPConnection(...) >>> response = urllib.request.urlopen('http://mywebsite.com') >>> # etc. Use as follows: >>> package_name = import_(module_name) On Py3, equivalent to this: >>> import module_name On Py2, equivalent to this if backport=False: >>> from future.moves import module_name or to this if backport=True: >>> from future.backports import module_name except that it also handles dotted module names such as ``http.client`` The effect then is like this: >>> from future.backports import module >>> from future.backports.module import submodule >>> module.submodule = submodule Note that this would be a SyntaxError in Python: >>> from future.backports import http.client rNfuture.backports future.movesr_ro) importlibrrr`rjoinr import_modulereversedrr) module_namebackportrprefixpartsrhrpartsofars rOimport_rts'\ +&&&  $'FF#F S!!K$5$5c$:$:: '' ; ;GAtHHU4AaC4[))E NN922599 : : : :Yu%5%5 6 677 4 4GAtAvv GAaCL$ 3 3 3 3qzrQcXtrt|Sd|vrt|drd}nd}|d|dz}t|dz|zfd|D}t |dkr|dS|S)aa Example use: >>> HTTPConnection = from_import('http.client', 'HTTPConnection') >>> HTTPServer = from_import('http.server', 'HTTPServer') >>> urlopen, urlparse = from_import('urllib.request', 'urlopen', 'urlparse') Equivalent to this on Py3: >>> from module_name import symbol_names[0], symbol_names[1], ... and this on Py2: >>> from future.moves.module_name import symbol_names[0], ... or: >>> from future.backports.module_name import symbol_names[0], ... except that it also handles dotted module names such as ``http.client``. rrrr_c0g|]}t|SrK)r)rLrjrls rOrbzfrom_import..s#AAAD'&$''AAArQror)rrboolr`rrrV)r symbol_nameskwargsrroutputrls @rO from_importrs, +&&&   D );$<$< 'FF#F S!!K$5$5c$:$::((# )CDDAAAALAAA v;;!  !9 MrQc$eZdZdZdZdZdZdS)exclude_local_folder_importsaZ A context-manager that prevents standard library modules like configparser from being imported from the local python-future source folder on Py3. (This was need prior to v0.16.0 because the presence of a configparser folder would otherwise have prevented setuptools from running on Py3. Maybe it's not needed any more?) ct|dksJ||_td|jDrtddS)Nrcg|]}d|vS)r_rK)rLrs rOrbz9exclude_local_folder_imports.__init__..s444Qq444rQz%Dotted module names are not supported)rV module_namesrNotImplementedErrorrs rOr\z%exclude_local_folder_imports.__init__s[4yy1}}}}  44$"3444 5 5 O%&MNN N O OrQctjtj|_tjtj|_tjddkrdSgd}|jD]<tfd|Drtj=|j D]$} t|d}#t$rY!wxYwdS)Nr)futurepast libfuturize libpasteurizer cg|]?}tjtj|@SrK)rrdexistsr)rL subfolderfolders rOrbz:exclude_local_folder_imports.__enter__..sG???!GNN27<< #B#BCC???rQ)level) rr.rd old_sys_pathrhr version_infoallremoverrr)rZFUTURE_SOURCE_SUBFOLDERSrrlrs @rOrz&exclude_local_folder_imports.__enter__s Ich//#y55  A  " " F$b#a#a ' ( (F????%=???@@ ('''"  A #AQ///      s2C CCc|jt_t|jttjz D]}|j|tj|<dSrJ)r r.rdrSrrTrh)rZrrs rOrz%exclude_local_folder_imports.__exit__sl$T)..0011C 8H8H8J8J4K4KK 5 5A!1!4CKNN 5 5rQN)r{r|r}r~r\rrrKrQrOrrsOOOO@55555rQr)r rrrrrrr tkinterrrrrrctt5tD]"} t|#t$rYwxYw ddddS#1swxYwYdSrJ)rTOP_LEVEL_MODULESrr)rs rOimport_top_level_modulesr)s %'8 9"  A 1      s, A*A 7A7AA A )F)7r~ __future__rrrr.loggingrvrtypesrr getLoggerrs Formatter BASIC_FORMAT _formatter StreamHandler_handler setFormatter addHandlersetLevelWARN future.utilsrrrSrrrVrUrobjectrGrrrrrrrrrrrrrrrrrrrrrrKrQrOr#s::xA@@@@@@@@@   w)) W w3 4 4 7 " "j!!! gl!!!!!!!!3:::;;% (6) *#+&!' &(5w< < F s33w~~ 33'7#8#8 899Q>>>>   lC3C3C3C3C36C3C3C3LFDK 3ss7>>##$$ss3+C'D'DD E E J J J J<2 F4 ! ! !K+K+K+`BBB(####(   $wsM""CO'''8FFFFR###L45454545456454545l rQ