mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-19 08:59:27 +01:00
Made utils.file.mktemp a little more stochastic.
This commit is contained in:
parent
8756b79cc4
commit
6aca01bafb
@ -42,10 +42,14 @@ def mktemp(suffix=''):
|
||||
m = md5.md5(suffix)
|
||||
r.seed(time.time())
|
||||
s = str(r.getstate())
|
||||
for x in xrange(0, random.randrange(400), random.randrange(1, 5)):
|
||||
m.update(str(x))
|
||||
period = random.random()
|
||||
now = start = time.time()
|
||||
while start + period < now:
|
||||
time.sleep() # Induce a context switch, if possible.
|
||||
now = time.time()
|
||||
m.update(str(random.random()))
|
||||
m.update(s)
|
||||
m.update(str(time.time()))
|
||||
m.update(str(now))
|
||||
s = m.hexdigest()
|
||||
return sha.sha(s + str(time.time())).hexdigest() + suffix
|
||||
|
||||
|
@ -458,6 +458,12 @@ class FileTest(SupyTestCase):
|
||||
self.assertEqual(list(utils.file.nonCommentNonEmptyLines(L)),
|
||||
['foo', 'bar', 'biff'])
|
||||
|
||||
def testMktemp(self):
|
||||
# This is mostly to test that it actually halts.
|
||||
self.failUnless(utils.file.mktemp())
|
||||
self.failUnless(utils.file.mktemp())
|
||||
self.failUnless(utils.file.mktemp())
|
||||
|
||||
|
||||
class NetTest(SupyTestCase):
|
||||
def testEmailRe(self):
|
||||
|
Loading…
Reference in New Issue
Block a user