diff options
Diffstat (limited to 'setuptools/sandbox.py')
-rwxr-xr-x | setuptools/sandbox.py | 45 |
1 files changed, 11 insertions, 34 deletions
diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index 29fc07b8..6dd1ca07 100755 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -1,4 +1,11 @@ -import os, sys, tempfile, operator, pkg_resources +import os +import sys +import tempfile +import operator +import functools + +import pkg_resources + if os.name == "java": import org.python.modules.posix.PosixModule as _os else: @@ -11,40 +18,12 @@ _open = open from distutils.errors import DistutilsError from pkg_resources import working_set -from setuptools.compat import builtins, execfile, reduce +from setuptools.compat import builtins, execfile __all__ = [ "AbstractSandbox", "DirectorySandbox", "SandboxViolation", "run_setup", ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - def run_setup(setup_script, args): """Run a distutils setup script, sandboxed in its directory""" old_dir = os.getcwd() @@ -93,7 +72,6 @@ def run_setup(setup_script, args): tempfile.tempdir = save_tmp - class AbstractSandbox: """Wrap 'os' module and 'open()' builtin for virtualizing setup scripts""" @@ -136,7 +114,6 @@ class AbstractSandbox: for name in ["rename", "link", "symlink"]: if hasattr(_os,name): locals()[name] = _mk_dual_path_wrapper(name) - def _mk_single_path_wrapper(name, original=None): original = original or getattr(_os,name) def wrap(self,path,*args,**kw): @@ -249,7 +226,7 @@ class DirectorySandbox(AbstractSandbox): self._active = False realpath = os.path.normcase(os.path.realpath(path)) if (self._exempted(realpath) or realpath == self._sandbox - or realpath.startswith(self._prefix)): + or realpath.startswith(self._prefix)): return True finally: self._active = active @@ -276,7 +253,7 @@ class DirectorySandbox(AbstractSandbox): self._violation("os.open", file, flags, mode, *args, **kw) return _os.open(file,flags,mode, *args, **kw) -WRITE_FLAGS = reduce( +WRITE_FLAGS = functools.reduce( operator.or_, [getattr(_os, a, 0) for a in "O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARY".split()] ) |