utils.py
branch3.5
changeset 3316 c4c07aab1c39
parent 3231 3ee43e2f8560
parent 3155 14e30e2520d7
child 3364 039d1694f36d
--- a/utils.py	Fri Sep 18 11:06:42 2009 +0200
+++ b/utils.py	Fri Sep 18 12:20:39 2009 +0200
@@ -10,13 +10,14 @@
 from logilab.mtconverter import xml_escape
 
 import locale
+import sys
+import decimal
+import datetime as pydatetime
 from md5 import md5
-import datetime as pydatetime
 from datetime import datetime, timedelta, date
 from time import time, mktime
 from random import randint, seed
 from calendar import monthrange
-import decimal
 
 import simplejson
 
@@ -107,11 +108,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 str(key) + str(uuid4())
 
 def dump_class(cls, clsname):
     """create copy of a class by creating an empty class inheriting