U âQabÄ7ã@s ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZddlZej d¡r ddlmmmmZn ejejZzeZWnek rÌdZYnXeZddlm Z ddlm!Z!ddd d gZ"d-d d „Z#ej$d.d d„ƒZ%ej$dd„ƒZ&ej$dd„ƒZ'ej$dd„ƒZ(Gdd„de)ƒZ*Gdd„dƒZ+ej$dd„ƒZ,dd„Z-ej$dd„ƒZ.ej$dd „ƒZ/d!d"„Z0d#d$„Z1d%d „Z2Gd&d„dƒZ3e4ed'ƒ�rÆej5gZ6ngZ6Gd(d„de3ƒZ7e 8ej9d)d*„d+ :¡Dƒ¡Z;Gd,d „d e ƒZr4r5ÚtbrrrÚ__exit__{s zExceptionSaver.__exit__cCs6dt|ƒkrdSttj|jƒ\}}t |||j¡dS)z"restore and re-raise any exceptionrAN)Úvarsrr.ÚloadsrArZreraiserB)r>r4r5rrrÚresume†s zExceptionSaver.resumeN)r7r8r9r:r?rDrGrrrrr<rs r<c #sVtj ¡‰tƒ� }ˆVW5QRXtj ˆ¡‡fdd„tjDƒ}t|ƒ| ¡dS)z  Context in which imported modules are saved. Translates exceptions internal to the context into the equivalent exception outside the context. c3s$|]}|ˆkr| d¡s|VqdS)z encodings.N©Ú startswith)Ú.0Úmod_namer!rrÚ žs ýzsave_modules..N)rÚmodulesÚcopyr<ÚupdateÚ_clear_modulesrG)Ú saved_excZ del_modulesrr!rÚ save_modules�s   ÿrRcCst|ƒD] }tj|=qdSr)ÚlistrrM)Z module_namesrKrrrrP©s rPc cs$t ¡}z |VW5t |¡XdSr)r$Ú __getstate__Ú __setstate__r!rrrÚsave_pkg_resources_state®s rVccs–tj |d¡}tƒ�xtƒ�ftƒtƒ�Ntƒ�<t|ƒ�(t |ƒ�t dƒdVW5QRXW5QRXW5QRXW5QRXW5QRXW5QRXdS)NZtempZ setuptools) r(r ÚjoinrVrRÚhide_setuptoolsr"rr'r,Ú __import__)Ú setup_dirZtemp_dirrrrÚ setup_context·s  r[cCst d¡}t| |¡ƒS)aH >>> _needs_hiding('setuptools') True >>> _needs_hiding('pkg_resources') True >>> _needs_hiding('setuptools_plugin') False >>> _needs_hiding('setuptools.__init__') True >>> _needs_hiding('distutils') True >>> _needs_hiding('os') False >>> _needs_hiding('Cython') True z1(setuptools|pkg_resources|distutils|Cython)(\.|$))ÚrerÚboolÚmatch)rKÚpatternrrrÚ _needs_hidingÆs r`cCstttjƒ}t|ƒdS)a% Remove references to setuptools' modules from sys.modules to allow the invocation to import the most appropriate setuptools. This technique is necessary to avoid issues such as #315 where setuptools upgrading itself would fail to find a function declared in the metadata. N)Úfilterr`rrMrP)rMrrrrXÛs rXc Csêtj tj |¡¡}t|ƒ�Äzˆ|gt|ƒtjdd…<tj d|¡t   ¡t j   dd„¡t |tƒrl|n | t ¡¡}t|ƒ�t|dd�}t||ƒW5QRXWn4tk rÚ}z|jrÊ|jdrÊ‚W5d}~XYnXW5QRXdS)z8Run a distutils setup script, sandboxed in its directoryNrcSs| ¡Sr)Zactivate)ZdistrrrÚïózrun_setup..Ú__main__)Ú__file__r7)r(r ÚabspathÚdirnamer[rSrrÚinsertrÚ__init__Z callbacksÚappendÚ isinstanceÚstrÚencodeÚgetfilesystemencodingr ÚdictrÚ SystemExitÚargs)Z setup_scriptrqrZZ dunder_fileÚnsÚvrrrr æs" ÿ ý  c@seZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dD]Z e e e ƒrDe e ƒeƒe <qDd$dd„ZerzedeƒZedeƒZdD]Z e e e ƒrˆee ƒeƒe <qˆdd„ZdD]Z e e e ƒr²ee ƒeƒe <q²dd„ZdD]Z e e e ƒrÜee ƒeƒe <qÜdd„Zdd„Zd d!„Zd"d#„ZdS)%rzDWrap 'os' module and 'open()' builtin for virtualizing setup scriptsFcs‡fdd„ttƒDƒˆ_dS)Ncs$g|]}| d¡stˆ|ƒr|‘qS)Ú_)rIÚhasattr)rJÚnamer=rrÚ s ÿz,AbstractSandbox.__init__..)ÚdirÚ_osÚ_attrsr=rr=rris ÿzAbstractSandbox.__init__cCs"|jD]}tt|t||ƒƒqdSr)rzÚsetattrr(Úgetattr)r>ÚsourcervrrrÚ_copy s zAbstractSandbox._copycCs(| |¡tr|jt_|jt_d|_dSr@)r~Ú_filerÚfileÚ_openrÚ_activer=rrrr?s  zAbstractSandbox.__enter__cCs$d|_trtt_tt_| t¡dS©NF)r‚rrr€r�rr~ry)r>Úexc_typeÚ exc_valueÚ tracebackrrrrDs zAbstractSandbox.__exit__c Cs"|�|ƒW5QR£SQRXdS)zRun 'func' under os sandboxingNr)r>ÚfuncrrrÚrunszAbstractSandbox.runcsttˆƒ‰‡‡fdd„}|S)Ncs2|jr |jˆ||f|ž|Ž\}}ˆ||f|ž|ŽSr)r‚Ú _remap_pair)r>ÚsrcÚdstrqÚkw©rvÚoriginalrrÚwrap&sz3AbstractSandbox._mk_dual_path_wrapper..wrap©r|ry©rvr�rr�rÚ_mk_dual_path_wrapper#s z%AbstractSandbox._mk_dual_path_wrapper)ÚrenameÚlinkÚsymlinkNcs ˆp ttˆƒ‰‡‡fdd„}|S)Ncs*|jr|jˆ|f|ž|Ž}ˆ|f|ž|ŽSr)r‚Ú _remap_input©r>r rqrŒr�rrr�4sz5AbstractSandbox._mk_single_path_wrapper..wrapr�)rvrŽr�rr�rÚ_mk_single_path_wrapper1sz'AbstractSandbox._mk_single_path_wrapperr€r)ÚstatÚlistdirr*rÚchmodÚchownÚmkdirÚremoveÚunlinkÚrmdirÚutimeÚlchownÚchrootÚlstatZ startfileÚmkfifoÚmknodÚpathconfÚaccesscsttˆƒ‰‡‡fdd„}|S)NcsB|jr2|jˆ|f|ž|Ž}| ˆˆ|f|ž|Ž¡Sˆ|f|ž|ŽSr)r‚r–Ú _remap_outputr—r�rrr�Isz4AbstractSandbox._mk_single_with_return..wrapr�r‘rr�rÚ_mk_single_with_returnFs z&AbstractSandbox._mk_single_with_return)ÚreadlinkÚtempnamcsttˆƒ‰‡‡fdd„}|S)Ncs ˆ||Ž}|jr| ˆ|¡S|Sr)r‚r©)r>rqrŒZretvalr�rrr�Xs  z'AbstractSandbox._mk_query..wrapr�r‘rr�rÚ _mk_queryUs zAbstractSandbox._mk_query)r)ÚtmpnamcCs|S)z=Called to remap or validate any path, whether input or outputr)r>r rrrÚ_validate_pathdszAbstractSandbox._validate_pathcOs | |¡S©zCalled for path inputs©r¯©r>Ú operationr rqrŒrrrr–hszAbstractSandbox._remap_inputcCs | |¡S)zCalled for path outputsr±)r>r³r rrrr©lszAbstractSandbox._remap_outputcOs0|j|d|f|ž|Ž|j|d|f|ž|ŽfS)ú?Called for path pairs like rename, link, and symlink operationsz-fromz-to)r–©r>r³rŠr‹rqrŒrrrr‰psþzAbstractSandbox._remap_pair)N)r7r8r9r:r‚rir~r?rDrˆr’rvruryrr˜rr�rªr­r¯r–r©r‰rrrrrs<          Údevnullc@s˜eZdZdZe dddddddd d d d d dg ¡ZdgZefdd„Z dd„Z e rXd'dd„Z d(dd„Z dd„Z dd„Zdd„Zdd „Zd!d"„Zd)d$d%„Zd&S)*r z.) r(r r¸r¹Ú_sandboxrWÚ_prefixÚ _exceptionsrri)r>ZsandboxÚ exceptionsrrrriŒs þzDirectorySandbox.__init__cOsddlm}||||ƒ‚dS)Nr)r )r1r )r>r³rqrŒr rrrÚ _violation•s zDirectorySandbox._violationÚrcOs:|dkr(| |¡s(|jd||f|ž|Žt||f|ž|ŽS)N©r¿Zrtr ZrUÚUr€)Ú_okr¾r©r>r rrqrŒrrrr›szDirectorySandbox._filecOs:|dkr(| |¡s(|jd||f|ž|Žt||f|ž|ŽS)NrÀr)rÂr¾r�rÃrrrr� szDirectorySandbox._opencCs| d¡dS)Nr®)r¾r=rrrr®¥szDirectorySandbox.tmpnamcCsR|j}z>d|_tj tj |¡¡}| |¡p@||jkp@| |j¡W¢S||_XdSrƒ) r‚r(r r¸r¹Ú _exemptedrºrIr»)r>r Zactiver¹rrrr¨s ÿ ýzDirectorySandbox._okcs<‡fdd„|jDƒ}‡fdd„|jDƒ}t ||¡}t|ƒS)Nc3s|]}ˆ |¡VqdSrrH)rJZ exception©ÚfilepathrrrL¶sÿz-DirectorySandbox._exempted..c3s|]}t |ˆ¡VqdSr)r\r^)rJr_rÅrrrLºsÿ)r¼Ú_exception_patternsÚ itertoolsÚchainÚany)r>rÆZ start_matchesZpattern_matchesZ candidatesrrÅrrĵs þ þ zDirectorySandbox._exemptedcOs4||jkr0| |¡s0|j|tj |¡f|ž|Ž|Sr°)Ú write_opsrÂr¾r(r r¹r²rrrr–ÁszDirectorySandbox._remap_inputcOs2| |¡r| |¡s*|j|||f|ž|Ž||fS)r´)rÂr¾rµrrrr‰ÇszDirectorySandbox._remap_pairéÿcOs@|t@r*| |¡s*|jd|||f|ž|Žtj|||f|ž|ŽS)zCalled for low-level os.open()zos.open)Ú WRITE_FLAGSrÂr¾ryr)r>r€ÚflagsrrqrŒrrrrÍszDirectorySandbox.openN)r¿)r¿)rÌ)r7r8r9r:roÚfromkeysrËrÇÚ _EXCEPTIONSrir¾rr�r®rÂrÄr–r‰rrrrrr ~s:þþ     cCsg|]}tt|dƒ‘qS)rr�)rJÚarrrrwÕsrwz4O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARYc@s&eZdZdZe d¡ ¡Zdd„ZdS)r zEA setup script attempted to modify the filesystem outside the sandboxa SandboxViolation: {cmd}{args!r} {kwargs} The package setup script has attempted to modify files on your system that are not within the EasyInstall build area, and has been aborted. This package cannot be safely installed by EasyInstall, and may not support alternate installation locations even if you run its setup script by hand. Please inform the package's author and the EasyInstall maintainers to find out if a fix or workaround is available. cCs|j\}}}|jjftƒŽSr)rqÚtmplÚformatr)r>ÚcmdrqÚkwargsrrrÚ__str__és zSandboxViolation.__str__N) r7r8r9r:ÚtextwrapÚdedentÚlstriprÒrÖrrrrr Ús )N)N)=r(rr&ÚoperatorÚ functoolsrÈr\Ú contextlibr.r×Zsetuptools.externrZsetuptools.extern.six.movesrrZpkg_resources.py31compatr$ÚplatformrIZ$org.python.modules.posix.PosixModuleÚpythonrMÚposixZ PosixModuleryrvr€rÚ NameErrorrr�Zdistutils.errorsrrÚ__all__rÚcontextmanagerrr"r'r,r0r-r<rRrPrVr[r`rXr rrur¶rÐr ÚreduceÚor_ÚsplitrÍr rrrrÚsx       ÿ         w  Vÿÿ