a [dgG7@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZejdrddlmmmmZn ejejZzeZWneydZYn0eZgdZd-ddZejd.dd Z ejd d Z!ejd d Z"ejddZ#Gddde$Z%GdddZ&ejddZ'ddZ(ejddZ)ejddZ*hdZ+ddZ,dd Z-d!d"Z.Gd#d$d$Z/e0ed%rej1gZ2ngZ2Gd&d'd'e/Z3e4ej5d(d)d*6DZ7Gd+d,d,e Z8dS)/N)DistutilsError) working_setjava)AbstractSandboxDirectorySandboxSandboxViolation run_setupcCs^d}t||}|}Wdn1s,0Y|durB|}t||d}t|||dS)z. Python 3 implementation of execfile. rbNexec)openreadcompiler )filenameglobalslocalsmodestreamZscriptcoderN)varsmapr+loadsr>with_tracebackr?)r;r1r2rrrresumes zExceptionSaver.resumeN)r4r5r6r7r<rArFrrrrr9ps r9c#sjtjt}VWdn1s,0YtjfddtjD}t||dS)z Context in which imported modules are saved. Translates exceptions internal to the context into the equivalent exception outside the context. Nc3s$|]}|vr|ds|VqdS)z encodings.N startswith).0mod_namerrr s zsave_modules..)rmodulescopyr9update_clear_modulesrF) saved_excZ del_modulesrrr save_moduless $  rQcCst|D] }tj|=qdSr)listrrL) module_namesrJrrrrOs rOc cs.t}z|VWt|n t|0dSr) pkg_resources __getstate__ __setstate__rrrrsave_pkg_resources_statesrWc cstj|d}tttttnt|Ft |t ddVWdn1sj0YWdn1s0YWdn1s0YWdn1s0YWdn1s0YWdn1s0YdS)NZtemp setuptools) r!rjoinrWrQrhide_setuptoolsrr%r) __import__) setup_dirZtemp_dirrrr setup_contexts  r]>rTZCythonrX_distutils_hackZ distutilscCs|ddd}|tvS)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 .r)split_MODULES_TO_HIDE)rJZ base_modulerrr _needs_hidingsrccCs6tjdd}|dur|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. r^N)rrLgetZ remove_shimfilterrcrO)r^rLrrrrZs  rZc Cstjtj|}t|z|gt|tjdd<tjd|t t j ddt |&t|dd}t||Wdn1s0YWn6ty}z|jr|jdrWYd}~n d}~00Wdn1s0YdS)z8Run a distutils setup script, sandboxed in its directoryNrcSs|Sr)Zactivate)distrrrzrun_setup..__main__)__file__r4)r!rabspathdirnamer]rRrrinsertr__init__Z callbacksappendrdictr SystemExitargs)Z setup_scriptrrr\nsvrrrrs   ,rc@seZdZdZdZddZddZddZd d Zd d Z d dZ dD]Z e e e rDe e ee <qDd$ddZerzedeZedeZdD]Z e e e ree ee <qddZdD]Z e e e ree ee <qddZdD]Z e e e ree ee <qddZddZd d!Zd"d#ZdS)%rzDWrap 'os' module and 'open()' builtin for virtualizing setup scriptsFcsfddttD_dS)Ncs$g|]}|dst|r|qS)_)rHhasattr)rInamer:rr sz,AbstractSandbox.__init__..)dir_os_attrsr:rr:rrn s zAbstractSandbox.__init__cCs"|jD]}tt|t||qdSr)r{setattrr!getattr)r;sourcerwrrr_copys zAbstractSandbox._copycCs(||tr|jt_|jt_d|_dSr=)r_filebuiltinsfile_openr _activer:rrrr<s  zAbstractSandbox.__enter__cCs$d|_trtt_tt_|tdSNF)rrrrrr rrz)r;exc_type exc_value tracebackrrrrAs zAbstractSandbox.__exit__cCs.||WdS1s 0YdS)zRun 'func' under os sandboxingNr)r;funcrrrrun"szAbstractSandbox.runcsttfdd}|S)Ncs>|jr&|j||g|Ri|\}}||g|Ri|Sr)r _remap_pair)r;srcdstrrkwrworiginalrrwrap*s z3AbstractSandbox._mk_dual_path_wrapper..wrapr}rzrwrrrr_mk_dual_path_wrapper's z%AbstractSandbox._mk_dual_path_wrapper)renamelinksymlinkNcs p ttfdd}|S)Ncs6|jr |j|g|Ri|}|g|Ri|Sr)r _remap_inputr;rrrrrrrr8sz5AbstractSandbox._mk_single_path_wrapper..wrapr)rwrrrrr_mk_single_path_wrapper5sz'AbstractSandbox._mk_single_path_wrapperrr )statlistdirr'r chmodchownmkdirremoveunlinkrmdirutimelchownchrootlstatZ startfilemkfifomknodpathconfaccesscsttfdd}|S)NcsT|jr>|j|g|Ri|}||g|Ri|S|g|Ri|Sr)rr _remap_outputrrrrrMsz4AbstractSandbox._mk_single_with_return..wraprrrrr_mk_single_with_returnJs z&AbstractSandbox._mk_single_with_return)readlinktempnamcsttfdd}|S)Ncs$|i|}|jr ||S|Sr)rr)r;rrrZretvalrrrr\s z'AbstractSandbox._mk_query..wraprrrrr _mk_queryYs zAbstractSandbox._mk_query)r&tmpnamcCs|S)z=Called to remap or validate any path, whether input or outputr)r;rrrr_validate_pathhszAbstractSandbox._validate_pathcOs ||SzCalled for path inputsrr; operationrrrrrrrrlszAbstractSandbox._remap_inputcCs ||S)zCalled for path outputsr)r;rrrrrrpszAbstractSandbox._remap_outputcOs<|j|d|g|Ri||j|d|g|Ri|fS)?Called for path pairs like rename, link, and symlink operationsz-fromz-to)rr;rrrrrrrrrrtszAbstractSandbox._remap_pair)N)r4r5r6r7rrnrr<rArrrwrvrzrrrrrrrrrrrrrrrs<          rdevnullc@seZdZdZegdZdgZefddZ ddZ e rBdd d Z dd d Z d dZ ddZddZddZddZdddZdS)rz.) r!rrr_sandboxrY_prefix _exceptionsrrn)r;Zsandbox exceptionsrrrrns zDirectorySandbox.__init__cOsddlm}||||dS)Nr)r)r.r)r;rrrrrrrr _violations zDirectorySandbox._violationrcOsF|dvr.||s.|jd||g|Ri|t||g|Ri|S)NrZrtr ZrUUr)_okrrr;rrrrrrrrrszDirectorySandbox._filecOsF|dvr.||s.|jd||g|Ri|t||g|Ri|S)Nrr )rrrrrrrrszDirectorySandbox._opencCs|ddS)Nr)rr:rrrrszDirectorySandbox.tmpnamcCsV|j}zBd|_tjtj|}||p@||jkp@||jW||_S||_0dSr) rr!rrr _exemptedrrHr)r;rZactiverrrrrs  zDirectorySandbox._okcs<fdd|jD}fdd|jD}t||}t|S)Nc3s|]}|VqdSrrG)rI exceptionfilepathrrrKsz-DirectorySandbox._exempted..c3s|]}t|VqdSr)rematch)rIpatternrrrrKs)r_exception_patterns itertoolschainany)r;rZ start_matchesZpattern_matchesZ candidatesrrrrs   zDirectorySandbox._exemptedcOs:||jvr6||s6|j|tj|g|Ri||Sr) write_opsrrr!rrrrrrrs"zDirectorySandbox._remap_inputcOs8||r||s0|j|||g|Ri|||fS)r)rrrrrrrszDirectorySandbox._remap_paircOsL|t@r0||s0|jd|||g|Ri|tj|||g|Ri|S)zCalled for low-level os.open()zos.open) WRITE_FLAGSrrrzr )r;rflagsrrrrrrrr szDirectorySandbox.openN)r)r)r)r4r5r6r7rpfromkeysrr _EXCEPTIONSrnrrrrrrrrr rrrrrs     rcCsg|]}tt|dqS)rr)rIarrrrxsrxz4O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARYc@s&eZdZdZedZddZdS)rzEA 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\}}}|jjfitSr)rrtmplformatr)r;cmdrrkwargsrrr__str__s zSandboxViolation.__str__N) r4r5r6r7textwrapdedentlstriprrrrrrrs r)N)N)9r!rr#operator functoolsrr contextlibr+rrrTZdistutils.errorsrrplatformrHZ$org.python.modules.posix.PosixModuleZpythonrLposixZ PosixModulerzrwrr NameErrorr r__all__rcontextmanagerrrr%r)r-r*r9rQrOrWr]rbrcrZrrrvrrrreduceor_rarrrrrrsn                w  V