o )a 8@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZejdrRddlmmmmZnejejZzeZWn eygdZYnweZgdZd-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|| }|}Wdn1swY|dur!|}t||d}t|||dS)z. Python 3 implementation of execfile. rbNexec)openreadcompiler )filenameglobalslocalsmodestreamZscriptcoderE/opt/alt/python310/lib/python3.10/site-packages/setuptools/sandbox.py _execfile$s   rc csRtjdd}|dur|tjdd<z |VW|tjdd<dS|tjdd<wN)sysargv)replsavedrrr save_argv1s"rc cs<tjdd}z |VW|tjdd<dS|tjdd<wr)rpathrrrr save_path<s "rccs8tj|ddtj}|t_z dVW|t_dS|t_w)zL Monkey-patch tempfile.tempdir with replacement, ensuring it exists T)exist_okN)osmakedirstempfileZtempdir)Z replacementrrrr override_tempEsr$c cs8t}t|z |VWt|dSt|wr)r!getcwdchdir)targetrrrrpushdVs  r(c@seZdZdZeddZdS)UnpickleableExceptionzP An exception representing another Exception that could not be pickled. c CsJz t|t|fWSty$ddlm}|||t|YSw)z Always return a dumped (pickled) type and exc. If exc can't be pickled, wrap it in UnpickleableException first. r)r))pickledumps Exceptionsetuptools.sandboxr)dumprepr)typeexcclsrrrr.es   zUnpickleableException.dumpN)__name__ __module__ __qualname____doc__ staticmethodr.rrrrr)`sr)c@s(eZdZdZddZddZddZdS) ExceptionSaverz^ A Context Manager that will save an exception, serialized, and restore it later. cCs|Srrselfrrr __enter__zszExceptionSaver.__enter__cCs |sdSt|||_||_dSNT)r)r._saved_tb)r:r0r1tbrrr__exit__}s zExceptionSaver.__exit__cCs.dt|vrdSttj|j\}}||j)z"restore and re-raise any exceptionr=N)varsmapr*loadsr=with_tracebackr>)r:r0r1rrrresumes  zExceptionSaver.resumeN)r3r4r5r6r;r@rErrrrr8ts  r8c#sltjt }VWdn1swYtjfddtjD}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..)rmodulescopyr8update_clear_modulesrE) saved_excZ del_modulesrrr save_moduless    rPcCst|D]}tj|=qdSr)listrrK)Z module_namesrIrrrrNs  rNc cs.t}z |VWt|dSt|wr) pkg_resources __getstate__ __setstate__rrrrsave_pkg_resources_states rUc cs"tj|d}t|t`tMtt7t|#t |t ddVWdn1s6wYWdn1sEwYWdn1sTwYWdn1scwYWdn1srwYWddSWddS1swYdS)NZtemp setuptools) r!rjoinrUrPrhide_setuptoolsrr$r( __import__) setup_dirZtemp_dirrrr setup_contexts.  "r[>Z distutilsZCythonrRrV_distutils_hackcCs|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)rIZ base_modulerrr _needs_hidingsracCs6tjdd}|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)rrKgetZ remove_shimfilterrarN)r\rKrrrrXs   rXc Cs tjtj|}t|mz@|gt|tjdd<tjd|t t j ddt |t|dd}t||Wdn1sIwYWntyj}z|jr`|jdr`WYd}~n d}~wwWddSWddS1s~wYdS)z8Run a distutils setup script, sandboxed in its directoryNrcSs|Sr)Zactivate)Zdistrrrszrun_setup..__main__)__file__r3)r!rabspathdirnamer[rQrrinsertr__init__Z callbacksappendrdictr SystemExitargs)Z setup_scriptrnrZnsvrrrrs*    "rc@seZdZdZdZddZddZddZd d Zd d Z d dZ dD]Z e e e r0e e ee <q"d$ddZer=edeZedeZdD]Z e e e rRee ee <qDddZdD]Z e e e rgee ee <qYddZdD]Z e e e r|ee ee <qnddZddZd d!Zd"d#ZdS)%rzDWrap 'os' module and 'open()' builtin for virtualizing setup scriptsFcsfddttD_dS)Ncs$g|]}|dst|r|qS)_)rGhasattr)rHnamer9rr sz,AbstractSandbox.__init__..)dir_os_attrsr9rr9rrjs  zAbstractSandbox.__init__cCs"|jD] }tt|t||qdSr)rwsetattrr!getattr)r:sourcersrrr_copys zAbstractSandbox._copycCs(||tr |jt_|jt_d|_dSr<)r{_filebuiltinsfile_openr _activer9rrrr;s  zAbstractSandbox.__enter__cCs$d|_trtt_tt_|tdSNF)rr|r}r~rr r{rv)r:exc_type exc_value tracebackrrrr@!s zAbstractSandbox.__exit__cCs.| |WdS1swYdS)zRun 'func' under os sandboxingNr)r:funcrrrrun(s$zAbstractSandbox.runcttfdd}|S)Ncs>|jr|j||g|Ri|\}}||g|Ri|Sr)r _remap_pair)r:srcdstrnkwrsoriginalrrwrap0s z3AbstractSandbox._mk_dual_path_wrapper..wrapryrvrsrrrr_mk_dual_path_wrapper-s z%AbstractSandbox._mk_dual_path_wrapper)renamelinksymlinkNcs pttfdd}|S)Ncs6|jr|j|g|Ri|}|g|Ri|Sr)r _remap_inputr:rrnrrrrr>sz5AbstractSandbox._mk_single_path_wrapper..wrapr)rsrrrrr_mk_single_path_wrapper;sz'AbstractSandbox._mk_single_path_wrapperr~r )statlistdirr&r chmodchownmkdirremoveunlinkrmdirutimelchownchrootlstatZ startfilemkfifomknodpathconfaccesscr)NcsT|jr|j|g|Ri|}||g|Ri|S|g|Ri|Sr)rr _remap_outputrrrrrcsz4AbstractSandbox._mk_single_with_return..wraprrrrr_mk_single_with_return` z&AbstractSandbox._mk_single_with_return)readlinktempnamcr)Ncs$|i|}|jr||S|Sr)rr)r:rnrZretvalrrrrrs z'AbstractSandbox._mk_query..wraprrrrr _mk_queryorzAbstractSandbox._mk_query)r%tmpnamcCs|S)z=Called to remap or validate any path, whether input or outputr)r:rrrr_validate_path~szAbstractSandbox._validate_pathcO ||SzCalled for path inputsrr: operationrrnrrrrr zAbstractSandbox._remap_inputcCr)zCalled for path outputsr)r:rrrrrrrzAbstractSandbox._remap_outputcOs<|j|d|g|Ri||j|d|g|Ri|fS)?Called for path pairs like rename, link, and symlink operationsz-fromz-to)rr:rrrrnrrrrrszAbstractSandbox._remap_pairr)r3r4r5r6rrjr{r;r@rrrsrrrvrrr|rrrrrrrrrrrr sF        rdevnullc@seZdZdZegdZgZ efddZ ddZ e r!ddd Z dd d Z d d Z ddZddZddZddZdddZdS)rz.) r!rrr_sandboxrW_prefix _exceptionsrrj)r:Zsandbox exceptionsrrrrjs zDirectorySandbox.__init__cOsddlm}||||)Nr)r)r-r)r:rrnrrrrr _violations  zDirectorySandbox._violationrcOF|dvr||s|jd||g|Ri|t||g|Ri|S)NrZrtr ZrUUr~)_okrr|r:rrrnrrrrr|zDirectorySandbox._filecOr)Nrr )rrrrrrrrrzDirectorySandbox._opencCs|ddS)Nr)rr9rrrrszDirectorySandbox.tmpnamcCsR|j}z!d|_tjtj|}||p ||jkp ||jW||_S||_wr) rr!rrr _exemptedrrGr)r:rZactiverrrrrs  zDirectorySandbox._okcs<fdd|jD}fdd|jD}t||}t|S)Nc3s|]}|VqdSrrF)rH exceptionfilepathrrrJs  z-DirectorySandbox._exempted..c3s|] }t|VqdSr)rematch)rHpatternrrrrJs  )r_exception_patterns itertoolschainany)r:rZ start_matchesZpattern_matchesZ candidatesrrrrs   zDirectorySandbox._exemptedcOs:||jvr||s|j|tj|g|Ri||Sr) write_opsrrr!rrrrrrrs"zDirectorySandbox._remap_inputcOs8||r ||s|j|||g|Ri|||fS)r)rrrrrrrszDirectorySandbox._remap_paircOsL|t@r||s|jd|||g|Ri|tj|||g|Ri|S)zCalled for low-level os.open()zos.open) WRITE_FLAGSrrrvr )r:r~flagsrrnrrrrr szDirectorySandbox.openN)r)r)r3r4r5r6rlfromkeysrr _EXCEPTIONSrjrr|rrrrrrr rrrrrs$     rcCsg|]}tt|dqS)rr)rHarrrrts rtz4O_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\}}}|jjditS)Nr)rntmplformatr)r:cmdrnkwargsrrr__str__s zSandboxViolation.__str__N) r3r4r5r6textwrapdedentlstriprrrrrrrs  rr)9r!rr#operator functoolsrr contextlibr*rr}rRZdistutils.errorsrrplatformrGZ$org.python.modules.posix.PosixModuleZpythonrKposixZ PosixModulervrsr~r| NameErrorr r__all__rcontextmanagerrrr$r(r,r)r8rPrNrUr[r`rarXrrrrrrrreduceor_r_rrrrrrsv                 ^