Anonymous avatar Anonymous committed 48274ba

Allowing 'os.devnull' in Sandbox, fixes #101

Comments (0)

Files changed (3)

   "setup.cfg" if any exists in the working directory. It will use it
   only if triggered by ``install_requires`` from a call
   (install, develop, etc).
+* Issue 101: Allowing ``os.devnull`` in Sandbox


+_EXCEPTIONS = [os.devnull,]
 class DirectorySandbox(AbstractSandbox):
     """Restrict operations to a single subdirectory - pseudo-chroot"""
         "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
     def _violation(self, operation, *args, **kw):
             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
             self._active = active


+"""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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.