Viewing File: /opt/alt/python35/lib/python3.5/site-packages/setuptools/__pycache__/sandbox.cpython-35.pyc



\8@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZddlZejjdrddljjjjZnejejZy
eZWnek
rdZYnXeZddlm Z ddlm!Z!ddd	d
gZ"dddZ#ej$dd
dZ%ej$ddZ&ej$ddZ'ej$ddZ(Gddde)Z*GdddZ+ej$ddZ,ddZ-ej$ddZ.ej$dd Z/d!d"Z0d#d$Z1d%d
Z2Gd&ddZ3e4ed'rsej5gZ6ngZ6Gd(dde3Z7ej8ej9d)d*d+j:DZ;Gd,d	d	e Z<dS)-N)six)builtinsmapjava)DistutilsError)working_setAbstractSandboxDirectorySandboxSandboxViolation	run_setupcCsd}t||}|j}WdQRXtjdddksvtjddd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)filenameglobalslocalsmodestreamZscriptcoder/sandbox.py	_execfile#sKrc
csVtjdd}|dk	r2|tjdd<z	|VWd|tjdd<XdS)N)rargv)replsavedrrr	save_argv4s	r#c
cs7tjdd}z	|VWd|tjdd<XdS)N)rpath)r"rrr	save_path?s	r%ccsBtjj|ddtj}|t_z	dVWd|t_XdS)zL
    Monkey-patch tempfile.tempdir with replacement, ensuring it exists
    exist_okTN)
pkg_resourcesZ
py31compatmakedirstempfiletempdir)Zreplacementr"rrr
override_tempHs			r+ccs7tj}tj|z	|VWdtj|XdS)N)osgetcwdchdir)targetr"rrrpushdYs

	r0c@s(eZdZdZeddZdS)UnpickleableExceptionzP
    An exception representing another Exception that could not be pickled.
    cCsey tj|tj|fSWn>tk
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)typeexcclsrrrr6hs
 
zUnpickleableException.dumpN)__name__
__module____qualname____doc__staticmethodr6rrrrr1cs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)varsrr2loadsrCrZreraiserD)rAr8r9rrrresumeszExceptionSaver.resumeN)r;r<r=r>rBrFrIrrrrr@vs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	<genexpr>szsave_modules.<locals>.<genexpr>)rmodulescopyr@update_clear_modulesrI)	saved_excZdel_modulesr)r"rsave_moduless
rScCs%xt|D]}tj|=q
WdS)N)listrrN)module_namesrLrrrrQsrQccs*tj}z	|VWdtj|XdS)N)r'__getstate____setstate__)r"rrrsave_pkg_resources_states	rXc,cstjj|d}tvtettMt<t|(t	|t
ddVWdQRXWdQRXWdQRXWdQRXWdQRXWdQRXdS)NZtempZ
setuptools)r,r$joinrXrShide_setuptoolsr%r#r+r0
__import__)	setup_dirZtemp_dirrrr
setup_contexts






r]cCs"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)rLpatternrrr
_needs_hidingsrbcCs 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)filterrbrrNrQ)rNrrrrZsrZcCs.tjjtjj|}t|y|gt|tjdd<tjjd|t	j
t	jjddt
|tr|n|jtj}t|'td|dd}t||WdQRXWn>tk
r"}z|jr|jdrWYdd}~XnXWdQRXdS)z8Run a distutils setup script, sandboxed in its directoryNrcSs
|jS)N)Zactivate)Zdistrrr<lambda>szrun_setup.<locals>.<lambda>__file__r;__main__)r,r$abspathdirnamer]rTrr insertr__init__Z	callbacksappend
isinstancestrencodegetfilesystemencodingr	dictr
SystemExitargs)Zsetup_scriptrrr\Zdunder_filensvrrrrs
 

c@seZdZdZdZddZddZddZd	d
ZddZ	d
dZ
x9dddgD](Zee
erpe
eee<qpWdddZeredeZedeZxiddddddddddd d!d"d#d$d%d&d'd(gD](Zee
ereeee<qWd)d*Zx6d+d,gD](Zee
erTeeee<qTWd-d.Zx6d/d0gD](Zee
ereeee<qWd1d2Zd3d4Zd5d6Zd7d8ZdS)9rzDWrap 'os' module and 'open()' builtin for virtualizing setup scriptsFcs&fddttD_dS)Ncs5g|]+}|jdrt|r|qS)_)rJhasattr)rKname)rArr
<listcomp>s	z,AbstractSandbox.__init__.<locals>.<listcomp>)dir_os_attrs)rAr)rArrj
szAbstractSandbox.__init__cCs1x*|jD]}tt|t||q
WdS)N)r{setattrr,getattr)rAsourcerwrrr_copyszAbstractSandbox._copycCs8|j|tr|jt_|jt_d|_dS)NT)r_filerfile_openr_active)rArrrrBs

zAbstractSandbox.__enter__cCs2d|_trtt_tt_|jtdS)NF)rrrrrrrrz)rAexc_type	exc_value	tracebackrrrrFs
			zAbstractSandbox.__exit__c	Cs||SWdQRXdS)zRun 'func' under os sandboxingNr)rAfuncrrrrun"szAbstractSandbox.runcs(ttfdd}|S)Ncs=|jr*|j||||\}}||||S)N)r_remap_pair)rAsrcdstrrkw)rworiginalrrwrap*s	!z3AbstractSandbox._mk_dual_path_wrapper.<locals>.wrap)r}rz)rwrr)rwrr_mk_dual_path_wrapper'sz%AbstractSandbox._mk_dual_path_wrapperrenamelinksymlinkNcs.pttfdd}|S)Ncs1|jr!|j|||}|||S)N)r_remap_input)rAr$rrr)rwrrrr8s	z5AbstractSandbox._mk_single_path_wrapper.<locals>.wrap)r}rz)rwrrr)rwrr_mk_single_path_wrapper5sz'AbstractSandbox._mk_single_path_wrapperrrstatlistdirr.chmodchownmkdirremoveunlinkrmdirutimelchownchrootlstatZ	startfilemkfifomknodpathconfaccesscs(ttfdd}|S)NcsM|jr=|j|||}|j|||S|||S)N)rr
_remap_output)rAr$rrr)rwrrrrMs	z4AbstractSandbox._mk_single_with_return.<locals>.wrap)r}rz)rwrr)rwrr_mk_single_with_returnJsz&AbstractSandbox._mk_single_with_returnreadlinktempnamcs(ttfdd}|S)Ncs,||}|jr(|j|S|S)N)rr)rArrrZretval)rwrrrr\s	z'AbstractSandbox._mk_query.<locals>.wrap)r}rz)rwrr)rwrr	_mk_queryYszAbstractSandbox._mk_queryr-tmpnamcCs|S)z=Called to remap or validate any path, whether input or outputr)rAr$rrr_validate_pathhszAbstractSandbox._validate_pathcOs
|j|S)zCalled for path inputs)r)rA	operationr$rrrrrrrlszAbstractSandbox._remap_inputcCs
|j|S)zCalled for path outputs)r)rArr$rrrrpszAbstractSandbox._remap_outputcOs6|j|d||||j|d|||fS)z?Called for path pairs like rename, link, and symlink operationsz-fromz-to)r)rArrrrrrrrrrtszAbstractSandbox._remap_pair)r;r<r=r>rrjrrBrFrrrwrvrzrrrrrrrrrrrrrrrsB

devnullc@seZdZdZejdddddddd	d
ddd
dg
ZdgZeddZ	ddZ
erdddZdddZddZ
ddZddZdd Zd!d"Zd#d$d%Zd&S)'r	z<Restrict operations to a single subdirectory - pseudo-chrootrrrrrrrrrrrrrz.*lib2to3.*\.pickle$cCsctjjtjj||_tjj|jd|_dd|D|_tj	|dS)NcSs.g|]$}tjjtjj|qSr)r,r$normcaserealpath)rKr$rrrrxs	z-DirectorySandbox.__init__.<locals>.<listcomp>)
r,r$rr_sandboxrY_prefix_exceptionsrrj)rAZsandbox
exceptionsrrrrjs
!	
zDirectorySandbox.__init__cOs&ddlm}||||dS)Nr)r
)r5r
)rArrrrr
rrr
_violationszDirectorySandbox._violationrcOsH|dkr5|j|r5|jd||||t||||S)NrrtrrUUr)rrrrr)_okrr)rAr$rrrrrrrrszDirectorySandbox._filecOsH|dkr5|j|r5|jd||||t||||S)Nrrrrrr)rrrrr)rrr)rAr$rrrrrrrrszDirectorySandbox._opencCs|jddS)Nr)r)rArrrrszDirectorySandbox.tmpnamcCss|j}zYd|_tjjtjj|}|j|p`||jkp`|j|jSWd||_XdS)NF)	rr,r$rr	_exemptedrrJr)rAr$Zactiverrrrrs		zDirectorySandbox._okcsTfdd|jD}fdd|jD}tj||}t|S)Nc3s|]}j|VqdS)N)rJ)rK	exception)filepathrrrMsz-DirectorySandbox._exempted.<locals>.<genexpr>c3s!|]}tj|VqdS)N)r^r`)rKra)rrrrMs)r_exception_patterns	itertoolschainany)rArZ
start_matchesZpattern_matchesZ
candidatesr)rrrs

zDirectorySandbox._exemptedcOsE||jkrA|j|rA|j|tjj||||S)zCalled for path inputs)	write_opsrrr,r$r)rArr$rrrrrrrs"zDirectorySandbox._remap_inputcOsC|j|s |j|r9|j|||||||fS)z?Called for path pairs like rename, link, and symlink operations)rr)rArrrrrrrrrrs zDirectorySandbox._remap_pairicOsO|t@r6|j|r6|jd|||||tj|||||S)zCalled for low-level os.open()zos.open)WRITE_FLAGSrrrzr)rArflagsrrrrrrrrszDirectorySandbox.openN)r;r<r=r>rpfromkeysrr_EXCEPTIONSrjrrrrrrrrrrrrrr	s 		
cCs"g|]}tt|dqS)r)r}rz)rKarrrrxs	rxz4O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARYc@s7eZdZdZejdjZddZdS)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\}}}|jjtS)N)rrtmplformatr)rAcmdrrkwargsrrr__str__szSandboxViolation.__str__N)	r;r<r=r>textwrapdedentlstriprrrrrrr
s
)=r,rr)operator	functoolsrr^
contextlibr2rZsetuptools.externrZsetuptools.extern.six.movesrrZpkg_resources.py31compatr'platformrJZ$org.python.modules.posix.PosixModulepythonrNposixZPosixModulerzrwrr	NameErrorrrZdistutils.errorsrr__all__rcontextmanagerr#r%r+r0r4r1r@rSrQrXr]rbrZrrrvrrr	reduceor_splitrr
rrrr<module>s^


	
	wV
Back to Directory File Manager