Commit f7279ede authored by tarek's avatar tarek

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

--HG--
branch : distribute
extra : rebase_source : d6f63794621874eb637139f353314256e02e02df
parent ca0105cf
......@@ -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
......
......@@ -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
......
"""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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment