Kaydet (Commit) b6b1ab4f authored tarafından Martin Panter's avatar Martin Panter

Issue #26385: Cleanup NamedTemporaryFile if fdopen() fails, by SilentGhost

üst 97b6e0bd
...@@ -476,7 +476,8 @@ def NamedTemporaryFile(mode='w+b', bufsize=-1, suffix="", ...@@ -476,7 +476,8 @@ def NamedTemporaryFile(mode='w+b', bufsize=-1, suffix="",
try: try:
file = _os.fdopen(fd, mode, bufsize) file = _os.fdopen(fd, mode, bufsize)
return _TemporaryFileWrapper(file, name, delete) return _TemporaryFileWrapper(file, name, delete)
except: except BaseException:
_os.unlink(name)
_os.close(fd) _os.close(fd)
raise raise
......
...@@ -827,6 +827,13 @@ class test_NamedTemporaryFile(TC): ...@@ -827,6 +827,13 @@ class test_NamedTemporaryFile(TC):
os.close = old_close os.close = old_close
os.fdopen = old_fdopen os.fdopen = old_fdopen
def test_bad_mode(self):
dir = tempfile.mkdtemp()
self.addCleanup(support.rmtree, dir)
with self.assertRaises(TypeError):
tempfile.NamedTemporaryFile(mode=(), dir=dir)
self.assertEqual(os.listdir(dir), [])
# How to test the mode and bufsize parameters? # How to test the mode and bufsize parameters?
test_classes.append(test_NamedTemporaryFile) test_classes.append(test_NamedTemporaryFile)
......
...@@ -55,6 +55,9 @@ Core and Builtins ...@@ -55,6 +55,9 @@ Core and Builtins
Library Library
------- -------
- Issue #26385: Remove the file if the internal fdopen() call in
NamedTemporaryFile() fails. Based on patch by Silent Ghost.
- Issue #26309: In the "socketserver" module, shut down the request (closing - Issue #26309: In the "socketserver" module, shut down the request (closing
the connected socket) when verify_request() returns false. Based on patch the connected socket) when verify_request() returns false. Based on patch
by Aviv Palivoda. by Aviv Palivoda.
......
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