diff options
Diffstat (limited to 'setuptools')
| -rwxr-xr-x | setuptools/sandbox.py | 8 | ||||
| -rw-r--r-- | setuptools/tests/test_sandbox.py | 28 |
2 files changed, 34 insertions, 2 deletions
diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index 7b487833..502598ca 100755 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -152,6 +152,8 @@ class AbstractSandbox: ) +_EXCEPTIONS = [os.devnull,] + class DirectorySandbox(AbstractSandbox): """Restrict operations to a single subdirectory - pseudo-chroot""" @@ -160,9 +162,10 @@ class DirectorySandbox(AbstractSandbox): "utime", "lchown", "chroot", "mkfifo", "mknod", "tempnam", ]) - def __init__(self,sandbox): + 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 AbstractSandbox.__init__(self) def _violation(self, operation, *args, **kw): @@ -187,7 +190,8 @@ class DirectorySandbox(AbstractSandbox): try: self._active = False realpath = os.path.normcase(os.path.realpath(path)) - if realpath==self._sandbox or realpath.startswith(self._prefix): + if (realpath in self._exceptions or realpath == self._sandbox + or realpath.startswith(self._prefix)): return True finally: self._active = active diff --git a/setuptools/tests/test_sandbox.py b/setuptools/tests/test_sandbox.py new file mode 100644 index 00000000..1b0dc4ea --- /dev/null +++ b/setuptools/tests/test_sandbox.py @@ -0,0 +1,28 @@ +"""develop tests +""" +import sys +import os +import shutil +import unittest +import tempfile + +from setuptools.sandbox import DirectorySandbox + +class TestSandbox(unittest.TestCase): + + def setUp(self): + self.dir = tempfile.mkdtemp() + + def tearDown(self): + shutil.rmtree(self.dir) + + def test_devnull(self): + sandbox = DirectorySandbox(self.dir) + + def _write(): + f = open(os.devnull, 'w') + f.write('xxx') + f.close() + + sandbox.run(_write) + |
