aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/sandbox.py
diff options
context:
space:
mode:
authorRonny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>2010-03-16 20:02:39 +0100
committerRonny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>2010-03-16 20:02:39 +0100
commit69da648099044a98f094b746c4d0295baf843ea2 (patch)
tree2ec89c3ef7aea39affe42c0737057b6d49fef4e8 /setuptools/sandbox.py
parent0b3d2302b8b209c7bed8bdad6e1a6cff34889779 (diff)
parentff3ee4aa6c6800d813162c09a58c6265c4675701 (diff)
downloadexternal_python_setuptools-69da648099044a98f094b746c4d0295baf843ea2.tar.gz
external_python_setuptools-69da648099044a98f094b746c4d0295baf843ea2.tar.bz2
external_python_setuptools-69da648099044a98f094b746c4d0295baf843ea2.zip
merge with upstream
--HG-- branch : distribute extra : rebase_source : 2ad13527b742644596b32fcd8feac7276b4a477e
Diffstat (limited to 'setuptools/sandbox.py')
-rwxr-xr-xsetuptools/sandbox.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py
index 502598ca..630d5792 100755
--- a/setuptools/sandbox.py
+++ b/setuptools/sandbox.py
@@ -154,6 +154,12 @@ class AbstractSandbox:
_EXCEPTIONS = [os.devnull,]
+try:
+ gen_py = os.path.dirname(__import__('win32com.gen_py', fromlist=['__name__']).__file__)
+ _EXCEPTIONS.append(gen_py)
+except ImportError:
+ pass
+
class DirectorySandbox(AbstractSandbox):
"""Restrict operations to a single subdirectory - pseudo-chroot"""
@@ -165,7 +171,7 @@ class DirectorySandbox(AbstractSandbox):
def __init__(self, sandbox, exceptions=_EXCEPTIONS):
self._sandbox = os.path.normcase(os.path.realpath(sandbox))
self._prefix = os.path.join(self._sandbox,'')
- self._exceptions = exceptions
+ self._exceptions = [os.path.normcase(os.path.realpath(path)) for path in exceptions]
AbstractSandbox.__init__(self)
def _violation(self, operation, *args, **kw):
@@ -190,12 +196,16 @@ class DirectorySandbox(AbstractSandbox):
try:
self._active = False
realpath = os.path.normcase(os.path.realpath(path))
- if (realpath in self._exceptions or realpath == self._sandbox
+ if (self._exempted(realpath) or realpath == self._sandbox
or realpath.startswith(self._prefix)):
return True
finally:
self._active = active
+ def _exempted(self, filepath):
+ exception_matches = map(filepath.startswith, self._exceptions)
+ return any(exception_matches)
+
def _remap_input(self,operation,path,*args,**kw):
"""Called for path inputs"""
if operation in self.write_ops and not self._ok(path):