aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarek <none@none>2009-12-04 11:20:36 +0100
committertarek <none@none>2009-12-04 11:20:36 +0100
commitf7279ede282b895e789b05ababb65ba4f6436160 (patch)
tree0714be9fb1fb446659d29843e2a5ccebfc9888b7
parentca0105cf105e6d8a6c3e552c82650de93dbe13b1 (diff)
downloadexternal_python_setuptools-f7279ede282b895e789b05ababb65ba4f6436160.tar.gz
external_python_setuptools-f7279ede282b895e789b05ababb65ba4f6436160.tar.bz2
external_python_setuptools-f7279ede282b895e789b05ababb65ba4f6436160.zip
Allowing 'os.devnull' in Sandbox, fixes #101
--HG-- branch : distribute extra : rebase_source : d6f63794621874eb637139f353314256e02e02df
-rw-r--r--CHANGES.txt1
-rwxr-xr-xsetuptools/sandbox.py8
-rw-r--r--setuptools/tests/test_sandbox.py28
3 files changed, 35 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 608a278e..422685a9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -19,6 +19,7 @@ CHANGES
"setup.cfg" if any exists in the working directory. It will use it
only if triggered by ``install_requires`` from a setup.py call
(install, develop, etc).
+* Issue 101: Allowing ``os.devnull`` in Sandbox
-----
0.6.8
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)
+