# HG changeset patch # User Aurelien Campeas # Date 1252511190 -7200 # Node ID cfc4344023f2e79b94136b5a913dd920b79aea49 # Parent 9b28545de60d1ccd8d0ac319477dc429bdd92bf9 have a better make_uid function, esp. useful for win32 as collisions are frequents with the old one diff -r 9b28545de60d -r cfc4344023f2 test/unittest_utils.py --- a/test/unittest_utils.py Wed Sep 09 17:45:34 2009 +0200 +++ b/test/unittest_utils.py Wed Sep 09 17:46:30 2009 +0200 @@ -17,12 +17,12 @@ self.assertNotEquals(make_uid('xyz'), make_uid('xyz')) def test_2(self): - d = {} + d = set() while len(d)<10000: uid = make_uid('xyz') - if d.has_key(uid): + if uid in d: self.fail(len(d)) - d[uid] = 1 + d.add(uid) class UStringIOTC(TestCase): diff -r 9b28545de60d -r cfc4344023f2 utils.py --- a/utils.py Wed Sep 09 17:45:34 2009 +0200 +++ b/utils.py Wed Sep 09 17:46:30 2009 +0200 @@ -11,6 +11,7 @@ import locale from md5 import md5 +import sys from datetime import datetime, timedelta, date from time import time, mktime from random import randint, seed @@ -103,11 +104,17 @@ encoding = locale.getpreferredencoding(do_setlocale=False) or 'UTF-8' return unicode(date.strftime(str(fmt)), encoding) -def make_uid(key): - """forge a unique identifier""" - msg = str(key) + "%.10f" % time() + str(randint(0, 1000000)) - return md5(msg).hexdigest() +if sys.version_info[:2] < (2, 5): + def make_uid(key): + """forge a unique identifier + not that unique on win32""" + msg = str(key) + "%.10f" % time() + str(randint(0, 1000000)) + return md5(msg).hexdigest() +else: + from uuid import uuid4 + def make_uid(key): + return key + str(uuid4()) def dump_class(cls, clsname): """create copy of a class by creating an empty class inheriting