[Python-checkins] cpython (3.4): Issue #20876: correctly close temporary file in
antoine.pitrou
python-checkins at python.org
Sun Mar 8 00:18:35 CET 2015
https://hg.python.org/cpython/rev/40e8a8e83ed0
changeset: 94895:40e8a8e83ed0
branch: 3.4
parent: 94891:5903ab233a1d
user: Antoine Pitrou <solipsis at pitrou.net>
date: Sun Mar 08 00:15:05 2015 +0100
summary:
Issue #20876: correctly close temporary file in test.support.fs_is_case_insensitive()
files:
Lib/test/support/__init__.py | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2133,16 +2133,15 @@
def fs_is_case_insensitive(directory):
"""Detects if the file system for the specified directory is case-insensitive."""
- base_fp, base_path = tempfile.mkstemp(dir=directory)
- case_path = base_path.upper()
- if case_path == base_path:
- case_path = base_path.lower()
- try:
- return os.path.samefile(base_path, case_path)
- except FileNotFoundError:
- return False
- finally:
- os.unlink(base_path)
+ with tempfile.NamedTemporaryFile(dir=directory) as base:
+ base_path = base.name
+ case_path = base_path.upper()
+ if case_path == base_path:
+ case_path = base_path.lower()
+ try:
+ return os.path.samefile(base_path, case_path)
+ except FileNotFoundError:
+ return False
class SuppressCrashReport:
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list