Update of /cvsroot/webware/Webware/MiscUtils
In directory usw-pr-cvs1:/tmp/cvs-serv21174
Modified Files:
Funcs.py
Log Message:
added uniqueId() compliments of Ken Lalonde
Index: Funcs.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiscUtils/Funcs.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Funcs.py 2001/03/23 13:50:17 1.8
--- Funcs.py 2001/11/12 12:18:18 1.9
***************
*** 5,9 ****
'''
! import os, string, time
--- 5,9 ----
'''
! import md5, os, random, string, time
***************
*** 91,94 ****
--- 91,106 ----
dashed = '%4i-%02i-%02i-%02i-%02i-%02i' % tuple
return locals()
+
+
+ def uniqueId(forObject=None):
+ '''
+ Generates an opaque, identifier string that is practically guaranteed to be unique.
+ If an object is passed, then its id() is incorporated into the generation.
+ Relies on md5 and returns a 32 character long string.
+ '''
+ r = [time.time(), random.random(), os.times()]
+ if forObject is not None:
+ r.append(id(forObject))
+ return md5.new(str(r)).hexdigest()
|