Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7869a227
Commit
7869a227
authored
Feb 28, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26385: Cleanup NamedTemporaryFile if open() fails, by SilentGhost
parent
96421d6f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
2 deletions
+14
-2
Lib/tempfile.py
Lib/tempfile.py
+2
-1
Lib/test/test_tempfile.py
Lib/test/test_tempfile.py
+9
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/tempfile.py
View file @
7869a227
...
...
@@ -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
...
...
Lib/test/test_tempfile.py
View file @
7869a227
...
...
@@ -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()."""
...
...
Misc/NEWS
View file @
7869a227
...
...
@@ -84,6 +84,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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment