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
ff7fef96
Commit
ff7fef96
authored
Feb 13, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #16800: tempfile.gettempdir() no longer left temporary files when
the disk is full. Original patch by Amir Szekely.
parents
b52d432a
f6b361ec
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
6 deletions
+51
-6
Lib/tempfile.py
Lib/tempfile.py
+8
-5
Lib/test/test_tempfile.py
Lib/test/test_tempfile.py
+39
-1
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/tempfile.py
View file @
ff7fef96
...
...
@@ -172,11 +172,14 @@ def _get_default_tempdir():
filename
=
_os
.
path
.
join
(
dir
,
name
)
try
:
fd
=
_os
.
open
(
filename
,
_bin_openflags
,
0o600
)
fp
=
_io
.
open
(
fd
,
'wb'
)
try
:
try
:
fp
=
_io
.
open
(
fd
,
'wb'
,
buffering
=
0
,
closefd
=
False
)
fp
.
write
(
b'blat'
)
fp
.
close
()
finally
:
_os
.
close
(
fd
)
finally
:
_os
.
unlink
(
filename
)
del
fp
,
fd
return
dir
except
FileExistsError
:
pass
...
...
Lib/test/test_tempfile.py
View file @
ff7fef96
# tempfile.py unit tests.
import
tempfile
import
errno
import
io
import
os
import
signal
import
sys
...
...
@@ -198,7 +199,44 @@ class TestCandidateTempdirList(BaseTestCase):
# paths in this list.
# We test _get_default_tempdir by testing gettempdir.
# We test _get_default_tempdir some more by testing gettempdir.
class
TestGetDefaultTempdir
(
BaseTestCase
):
"""Test _get_default_tempdir()."""
def
test_no_files_left_behind
(
self
):
# use a private empty directory
with
tempfile
.
TemporaryDirectory
()
as
our_temp_directory
:
# force _get_default_tempdir() to consider our empty directory
def
our_candidate_list
():
return
[
our_temp_directory
]
with
support
.
swap_attr
(
tempfile
,
"_candidate_tempdir_list"
,
our_candidate_list
):
# verify our directory is empty after _get_default_tempdir()
tempfile
.
_get_default_tempdir
()
self
.
assertEqual
(
os
.
listdir
(
our_temp_directory
),
[])
def
raise_OSError
(
*
args
,
**
kwargs
):
raise
OSError
()
with
support
.
swap_attr
(
io
,
"open"
,
raise_OSError
):
# test again with failing io.open()
with
self
.
assertRaises
(
FileNotFoundError
):
tempfile
.
_get_default_tempdir
()
self
.
assertEqual
(
os
.
listdir
(
our_temp_directory
),
[])
open
=
io
.
open
def
bad_writer
(
*
args
,
**
kwargs
):
fp
=
open
(
*
args
,
**
kwargs
)
fp
.
write
=
raise_OSError
return
fp
with
support
.
swap_attr
(
io
,
"open"
,
bad_writer
):
# test again with failing write()
with
self
.
assertRaises
(
FileNotFoundError
):
tempfile
.
_get_default_tempdir
()
self
.
assertEqual
(
os
.
listdir
(
our_temp_directory
),
[])
class
TestGetCandidateNames
(
BaseTestCase
):
...
...
Misc/ACKS
View file @
ff7fef96
...
...
@@ -1163,6 +1163,7 @@ Andrew Svetlov
Paul Swartz
Thenault Sylvain
Péter Szabó
Amir Szekely
Arfrever Frehtes Taifersar Arahesis
Neil Tallim
Geoff Talvola
...
...
Misc/NEWS
View file @
ff7fef96
...
...
@@ -175,6 +175,9 @@ Core and Builtins
Library
-------
- Issue #16800: tempfile.gettempdir() no longer left temporary files when
the disk is full. Original patch by Amir Szekely.
- Issue #16564: Fixed regression relative to Python2 in the operation of
email.encoders.encode_7or8bit when used with binary data.
...
...
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