[Python-checkins] cpython: Close #12015: The tempfile module now uses a suffix of 8 random characters
victor.stinner
python-checkins at python.org
Wed Aug 14 01:28:41 CEST 2013
http://hg.python.org/cpython/rev/de5077aca668
changeset: 85160:de5077aca668
user: Victor Stinner <victor.stinner at gmail.com>
date: Wed Aug 14 01:28:28 2013 +0200
summary:
Close #12015: The tempfile module now uses a suffix of 8 random characters
instead of 6, to reduce the risk of filename collision. The entropy was reduced
when uppercase letters were removed from the charset used to generate random
characters.
files:
Lib/tempfile.py | 2 +-
Lib/test/test_tempfile.py | 4 ++--
Misc/NEWS | 5 +++++
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -125,7 +125,7 @@
def __next__(self):
c = self.characters
choose = self.rng.choice
- letters = [choose(c) for dummy in "123456"]
+ letters = [choose(c) for dummy in range(8)]
return ''.join(letters)
def _candidate_tempdir_list():
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
@@ -35,7 +35,7 @@
# Common functionality.
class BaseTestCase(unittest.TestCase):
- str_check = re.compile(r"[a-zA-Z0-9_-]{6}$")
+ str_check = re.compile(r"^[a-z0-9_-]{8}$")
def setUp(self):
self._warnings_manager = support.check_warnings()
@@ -62,7 +62,7 @@
nbase = nbase[len(pre):len(nbase)-len(suf)]
self.assertTrue(self.str_check.match(nbase),
- "random string '%s' does not match /^[a-zA-Z0-9_-]{6}$/"
+ "random string '%s' does not match ^[a-z0-9_-]{8}$"
% nbase)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -28,6 +28,11 @@
Library
-------
+- Issue #12015: The tempfile module now uses a suffix of 8 random characters
+ instead of 6, to reduce the risk of filename collision. The entropy was
+ reduced when uppercase letters were removed from the charset used to generate
+ random characters.
+
- Issue #18585: Add :func:`textwrap.shorten` to collapse and truncate a
piece of text to a given length.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list