a „oe 8ã@søddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZej d¡r¤ddlmmmmZn ejejZzeZWneyÎdZYn0eZgd¢Zd-dd„Zejd.dd „ƒZ ejd d „ƒZ!ejd d „ƒZ"ejdd„ƒZ#Gdd„de$ƒZ%Gdd„dƒZ&ejdd„ƒZ'dd„Z(ejdd„ƒZ)ejdd„ƒZ*hd£Z+dd„Z,dd „Z-d!d"„Z.Gd#d$„d$ƒZ/e0ed%ƒ�r´ej1gZ2ngZ2Gd&d'„d'e/ƒZ3e 4ej5d(d)„d* 6¡Dƒ¡Z7Gd+d,„d,e ƒZ8dS)/éN)ÚDistutilsError)Ú working_setÚjava)ÚAbstractSandboxÚDirectorySandboxÚSandboxViolationÚ run_setupcCs^d}t||ƒ�}| ¡}Wdƒn1s,0Y|durB|}t||dƒ}t|||ƒdS)z. Python 3 implementation of execfile. ÚrbNÚexec)ÚopenÚreadÚcompiler )ÚfilenameÚglobalsÚlocalsÚmodeÚstreamZscriptÚcode©rú3C:\Program Files\Certbot\pkgs\setuptools\sandbox.pyÚ _execfile$s & rc csRtjdd…}|dur$|tjdd…<z|VW|tjdd…<n|tjdd…<0dS©N)ÚsysÚargv)ÚreplÚsavedrrrÚ save_argv1s rc cs<tjdd…}z|VW|tjdd…<n|tjdd…<0dSr)rÚpath©rrrrÚ save_path<srccs8tj|dd�tj}|t_zdVW|t_n|t_0dS)zL Monkey-patch tempfile.tempdir with replacement, ensuring it exists T)Úexist_okN)ÚosÚmakedirsÚtempfileZtempdir)Z replacementrrrrÚ override_tempEs r$c cs8t ¡}t |¡z|VWt |¡n t |¡0dSr)r!ÚgetcwdÚchdir)ÚtargetrrrrÚpushdVs  r(c@seZdZdZedd„ƒZdS)ÚUnpickleableExceptionzP An exception representing another Exception that could not be pickled. c CsNzt |¡t |¡fWStyHddlm}| ||t|ƒƒ¡YS0dS)z‰ Always return a dumped (pickled) type and exc. If exc can't be pickled, wrap it in UnpickleableException first. r)r)N)ÚpickleÚdumpsÚ ExceptionÚsetuptools.sandboxr)ÚdumpÚrepr)ÚtypeÚexcÚclsrrrr.es   zUnpickleableException.dumpN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú staticmethodr.rrrrr)`sr)c@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚExceptionSaverz^ A Context Manager that will save an exception, serialized, and restore it later. cCs|Srr©ÚselfrrrÚ __enter__zszExceptionSaver.__enter__cCs |sdSt ||¡|_||_dS©NT)r)r.Ú_savedÚ_tb)r:r0r1ÚtbrrrÚ__exit__}s zExceptionSaver.__exit__cCs2dt|ƒvrdSttj|jƒ\}}| |j¡‚dS)z"restore and re-raise any exceptionr=N)ÚvarsÚmapr*Úloadsr=Úwith_tracebackr>)r:r0r1rrrÚresumeˆs zExceptionSaver.resumeN)r3r4r5r6r;r@rErrrrr8ts r8c#sjtj ¡‰tƒ�}ˆVWdƒn1s,0Ytj ˆ¡‡fdd„tjDƒ}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| d¡s|VqdS)z encodings.N©Ú startswith)Ú.0Úmod_namerrrÚ  s üzsave_modules..)rÚmodulesÚcopyr8ÚupdateÚ_clear_modulesrE)Ú saved_excZ del_modulesrrrÚ save_modules’s $  þrPcCst|ƒD] }tj|=qdSr)ÚlistrrK)Z module_namesrIrrrrN¬s rNc cs.t ¡}z|VWt |¡n t |¡0dSr)Ú pkg_resourcesÚ __getstate__Ú __setstate__rrrrÚsave_pkg_resources_state±srUc cstj |d¡}tƒ�ætƒ�Àtƒ�štƒtƒ�nt|ƒ�Ft |ƒ�t dƒdVWdƒn1sj0YWdƒn1sˆ0YWdƒn1s¦0YWdƒn1sÄ0YWdƒn1sâ0YWdƒn1�s0YdS)NZtempÚ setuptools) r!rÚjoinrUrPrÚhide_setuptoolsrr$r(Ú __import__)Ú setup_dirZtemp_dirrrrÚ setup_contextºs  r[>Z distutilsrVÚ_distutils_hackZCythonrRcCs| dd¡d}|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_hidingÒsracCs6tj dd¡}|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)rrKÚgetZ _remove_shimÚfilterrarN)r\rKrrrrXçs  rXc Csøtj tj |¡¡}t|ƒ�Èz€|gt|ƒtjdd…<tj d|¡t   ¡t j   dd„¡t |ƒ�&t|dd�}t||ƒWdƒn1s’0YWn6tyÔ}z|jrÀ|jdrÀ‚WYd}~n d}~00Wdƒn1sê0YdS)z8Run a distutils setup script, sandboxed in its directoryNrcSs| ¡Sr)Zactivate)ZdistrrrÚÿózrun_setup..Ú__main__)Ú__file__r3)r!rÚabspathÚdirnamer[rQrrÚinsertrÚ__init__Z callbacksÚappendrÚdictrÚ SystemExitÚargs)Z setup_scriptrorZÚnsÚvrrrrös   ,rc@seZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dD]Z e e e ƒrDe e ƒeƒe <qDd$dd„ZerzedeƒZedeƒZdD]Z e e e ƒrˆee ƒeƒe <qˆdd„ZdD]Z e e e ƒr²ee ƒeƒe <q²dd„ZdD]Z e e e ƒrÜee ƒeƒe <qÜdd„Zdd„Zd d!„Zd"d#„ZdS)%rzDWrap 'os' module and 'open()' builtin for virtualizing setup scriptsFcs‡fdd„ttƒDƒˆ_dS)Ncs$g|]}| d¡stˆ|ƒr|‘qS)Ú_)rGÚhasattr)rHÚnamer9rrÚ sþz,AbstractSandbox.__init__..)ÚdirÚ_osÚ_attrsr9rr9rrks þzAbstractSandbox.__init__cCs"|jD]}tt|t||ƒƒqdSr)rxÚsetattrr!Úgetattr)r:ÚsourcertrrrÚ_copys zAbstractSandbox._copycCs(| |¡tr|jt_|jt_d|_dSr<)r|Ú_fileÚbuiltinsÚfileÚ_openr Ú_activer9rrrr;s  zAbstractSandbox.__enter__cCs$d|_trtt_tt_| t¡dS©NF)r�r}r~rr€r r|rw)r:Úexc_typeÚ exc_valueÚ tracebackrrrr@!s zAbstractSandbox.__exit__cCs.|�|ƒWdƒS1s 0YdS)zRun 'func' under os sandboxingNr)r:ÚfuncrrrÚrun(szAbstractSandbox.runcsttˆƒ‰‡‡fdd„}|S)Ncs>|jr&|jˆ||g|¢Ri|¤Ž\}}ˆ||g|¢Ri|¤ŽSr)r�Ú _remap_pair)r:ÚsrcÚdstroÚkw©rtÚoriginalrrÚwrap0s z3AbstractSandbox._mk_dual_path_wrapper..wrap©rzrw©rtrŽrrŒrÚ_mk_dual_path_wrapper-s z%AbstractSandbox._mk_dual_path_wrapper)ÚrenameÚlinkÚsymlinkNcs ˆp ttˆƒ‰‡‡fdd„}|S)Ncs6|jr |jˆ|g|¢Ri|¤Ž}ˆ|g|¢Ri|¤ŽSr)r�Ú _remap_input©r:rror‹rŒrrrŽ>sz5AbstractSandbox._mk_single_path_wrapper..wrapr�)rtr�rŽrrŒrÚ_mk_single_path_wrapper;sz'AbstractSandbox._mk_single_path_wrapperrr )ÚstatÚlistdirr&r ÚchmodÚchownÚmkdirÚremoveÚunlinkÚrmdirÚutimeÚlchownÚchrootÚlstatÚ startfileÚmkfifoÚmknodZpathconfÚaccesscsttˆƒ‰‡‡fdd„}|S)NcsT|jr>|jˆ|g|¢Ri|¤Ž}| ˆˆ|g|¢Ri|¤Ž¡Sˆ|g|¢Ri|¤ŽSr)r�r•Ú _remap_outputr–rŒrrrŽcsz4AbstractSandbox._mk_single_with_return..wrapr�r�rrŒrÚ_mk_single_with_return`s z&AbstractSandbox._mk_single_with_return)ÚreadlinkÚtempnamcsttˆƒ‰‡‡fdd„}|S)Ncs$ˆ|i|¤Ž}|jr | ˆ|¡S|Sr)r�r¨)r:ror‹ZretvalrŒrrrŽrs z'AbstractSandbox._mk_query..wrapr�r�rrŒrÚ _mk_queryos zAbstractSandbox._mk_query)r%ÚtmpnamcCs|S)z=Called to remap or validate any path, whether input or outputr)r:rrrrÚ_validate_path~szAbstractSandbox._validate_pathcOs | |¡S©zCalled for path inputs©r®©r:Ú operationrror‹rrrr•‚szAbstractSandbox._remap_inputcCs | |¡S)zCalled for path outputsr°)r:r²rrrrr¨†szAbstractSandbox._remap_outputcOs<|j|d|g|¢Ri|¤Ž|j|d|g|¢Ri|¤ŽfS)ú?Called for path pairs like rename, link, and symlink operationsz-fromz-to)r•©r:r²r‰rŠror‹rrrrˆŠsþzAbstractSandbox._remap_pair)N)r3r4r5r6r�rkr|r;r@r‡r‘rtrsrwrr—r}r€r©r¬r®r•r¨rˆrrrrr s<          rÚdevnullc@s€eZdZdZe gd¢¡ZgZefdd„Z dd„Z e r@ddd „Z dd d „Z d d „Z dd„Zdd„Zdd„Zdd„Zddd„ZdS)rz.) r!rr·r¸Ú_sandboxrWÚ_prefixÚ _exceptionsrrk)r:ZsandboxÚ exceptionsrrrrk°s ÿzDirectorySandbox.__init__cOsddlm}||||ƒ‚dS)Nr)r)r-r)r:r²ror‹rrrrÚ _violation¸s zDirectorySandbox._violationÚrcOsF|dvr.| |¡s.|jd||g|¢Ri|¤Žt||g|¢Ri|¤ŽS)N©r¾Zrtr ZrUÚUr)Ú_okr½r}©r:rrror‹rrrr}¿szDirectorySandbox._filecOsF|dvr.| |¡s.|jd||g|¢Ri|¤Žt||g|¢Ri|¤ŽS)Nr¿r )rÁr½r€rÂrrrr€ÄszDirectorySandbox._opencCs| d¡dS)Nr­)r½r9rrrr­ÉszDirectorySandbox.tmpnamcCsV|j}zBd|_tj tj |¡¡}| |¡p@||jkp@| |j¡W||_S||_0dSr‚) r�r!rr·r¸Ú _exemptedr¹rGrº)r:rZactiver¸rrrrÁÌs ÿ ýúzDirectorySandbox._okcs<‡fdd„|jDƒ}‡fdd„|jDƒ}t ||¡}t|ƒS)Nc3s|]}ˆ |¡VqdSrrF)rHÚ exception©ÚfilepathrrrJÚsz-DirectorySandbox._exempted..c3s|]}t |ˆ¡VqdSr)ÚreÚmatch)rHÚpatternrÅrrrJÝs)r»Ú_exception_patternsÚ itertoolsÚchainÚany)r:rÆZ start_matchesZpattern_matchesZ candidatesrrÅrrÃÙs ÿ ÿ zDirectorySandbox._exemptedcOs:||jvr6| |¡s6|j|tj |¡g|¢Ri|¤Ž|Sr¯)Ú write_opsrÁr½r!rr¸r±rrrr•ãs"zDirectorySandbox._remap_inputcOs8| |¡r| |¡s0|j|||g|¢Ri|¤Ž||fS)r³)rÁr½r´rrrrˆészDirectorySandbox._remap_pairéÿcOsL|t@r0| |¡s0|jd|||g|¢Ri|¤Žtj|||g|¢Ri|¤ŽS)zCalled for low-level os.open()zos.open)Ú WRITE_FLAGSrÁr½rwr )r:rÚflagsrror‹rrrr ïszDirectorySandbox.openN)r¾)r¾)rÏ)r3r4r5r6rmÚfromkeysrÎrÊÚ _EXCEPTIONSrkr½r}r€r­rÁrÃr•rˆr rrrrr˜s ÿ     rcCsg|]}tt|dƒ‘qS)rr�)rHÚarrrruøsÿruz4O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARYc@s&eZdZdZe d¡ ¡Zdd„ZdS)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\}}}|jjfitƒ¤ŽSr)roÚtmplÚformatr)r:ÚcmdroÚkwargsrrrÚ__str__s zSandboxViolation.__str__N) r3r4r5r6ÚtextwrapÚdedentÚlstriprÕrÙrrrrrÿs ÿr)N)N)9r!rr#ÚoperatorÚ functoolsrËrÇÚ contextlibr*rÚr~rRZdistutils.errorsrrÚplatformrGZ$org.python.modules.posix.PosixModuleZpythonrKÚposixZ PosixModulerwrtrr}Ú NameErrorr r€Ú__all__rÚcontextmanagerrrr$r(r,r)r8rPrNrUr[r`rarXrrrsrµrÓrÚreduceÚor_r_rÐrrrrrÚsr                  ^þþ