Commit 97701b50 authored by Tim Peters's avatar Tim Peters

_RandomNameSequence(): style guide changes, small speedup, don't

put more in the critical section than absolutely needed, acquire
the mutex before the "try".
parent 6ef966e1
...@@ -88,30 +88,30 @@ class _RandomNameSequence: ...@@ -88,30 +88,30 @@ class _RandomNameSequence:
_RandomNameSequence is an iterator.""" _RandomNameSequence is an iterator."""
characters = ( "abcdefghijklmnopqrstuvwxyz" characters = ("abcdefghijklmnopqrstuvwxyz" +
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
+ "0123456789-_") "0123456789-_")
def __init__(self): def __init__(self):
self.mutex = _allocate_lock() self.mutex = _allocate_lock()
self.rng = _Random() self.rng = _Random()
self.normcase = _os.path.normcase self.normcase = _os.path.normcase
def __iter__(self): def __iter__(self):
return self return self
def next(self): def next(self):
m = self.mutex m = self.mutex
c = self.characters c = self.characters
r = self.rng choose = self.rng.choice
try:
m.acquire() m.acquire()
letters = ''.join([r.choice(c), r.choice(c), r.choice(c), try:
r.choice(c), r.choice(c), r.choice(c)]) letters = [choose(c) for dummy in "123456"]
finally: finally:
m.release() m.release()
return self.normcase(letters) return self.normcase(''.join(letters))
def _candidate_tempdir_list(): def _candidate_tempdir_list():
"""Generate a list of candidate temporary directories which """Generate a list of candidate temporary directories which
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment