Skip to content

Commit

Permalink
Remove sandbox Python 2 builtins.file support (#4554)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Aug 12, 2024
1 parent 153c0fe commit 7aa30d0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
1 change: 1 addition & 0 deletions newsfragments/4554.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed ``setputools.sandbox``'s Python 2 ``builtins.file`` support -- by :user:`Avasam`
17 changes: 0 additions & 17 deletions setuptools/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
import org.python.modules.posix.PosixModule as _os
else:
_os = sys.modules[os.name]
try:
_file = file # type: ignore[name-defined] # Check for global variable
except NameError:
_file = None
_open = open


Expand Down Expand Up @@ -285,15 +281,11 @@ def _copy(self, source):

def __enter__(self):
self._copy(self)
if _file:
builtins.file = self._file
builtins.open = self._open
self._active = True

def __exit__(self, exc_type, exc_value, traceback):
self._active = False
if _file:
builtins.file = _file
builtins.open = _open
self._copy(_os)

Expand Down Expand Up @@ -326,8 +318,6 @@ def wrap(self, path, *args, **kw):

return wrap

if _file:
_file = _mk_single_path_wrapper('file', _file)
_open = _mk_single_path_wrapper('open', _open)
for __name in [
"stat",
Expand Down Expand Up @@ -444,13 +434,6 @@ def _violation(self, operation, *args, **kw):

raise SandboxViolation(operation, args, kw)

if _file:

def _file(self, path, mode='r', *args, **kw):
if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
self._violation("file", path, mode, *args, **kw)
return _file(path, mode, *args, **kw)

def _open(self, path, mode='r', *args, **kw):
if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
self._violation("open", path, mode, *args, **kw)
Expand Down

0 comments on commit 7aa30d0

Please sign in to comment.