a c7@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZddlZejdrddlmmmmZn ejejZzeZWneydZYn0eZddlm Z ddlm!Z!gdZ"d.dd Z#ej$d/d d Z%ej$d d Z&ej$ddZ'ej$ddZ(Gddde)Z*GdddZ+ej$ddZ,ddZ-ej$ddZ.ej$ddZ/ddZ0d d!Z1d"d#Z2Gd$d%d%Z3e4ed&rej5gZ6ngZ6Gd'd(d(e3Z7e8ej9d)d*d+:DZ;Gd,d-d-e ZrCrHrLrrrrr@rs r@c#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_namer"rr s zsave_modules..)rmodulescopyr@update_clear_modulesrL) saved_excZ del_modulesrr"r save_moduless $  rWcCst|D] }tj|=qdSr)listrrR)Z module_namesrPrrrrUs rUc cs.t}z|VWt|n t|0dSr)r% __getstate__ __setstate__r"rrrsave_pkg_resources_statesr[c cstj|d}tttttnt|Ft |t ddVWdn1sj0YWdn1s0YWdn1s0YWdn1s0YWdn1s0YWdn1s0YdS)Ntemp setuptools) r,r!joinr[rWhide_setuptoolsr#r r+r0 __import__) setup_dirtemp_dirrrr setup_contexts  rccCstd}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)(\.|$))rerboolmatch)rPpatternrrr _needs_hidings rhcCstttj}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)filterrhrrRrU)rRrrrr_s r_c Cstjtj|}t|z|gt|tjdd<tjd|t t j ddt |trl|n |t}t|&t|dd}t||Wdn1s0YWn6ty}z|jr|jdr܂WYd}~n d}~00Wdn1s0YdS)z8Run a distutils setup script, sandboxed in its directoryNrcSs|Sr)activate)distrrrzrun_setup..__main__)__file__r;)r,r!abspathdirnamercrXrrinsertr__init__ callbacksappend isinstancestrencodegetfilesystemencodingr dictr SystemExitargs)Z setup_scriptr|raZ dunder_filensvrrrr s"    ,r c@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)_)rNhasattr)rOnamerArr sz,AbstractSandbox.__init__..)dir_os_attrsrArrArrss zAbstractSandbox.__init__cCs"|jD]}tt|t||qdSr)rsetattrr,getattr)rBsourcerrrr_copy s zAbstractSandbox._copycCs(||tr|jt_|jt_d|_dSrD)r_filerfile_openr_activerArrrrCs  zAbstractSandbox.__enter__cCs$d|_trtt_tt_|tdSNF)rrrrrrrr)rBexc_type exc_value tracebackrrrrHs zAbstractSandbox.__exit__cCs.||WdS1s 0YdS)zRun 'func' under os sandboxingNr)rBfuncrrrrunszAbstractSandbox.runcsttfdd}|S)Ncs>|jr&|j||g|Ri|\}}||g|Ri|Sr)r _remap_pair)rBsrcdstr|kwroriginalrrwrap&s z3AbstractSandbox._mk_dual_path_wrapper..wraprrrrrrr_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_inputrBr!r|rrrrr4sz5AbstractSandbox._mk_single_path_wrapper..wrapr)rrrrrr_mk_single_path_wrapper1sz'AbstractSandbox._mk_single_path_wrapperrr)statlistdirr.rchmodchownmkdirremoveunlinkrmdirutimelchownchrootlstatZ startfilemkfifomknodpathconfaccesscsttfdd}|S)NcsT|jr>|j|g|Ri|}||g|Ri|S|g|Ri|Sr)rr _remap_outputrrrrrIsz4AbstractSandbox._mk_single_with_return..wraprrrrr_mk_single_with_returnFs z&AbstractSandbox._mk_single_with_return)readlinktempnamcsttfdd}|S)Ncs$|i|}|jr ||S|Sr)rr)rBr|rretvalrrrrXs z'AbstractSandbox._mk_query..wraprrrrr _mk_queryUs zAbstractSandbox._mk_query)r-tmpnamcCs|S)z=Called to remap or validate any path, whether input or outputr)rBr!rrr_validate_pathdszAbstractSandbox._validate_pathcOs ||SzCalled for path inputsrrB operationr!r|rrrrrhszAbstractSandbox._remap_inputcCs ||S)zCalled for path outputsr)rBrr!rrrrlszAbstractSandbox._remap_outputcOs<|j|d|g|Ri||j|d|g|Ri|fS)?Called for path pairs like rename, link, and symlink operationsz-fromz-to)rrBrrrr|rrrrrpszAbstractSandbox._remap_pair)N)r;r<r=r>rrsrrCrHrrrrrrrrrrrrrrrrrrrrs<          rdevnullc@seZdZdZegdZdgZefddZ ddZ e rBdd d Z dd d Z d dZ ddZddZddZddZdddZdS)r z.) r,r!rr_sandboxr^_prefix _exceptionsrrs)rBZsandbox exceptionsrrrrss zDirectorySandbox.__init__cOsddlm}||||dS)Nr)r )r5r )rBrr|rr rrr _violations zDirectorySandbox._violationrcOsF|dvr.||s.|jd||g|Ri|t||g|Ri|S)Nrrtr ZrUUr)_okrrrBr!rr|rrrrrszDirectorySandbox._filecOsF|dvr.||s.|jd||g|Ri|t||g|Ri|S)Nrr)rrrrrrrrszDirectorySandbox._opencCs|ddS)Nr)rrArrrrszDirectorySandbox.tmpnamcCsV|j}zBd|_tjtj|}||p@||jkp@||jW||_S||_0dSr) rr,r!rr _exemptedrrNr)rBr!activerrrrrs  zDirectorySandbox._okcs<fdd|jD}fdd|jD}t||}t|S)Nc3s|]}|VqdSrrM)rO exceptionfilepathrrrQsz-DirectorySandbox._exempted..c3s|]}t|VqdSr)rdrf)rOrgrrrrQs)r_exception_patterns itertoolschainany)rBrZ start_matchesZpattern_matches candidatesrrrrs   zDirectorySandbox._exemptedcOs:||jvr6||s6|j|tj|g|Ri||Sr) write_opsrrr,r!rrrrrrs"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_FLAGSrrrr)rBrflagsrr|rrrrrszDirectorySandbox.openN)r)r)r)r;r<r=r>rzfromkeysrr _EXCEPTIONSrsrrrrrrrrrrrrrr ~s     r cCsg|]}tt|dqS)rr)rOarrrrrmrz4O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARYc@s&eZdZdZedZddZdS)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\}}}|jjfitSr)r|tmplformatr)rBcmdr|kwargsrrr__str__s zSandboxViolation.__str__N) r;r<r=r>textwrapdedentlstriprrrrrrr s r )N)N)=r,rr(operator functoolsrrd contextlibr2rZsetuptools.externrZsetuptools.extern.six.movesrrZpkg_resources.py31compatr%platformrNZ$org.python.modules.posix.PosixModulepythonrRposixZ PosixModulerrrr NameErrorrrdistutils.errorsrr__all__rcontextmanagerr r#r+r0r4r1r@rWrUr[rcrhr_r rrrrr reduceor_splitrr rrrrsn                 w  V