[utils] make_uid imrovment: using .hex already remove '-', make key argument optional, document it
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 12 Mar 2010 10:51:30 +0100
changeset 4880 fa6671e83639
parent 4879 56c16efedc51
child 4881 39fc30001a20
[utils] make_uid imrovment: using .hex already remove '-', make key argument optional, document it
utils.py
--- a/utils.py	Fri Mar 12 10:50:37 2010 +0100
+++ b/utils.py	Fri Mar 12 10:51:30 2010 +0100
@@ -22,10 +22,18 @@
 # initialize random seed from current time
 random.seed()
 
-def make_uid(key):
-    # remove dash, generated uid are used as identifier sometimes (sql table
-    # names at least)
-    return str(key) + str(uuid4()).replace('-', '')
+def make_uid(key=None):
+    """Return a unique identifier string.
+
+    if specified, `key` is used to prefix the generated uid so it can be used
+    for instance as a DOM id or as sql table names.
+
+    See uuid.uuid4 documentation for the shape of the generated identifier, but
+    this is basicallly a 32 bits hexadecimal string.
+    """
+    if key is None:
+        return uuid4().hex
+    return str(key) + uuid4().hex
 
 
 def dump_class(cls, clsname):