Commit 96c97c7b authored by Martin v. Löwis's avatar Martin v. Löwis

Conditionalize _file processing.

--HG--
branch : distribute
extra : rebase_source : fd07ce0e0541a269a88596e985884f688c86185e
parent 6f3378c0
import os, sys, __builtin__, tempfile, operator import os, sys, __builtin__, tempfile, operator
_os = sys.modules[os.name] _os = sys.modules[os.name]
_file = file try:
_file = file
except NameError:
_file = None
_open = open _open = open
from distutils.errors import DistutilsError from distutils.errors import DistutilsError
__all__ = [ __all__ = [
...@@ -60,12 +63,14 @@ class AbstractSandbox: ...@@ -60,12 +63,14 @@ class AbstractSandbox:
"""Run 'func' under os sandboxing""" """Run 'func' under os sandboxing"""
try: try:
self._copy(self) self._copy(self)
if _file:
__builtin__.file = self._file __builtin__.file = self._file
__builtin__.open = self._open __builtin__.open = self._open
self._active = True self._active = True
return func() return func()
finally: finally:
self._active = False self._active = False
if _file:
__builtin__.file = _file __builtin__.file = _file
__builtin__.open = _open __builtin__.open = _open
self._copy(_os) self._copy(_os)
...@@ -92,6 +97,7 @@ class AbstractSandbox: ...@@ -92,6 +97,7 @@ class AbstractSandbox:
return original(path,*args,**kw) return original(path,*args,**kw)
return wrap return wrap
if _file:
_file = _mk_single_path_wrapper('file', _file) _file = _mk_single_path_wrapper('file', _file)
_open = _mk_single_path_wrapper('open', _open) _open = _mk_single_path_wrapper('open', _open)
for name in [ for name in [
......
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