Y7 @sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddl Z ejjdrddljjjjZnejejZy eZWnek rdZYnXeZddlmZddl mZdddd gZdd d Z ej!dd d Z"ej!ddZ#ej!ddZ$ej!ddZ%Gddde&Z'GdddZ(ej!ddZ)ddZ*ej!ddZ+ej!ddZ,d d!Z-d"d#Z.d$d Z/Gd%ddZ0e1ed&rcej2gZ3ngZ3Gd'dde0Z4ej5ej6d(d)d*j7DZ8Gd+ddeZ9dS),N)builtinsmapjava)DistutilsError) working_setAbstractSandboxDirectorySandboxSandboxViolation run_setupc Csd}t||}|j}WdQRXtjddd ksvtjddd krtjddd kr|jdd}|jd d}|dkr|}t||d }t|||dS)z. Python 3 implementation of execfile. rbNrs s s exec)r r )rr)rr )openreadsys version_inforeplacecompiler)filenameglobalslocalsmodestreamscriptcoder8/tmp/pip-build-3puug3g5/setuptools/setuptools/sandbox.py _execfile!sK rc csVtjdd}|dk r2|tjddtk r`ddlm}|j||t|SYnXdS)z Always return a dumped (pickled) type and exc. If exc can't be pickled, wrap it in UnpickleableException first. r)r1N)pickledumps Exceptionsetuptools.sandboxr1dumprepr)typeexcclsrrrr6gs   zUnpickleableException.dumpN)__name__ __module__ __qualname____doc__ staticmethodr6rrrrr1bs r1c@s:eZdZdZddZddZddZdS) ExceptionSaverz^ A Context Manager that will save an exception, serialized, and restore it later. cCs|S)Nr)selfrrr __enter__{szExceptionSaver.__enter__cCs,|s dStj|||_||_dS)NT)r1r6_saved_tb)rAr8r9tbrrr__exit__~s  zExceptionSaver.__exit__cCsKdt|krdSttj|j\}}tj|||jdS)z"restore and re-raise any exceptionrCN)varsrr2loadsrCsixreraiserD)rAr8r9rrrresumeszExceptionSaver.resumeN)r;r<r=r>rBrFrKrrrrr@us   r@c #sktjjt }VWdQRXtjjfddtjD}t||jdS)z Context in which imported modules are saved. Translates exceptions internal to the context into the equivalent exception outside the context. Nc3s1|]'}|kr|jd r|VqdS)z encodings.N) startswith).0mod_name)r"rr s zsave_modules..)rmodulescopyr@update_clear_modulesrK) saved_excZ del_modulesr)r"r save_moduless   rUcCs%xt|D]}tj|=q WdS)N)listrrP) module_namesrNrrrrSsrSc cs*tj}z |VWdtj|XdS)N) pkg_resources __getstate__ __setstate__)r"rrrsave_pkg_resources_states  r[c,cstjj|d}tvtettMt<t|(t |t ddVWdQRXWdQRXWdQRXWdQRXWdQRXWdQRXdS)Ntemp setuptools) r&r$joinr[rUhide_setuptoolsr%r#r,r0 __import__) setup_dirtemp_dirrrr setup_contexts       rccCs"tjd}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)rNpatternrrr _needs_hidingsrhcCs tttj}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)filterrhrrPrS)rPrrrr_sr_cs tjjtjj}t|ygt|tjddtk r}z|jr|jdrWYdd}~XnXWdQRXdS)z8Run a distutils setup script, sandboxed in its directoryNrcSs |jS)N)activate)distrrrszrun_setup..cs&tddd}t|dS)N__file__r;__main__)dictr)ns) dunder_file setup_scriptrrrunnerszrun_setup..runner)r&r$abspathdirnamercrVrr insertr__init__ callbacksappend isinstancestrencodegetfilesystemencodingrrun SystemExitargs)rrrrarsvr)rqrrrr s   c@seZdZdZdZddZddZddZd d Zx9d d d gD](Z e e e rXee e e s z,AbstractSandbox.__init__..)dir_os_attrs)rAr)rArrw szAbstractSandbox.__init__cCs1x*|jD]}tt|t||q WdS)N)rsetattrr&getattr)rAsourcerrrr_copyszAbstractSandbox._copyc Csuz?|j|tr"|jt_|jt_d|_|SWdd|_trZtt_tt_|jtXdS)zRun 'func' under os sandboxingTNF)r_filerfile_openr_activer)rAfuncrrrr~s        zAbstractSandbox.runcs(ttfdd}|S)Ncs=|jr*|j||||\}}||||S)N)r _remap_pair)rAsrcdstrkw)roriginalrrwrap(s !z3AbstractSandbox._mk_dual_path_wrapper..wrap)rr)rrr)rrr_mk_dual_path_wrapper%sz%AbstractSandbox._mk_dual_path_wrapperrenamelinksymlinkNcs.pttfdd}|S)Ncs1|jr!|j|||}|||S)N)r _remap_input)rAr$rr)rrrrr6s z5AbstractSandbox._mk_single_path_wrapper..wrap)rr)rrrr)rrr_mk_single_path_wrapper3sz'AbstractSandbox._mk_single_path_wrapperrrstatlistdirr.chmodchownmkdirremoveunlinkrmdirutimelchownchrootlstatZ startfilemkfifomknodpathconfaccesscs(ttfdd}|S)NcsM|jr=|j|||}|j|||S|||S)N)rr _remap_output)rAr$rr)rrrrrKs z4AbstractSandbox._mk_single_with_return..wrap)rr)rrr)rrr_mk_single_with_returnHsz&AbstractSandbox._mk_single_with_returnreadlinktempnamcs(ttfdd}|S)Ncs,||}|jr(|j|S|S)N)rr)rArrretval)rrrrrZs z'AbstractSandbox._mk_query..wrap)rr)rrr)rrr _mk_queryWszAbstractSandbox._mk_queryr-tmpnamcCs|S)z=Called to remap or validate any path, whether input or outputr)rAr$rrr_validate_pathfszAbstractSandbox._validate_pathcOs |j|S)zCalled for path inputs)r)rA operationr$rrrrrrjszAbstractSandbox._remap_inputcCs |j|S)zCalled for path outputs)r)rArr$rrrrnszAbstractSandbox._remap_outputcOs6|j|d||||j|d|||fS)z?Called for path pairs like rename, link, and symlink operationsz-fromz-to)r)rArrrrrrrrrrszAbstractSandbox._remap_pair)r;r<r=r>rrwrr~rrrrrrrrrrrrrrrrrrrs>           devnullc@seZdZdZejdddddddd d d d d dg ZdgZeddZ ddZ e rdddZ dddZ ddZ ddZddZdd Zd!d"Zd#d$d%Zd&S)'rz.) r&r$rr_sandboxr^_prefix _exceptionsrrw)rAZsandbox exceptionsrrrrws !  zDirectorySandbox.__init__cOs&ddlm}||||dS)Nr)r )r5r )rArrrr rrr _violationszDirectorySandbox._violationrcOsH|dkr5|j| r5|jd||||t||||S)Nrrtr rUUr)rzrtzrbzrUr)_okrr)rAr$rrrrrrrszDirectorySandbox._filecOsH|dkr5|j| r5|jd||||t||||S)Nrrr rrr)rzrtzrbzrUr)rrr)rAr$rrrrrrrszDirectorySandbox._opencCs|jddS)Nr)r)rArrrrszDirectorySandbox.tmpnamc Css|j}zYd|_tjjtjj|}|j|p`||jkp`|j|jSWd||_XdS)NF) rr&r$rr _exemptedrrLr)rAr$Zactiverrrrrs  zDirectorySandbox._okcsTfdd|jD}fdd|jD}tj||}t|S)Nc3s|]}j|VqdS)N)rL)rM exception)filepathrrrOsz-DirectorySandbox._exempted..c3s!|]}tj|VqdS)N)rdrf)rMrg)rrrrOs)r_exception_patterns itertoolschainany)rArZ start_matchesZpattern_matches candidatesr)rrrs   zDirectorySandbox._exemptedcOsE||jkrA|j| rA|j|tjj||||S)zCalled for path inputs) write_opsrrr&r$r)rArr$rrrrrrs"zDirectorySandbox._remap_inputcOsC|j| s |j| r9|j|||||||fS)z?Called for path pairs like rename, link, and symlink operations)rr)rArrrrrrrrrs zDirectorySandbox._remap_pairicOsO|t@r6|j| r6|jd|||||tj|||||S)zCalled for low-level os.open()zos.open) WRITE_FLAGSrrrr)rArflagsrrrrrrrszDirectorySandbox.openN)r;r<r=r>rofromkeysrr _EXCEPTIONSrwrrrrrrrrrrrrrrs      cCs"g|]}tt|dqS)r)rr)rMarrrrs rz4O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARYc@s"eZdZdZddZdS)r zEA setup script attempted to modify the filesystem outside the sandboxcCs d|jS)NaSandboxViolation: %s%r %s 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.)r)rArrr__str__s zSandboxViolation.__str__N)r;r<r=r>rrrrrr s ):r&rr)operator functoolsrrd contextlibr2rIZ six.movesrrrXplatformrLZ$org.python.modules.posix.PosixModulepythonrPposixZ PosixModulerrrr NameErrorrrdistutils.errorsrr__all__rcontextmanagerr#r%r,r0r4r1r@rUrSr[rcrhr_r rrrrrreduceor_splitrr rrrrs\                     tV