3 M(Y8 @sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZddlZejjdrddljjjjZn ejejZyeZWnek rdZYnXeZddlm Z ddlm!Z!ddd d gZ"d-d d Z#ej$d.d dZ%ej$ddZ&ej$ddZ'ej$ddZ(Gddde)Z*GdddZ+ej$ddZ,ddZ-ej$ddZ.ej$dd Z/d!d"Z0d#d$Z1d%d Z2Gd&ddZ3e4ed'rej5gZ6ngZ6Gd(dde3Z7ej8ej9d)d*d+j:DZ;Gd,d d e Zszsave_modules..)rmodulescopyrDupdate_clear_modulesrN) saved_excZ del_modulesr )r%r! save_moduless  rXcCsxt|D] }tj|=q WdS)N)listrrS) module_namesrQr r r!rVsrVc cs$tj}z |VWdtj|XdS)N)r* __getstate__ __setstate__)r%r r r!save_pkg_resources_states r]c,cstjj|d}txtfttNt<t|(t |t ddVWdQRXWdQRXWdQRXWdQRXWdQRXWdQRXdS)Ntemp setuptools) r0r'joinr]rXhide_setuptoolsr(r&r/r4 __import__) setup_dirtemp_dirr r r! setup_contexts  recCstjd}t|j|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)(\.|$))rerboolmatch)rQpatternr r r! _needs_hidings rjcCstttj}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)filterrjrrSrV)rSr r r!ras racCstjjtjj|}t|y|gt|tjdd<tjjd|t j t j j ddt |trl|n |jtj}t|t|dd}t||WdQRXWn4tk r}z|jr|jdrʂWYdd}~XnXWdQRXdS)z8Run a distutils setup script, sandboxed in its directoryNrcSs|jS)N)activate)distr r r!szrun_setup..__main__)__file__r?)r0r'abspathdirnamererYrr#insertr__init__ callbacksappend isinstancestrencodegetfilesystemencodingr dictr" SystemExitargs)Z setup_scriptr}rcZ dunder_filensvr r r!r s   c@s2eZdZdZdZddZddZddZd d Zd d Z d dZ x$d9D]Z e e e rFe e ee <qFWd:ddZer~edeZedeZx$d;D]Z e e e ree ee <qWd)d*Zx$drzDWrap 'os' module and 'open()' builtin for virtualizing setup scriptsFcsfddttD_dS)Ncs&g|]}|jd rt|r|qS)_)rOhasattr)rPname)rEr r! sz,AbstractSandbox.__init__..)dir_os_attrs)rEr )rEr!rt szAbstractSandbox.__init__cCs&x |jD]}tt|t||qWdS)N)rsetattrr0getattr)rEsourcerr r r!_copys zAbstractSandbox._copycCs(|j|tr|jt_|jt_d|_dS)NT)r_filerfile_openr_active)rEr r r!rFs  zAbstractSandbox.__enter__cCs$d|_trtt_tt_|jtdS)NF)rrrrrrrr)rEexc_type exc_value tracebackr r r!rJs zAbstractSandbox.__exit__c Cs||SQRXdS)zRun 'func' under os sandboxingNr )rEfuncr r r!run"szAbstractSandbox.runcsttfdd}|S)Ncs2|jr |j||f||\}}||f||S)N)r _remap_pair)rEsrcdstr}kw)roriginalr r!wrap*sz3AbstractSandbox._mk_dual_path_wrapper..wrap)rr)rrr )rrr!_mk_dual_path_wrapper's z%AbstractSandbox._mk_dual_path_wrapperrenamelinksymlinkNcs p ttfdd}|S)Ncs*|jr|j|f||}|f||S)N)r _remap_input)rEr'r}r)rrr r!r8sz5AbstractSandbox._mk_single_path_wrapper..wrap)rr)rrrr )rrr!_mk_single_path_wrapper5sz'AbstractSandbox._mk_single_path_wrapperrrstatlistdirr2chmodchownmkdirremoveunlinkrmdirutimelchownchrootlstat startfilemkfifomknodpathconfaccesscsttfdd}|S)NcsB|jr2|j|f||}|j|f||S|f||S)N)rr _remap_output)rEr'r}r)rrr r!rMsz4AbstractSandbox._mk_single_with_return..wrap)rr)rrr )rrr!_mk_single_with_returnJs z&AbstractSandbox._mk_single_with_returnreadlinktempnamcsttfdd}|S)Ncs ||}|jr|j|S|S)N)rr)rEr}rretval)rrr r!r\s  z'AbstractSandbox._mk_query..wrap)rr)rrr )rrr! _mk_queryYs zAbstractSandbox._mk_queryr1tmpnamcCs|S)z=Called to remap or validate any path, whether input or outputr )rEr'r r r!_validate_pathhszAbstractSandbox._validate_pathcOs |j|S)zCalled for path inputs)r)rE operationr'r}rr r r!rlszAbstractSandbox._remap_inputcCs |j|S)zCalled for path outputs)r)rErr'r r r!rpszAbstractSandbox._remap_outputcOs0|j|d|f|||j|d|f||fS)z?Called for path pairs like rename, link, and symlink operationsz-fromz-to)r)rErrrr}rr r r!rtszAbstractSandbox._remap_pair)rrr)N)rrr2rrrrrrrrrrrrrrrr)rr)r1r)r?r@rArBrrtrrFrJrrrrrrrrrrrrrrrr r r r!rsB          devnullc@seZdZdZejdddddddd d d d d dg ZdgZefddZ ddZ e rXd'ddZ d(ddZ ddZ ddZddZdd Zd!d"Zd)d$d%Zd&S)*r z.) r0r'rr_sandboxr`_prefix _exceptionsrrt)rEZsandbox exceptionsr r r!rts  zDirectorySandbox.__init__cOsddlm}||||dS)Nr)r )r9r )rErr}rr r r r! _violations zDirectorySandbox._violationrcOs<|dkr*|j| r*|jd||f||t||f||S)Nrrtr rUUr)rrr rr)_okrr)rEr'rr}rr r r!rszDirectorySandbox._filecOs<|dkr*|j| r*|jd||f||t||f||S)Nrrr rrr)rrr rr)rrr)rEr'rr}rr r r!rszDirectorySandbox._opencCs|jddS)Nr)r)rEr r r!rszDirectorySandbox.tmpnamc CsN|j}z:d|_tjjtjj|}|j|p@||jkp@|j|jS||_XdS)NF) rr0r'rr _exemptedrrOr)rEr'Zactiverr r r!rs   zDirectorySandbox._okcs<fdd|jD}fdd|jD}tj||}t|S)Nc3s|]}j|VqdS)N)rO)rP exception)filepathr r!rRsz-DirectorySandbox._exempted..c3s|]}tj|VqdS)N)rfrh)rPri)rr r!rRs)r_exception_patterns itertoolschainany)rErZ start_matchesZpattern_matches candidatesr )rr!rs      zDirectorySandbox._exemptedcOs6||jkr2|j| r2|j|tjj|f|||S)zCalled for path inputs) write_opsrrr0r'r)rErr'r}rr r r!rszDirectorySandbox._remap_inputcOs6|j| s|j| r.|j|||f||||fS)z?Called for path pairs like rename, link, and symlink operations)rr)rErrrr}rr r r!rszDirectorySandbox._remap_paircOsB|t@r,|j| r,|jd|||f||tj|||f||S)zCalled for low-level os.open()zos.open) WRITE_FLAGSrrrr)rErflagsrr}rr r r!rszDirectorySandbox.openN)r)r)r)r?r@rArBr{fromkeysrr _EXCEPTIONSrtrrrrrrrrrr r r r!r s      cCsg|]}tt|dqS)r)rr)rPar r r!rsrz4O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARYc@s&eZdZdZejdjZddZdS)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\}}}|jjftS)N)r}tmplformatr)rEcmdr}kwargsr r r!__str__s zSandboxViolation.__str__N) r?r@rArBtextwrapdedentlstriprrr r r r!r s )N)N)=r0rr,operator functoolsrrf contextlibr6rZsetuptools.externrZsetuptools.extern.six.movesrrZpkg_resources.py31compatr*platformrOZ$org.python.modules.posix.PosixModulepythonrSposixZ PosixModulerrrr NameErrorrrZdistutils.errorsrr__all__r"contextmanagerr&r(r/r4r8r5rDrXrVr]rerjrar rrrrr reduceor_splitrr r r r r!s^             w  V