summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-02-29 11:25:09 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-02-29 11:25:09 (GMT)
commit93088d1b031a6a00474c13c44d130b7c078de35d (patch)
tree39a4cb8647f87328dcbca65ef16b1c13e947c933
parentd047c2f8b2a4c25bd04f2536e9af24a9cc01ab77 (diff)
parent7869a227795da08841f8139b69b7d4521b12e184 (diff)
downloadcpython-93088d1b031a6a00474c13c44d130b7c078de35d.zip
cpython-93088d1b031a6a00474c13c44d130b7c078de35d.tar.gz
cpython-93088d1b031a6a00474c13c44d130b7c078de35d.tar.bz2
Issue #26385: Merge NamedTemporaryFile fix from 3.5
-rw-r--r--Lib/tempfile.py3
-rw-r--r--Lib/test/test_tempfile.py10
-rw-r--r--Misc/NEWS3
3 files changed, 14 insertions, 2 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index c39820e..ad687b9 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -552,7 +552,8 @@ def NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None,
newline=newline, encoding=encoding)
return _TemporaryFileWrapper(file, name, delete)
- except Exception:
+ except BaseException:
+ _os.unlink(name)
_os.close(fd)
raise
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 4a077cc..51df1ec 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -948,8 +948,16 @@ class TestNamedTemporaryFile(BaseTestCase):
self.assertRaises(ValueError, tempfile.NamedTemporaryFile)
self.assertEqual(len(closed), 1)
- # How to test the mode and bufsize parameters?
+ def test_bad_mode(self):
+ dir = tempfile.mkdtemp()
+ self.addCleanup(support.rmtree, dir)
+ with self.assertRaises(ValueError):
+ tempfile.NamedTemporaryFile(mode='wr', dir=dir)
+ with self.assertRaises(TypeError):
+ tempfile.NamedTemporaryFile(mode=2, dir=dir)
+ self.assertEqual(os.listdir(dir), [])
+ # How to test the mode and bufsize parameters?
class TestSpooledTemporaryFile(BaseTestCase):
"""Test SpooledTemporaryFile()."""
diff --git a/Misc/NEWS b/Misc/NEWS
index 64af219..315167e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -194,6 +194,9 @@ Core and Builtins
Library
-------
+- Issue #26385: Remove the file if the internal open() call in
+ NamedTemporaryFile() fails. Patch by Silent Ghost.
+
- Issue #26402: Fix XML-RPC client to retry when the server shuts down a
persistent connection. This was a regression related to the new
http.client.RemoteDisconnected exception in 3.5.0a4.