summaryrefslogtreecommitdiffstats
path: root/Lib/tempfile.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-11-21 15:59:59 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-11-21 15:59:59 (GMT)
commit97701b507bceb466a74d587462cfcbdb79d2fa46 (patch)
tree6e6bc29c3651c6ac9781a8db538125c1da7214a7 /Lib/tempfile.py
parent6ef966e1ad334d78bd555fb720b606bf3b97aef9 (diff)
downloadcpython-97701b507bceb466a74d587462cfcbdb79d2fa46.zip
cpython-97701b507bceb466a74d587462cfcbdb79d2fa46.tar.gz
cpython-97701b507bceb466a74d587462cfcbdb79d2fa46.tar.bz2
_RandomNameSequence(): style guide changes, small speedup, don't
put more in the critical section than absolutely needed, acquire the mutex before the "try".
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r--Lib/tempfile.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 2ad525e..97f1252 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -88,30 +88,30 @@ class _RandomNameSequence:
_RandomNameSequence is an iterator."""
- characters = ( "abcdefghijklmnopqrstuvwxyz"
- + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- + "0123456789-_")
+ characters = ("abcdefghijklmnopqrstuvwxyz" +
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
+ "0123456789-_")
def __init__(self):
self.mutex = _allocate_lock()
self.rng = _Random()
self.normcase = _os.path.normcase
+
def __iter__(self):
return self
def next(self):
m = self.mutex
c = self.characters
- r = self.rng
+ choose = self.rng.choice
+ m.acquire()
try:
- m.acquire()
- letters = ''.join([r.choice(c), r.choice(c), r.choice(c),
- r.choice(c), r.choice(c), r.choice(c)])
+ letters = [choose(c) for dummy in "123456"]
finally:
m.release()
- return self.normcase(letters)
+ return self.normcase(''.join(letters))
def _candidate_tempdir_list():
"""Generate a list of candidate temporary directories which