# HG changeset patch # User Sylvain Thénault # Date 1268387490 -3600 # Node ID fa6671e836391d13b058da81a78edf9c06b48b5f # Parent 56c16efedc51c9e0a467d04aa31a87760736f007 [utils] make_uid imrovment: using .hex already remove '-', make key argument optional, document it diff -r 56c16efedc51 -r fa6671e83639 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):