mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-14 06:02:36 +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)
|
m = md5.md5(suffix)
|
||||||
r.seed(time.time())
|
r.seed(time.time())
|
||||||
s = str(r.getstate())
|
s = str(r.getstate())
|
||||||
for x in xrange(0, random.randrange(400), random.randrange(1, 5)):
|
period = random.random()
|
||||||
m.update(str(x))
|
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(s)
|
||||||
m.update(str(time.time()))
|
m.update(str(now))
|
||||||
s = m.hexdigest()
|
s = m.hexdigest()
|
||||||
return sha.sha(s + str(time.time())).hexdigest() + suffix
|
return sha.sha(s + str(time.time())).hexdigest() + suffix
|
||||||
|
|
||||||
|
@ -458,6 +458,12 @@ class FileTest(SupyTestCase):
|
|||||||
self.assertEqual(list(utils.file.nonCommentNonEmptyLines(L)),
|
self.assertEqual(list(utils.file.nonCommentNonEmptyLines(L)),
|
||||||
['foo', 'bar', 'biff'])
|
['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):
|
class NetTest(SupyTestCase):
|
||||||
def testEmailRe(self):
|
def testEmailRe(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user