summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-09 20:25:49 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-09 20:25:49 (GMT)
commit7451a72e2ba8939215324387e36285725632e637 (patch)
treef73f91484cb022179212c1af2a5e6752fdd70bd9
parentf4b54adc706c6b0eb5d0d4bda5cdcf43ef28171b (diff)
downloadcpython-7451a72e2ba8939215324387e36285725632e637.zip
cpython-7451a72e2ba8939215324387e36285725632e637.tar.gz
cpython-7451a72e2ba8939215324387e36285725632e637.tar.bz2
Issue #17169: Restore errno in tempfile exceptions.
-rw-r--r--Lib/tempfile.py14
-rw-r--r--Lib/test/test_tempfile.py4
2 files changed, 13 insertions, 5 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 61b0df1..0cc5c04 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -31,6 +31,7 @@ import warnings as _warnings
import sys as _sys
import io as _io
import os as _os
+import errno as _errno
from random import Random as _Random
try:
@@ -181,7 +182,9 @@ def _get_default_tempdir():
pass
except OSError:
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
@@ -214,7 +217,8 @@ def _mkstemp_inner(dir, pre, suf, flags):
except FileExistsError:
continue # try again
- raise FileExistsError("No usable temporary file name found")
+ raise FileExistsError(_errno.EEXIST,
+ "No usable temporary file name found")
# User visible interfaces.
@@ -301,7 +305,8 @@ def mkdtemp(suffix="", prefix=template, dir=None):
except FileExistsError:
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):
"""User-callable function to return a unique temporary file name. The
@@ -330,7 +335,8 @@ def mktemp(suffix="", prefix=template, dir=None):
if not _exists(file):
return file
- raise FileExistsError("No usable temporary filename found")
+ raise FileExistsError(_errno.EEXIST,
+ "No usable temporary filename found")
class _TemporaryFileWrapper:
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 40e5e6f..7f4d5b9 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -1,5 +1,6 @@
# tempfile.py unit tests.
import tempfile
+import errno
import os
import signal
import sys
@@ -963,8 +964,9 @@ class TestTemporaryDirectory(BaseTestCase):
# (noted as part of Issue #10188)
with tempfile.TemporaryDirectory() as nonexistent:
pass
- with self.assertRaises(os.error):
+ with self.assertRaises(FileNotFoundError) as cm:
tempfile.TemporaryDirectory(dir=nonexistent)
+ self.assertEqual(cm.exception.errno, errno.ENOENT)
def test_explicit_cleanup(self):
# A TemporaryDirectory is deleted when cleaned up