[Python-checkins] cpython (merge 3.3 -> default): Issue #17169: Restore errno in tempfile exceptions.
serhiy.storchaka
python-checkins at python.org
Sat Feb 9 21:28:21 CET 2013
http://hg.python.org/cpython/rev/fd3e3059381a
changeset: 82105:fd3e3059381a
parent: 82102:c4512797b879
parent: 82104:11eaa61124c2
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sat Feb 09 22:27:23 2013 +0200
summary:
Issue #17169: Restore errno in tempfile exceptions.
files:
Lib/tempfile.py | 14 ++++++++++----
Lib/test/test_tempfile.py | 4 +++-
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -31,6 +31,7 @@
import sys as _sys
import io as _io
import os as _os
+import errno as _errno
from random import Random as _Random
try:
@@ -183,7 +184,9 @@
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
@@ -216,7 +219,8 @@
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.
@@ -303,7 +307,8 @@
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
@@ -332,7 +337,8 @@
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
--- 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 @@
# (noted as part of Issue #10188)
with tempfile.TemporaryDirectory() as nonexistent:
pass
- with self.assertRaises(OSError):
+ 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
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list