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
e36a077d
Commit
e36a077d
authored
Feb 09, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #17169: Restore errno in tempfile exceptions.
parent
99257896
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
5 deletions
+13
-5
Lib/tempfile.py
Lib/tempfile.py
+10
-4
Lib/test/test_tempfile.py
Lib/test/test_tempfile.py
+3
-1
No files found.
Lib/tempfile.py
View file @
e36a077d
...
@@ -31,6 +31,7 @@ import warnings as _warnings
...
@@ -31,6 +31,7 @@ import warnings as _warnings
import
sys
as
_sys
import
sys
as
_sys
import
io
as
_io
import
io
as
_io
import
os
as
_os
import
os
as
_os
import
errno
as
_errno
from
random
import
Random
as
_Random
from
random
import
Random
as
_Random
try
:
try
:
...
@@ -181,7 +182,9 @@ def _get_default_tempdir():
...
@@ -181,7 +182,9 @@ def _get_default_tempdir():
pass
pass
except
OSError
:
except
OSError
:
break
# no point trying more names in this directory
break
# no point trying more names in this directory
raise
FileNotFoundError
(
"No usable temporary directory found in %s"
%
dirlist
)
raise
FileNotFoundError
(
_errno
.
ENOENT
,
"No usable temporary directory found in %s"
%
dirlist
)
_name_sequence
=
None
_name_sequence
=
None
...
@@ -214,7 +217,8 @@ def _mkstemp_inner(dir, pre, suf, flags):
...
@@ -214,7 +217,8 @@ def _mkstemp_inner(dir, pre, suf, flags):
except
FileExistsError
:
except
FileExistsError
:
continue
# try again
continue
# try again
raise
FileExistsError
(
"No usable temporary file name found"
)
raise
FileExistsError
(
_errno
.
EEXIST
,
"No usable temporary file name found"
)
# User visible interfaces.
# User visible interfaces.
...
@@ -301,7 +305,8 @@ def mkdtemp(suffix="", prefix=template, dir=None):
...
@@ -301,7 +305,8 @@ def mkdtemp(suffix="", prefix=template, dir=None):
except
FileExistsError
:
except
FileExistsError
:
continue
# try again
continue
# try again
raise
FileExistsError
(
"No usable temporary directory name found"
)
raise
FileExistsError
(
_errno
.
EEXIST
,
"No usable temporary directory name found"
)
def
mktemp
(
suffix
=
""
,
prefix
=
template
,
dir
=
None
):
def
mktemp
(
suffix
=
""
,
prefix
=
template
,
dir
=
None
):
"""User-callable function to return a unique temporary file name. The
"""User-callable function to return a unique temporary file name. The
...
@@ -330,7 +335,8 @@ def mktemp(suffix="", prefix=template, dir=None):
...
@@ -330,7 +335,8 @@ def mktemp(suffix="", prefix=template, dir=None):
if
not
_exists
(
file
):
if
not
_exists
(
file
):
return
file
return
file
raise
FileExistsError
(
"No usable temporary filename found"
)
raise
FileExistsError
(
_errno
.
EEXIST
,
"No usable temporary filename found"
)
class
_TemporaryFileWrapper
:
class
_TemporaryFileWrapper
:
...
...
Lib/test/test_tempfile.py
View file @
e36a077d
# tempfile.py unit tests.
# tempfile.py unit tests.
import
tempfile
import
tempfile
import
errno
import
os
import
os
import
signal
import
signal
import
sys
import
sys
...
@@ -963,8 +964,9 @@ class TestTemporaryDirectory(BaseTestCase):
...
@@ -963,8 +964,9 @@ class TestTemporaryDirectory(BaseTestCase):
# (noted as part of Issue #10188)
# (noted as part of Issue #10188)
with
tempfile
.
TemporaryDirectory
()
as
nonexistent
:
with
tempfile
.
TemporaryDirectory
()
as
nonexistent
:
pass
pass
with
self
.
assertRaises
(
os
.
error
)
:
with
self
.
assertRaises
(
FileNotFoundError
)
as
cm
:
tempfile
.
TemporaryDirectory
(
dir
=
nonexistent
)
tempfile
.
TemporaryDirectory
(
dir
=
nonexistent
)
self
.
assertEqual
(
cm
.
exception
.
errno
,
errno
.
ENOENT
)
def
test_explicit_cleanup
(
self
):
def
test_explicit_cleanup
(
self
):
# A TemporaryDirectory is deleted when cleaned up
# A TemporaryDirectory is deleted when cleaned up
...
...
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