[Zope-dev] Globally unique id's in Zope in a new way

Jason Spisak 444@hiretechs.com
Wed, 08 Mar 2000 19:49:47 -0500


Zopsters,

I use the Catalog for quite a bit of jumping around the ZODB, and have a
30,000 plus objects in a system.  I like the idea of not having to worry
about id's conflicting with other numbers that might appear (invoice
numbers, employee numbers, etc...) so I don't like to use a counter for
ids.  The ZopeTime() to int to string conversion works unless you are
programatically creating multiple items in the same folder, and have a
descent processor.  I have derived the following bad hack from the code
used to generate ZClass ids.  Does anyone know off hand how many
different combinations this offers?  Is it considered unique? It returns
a url valid string with no special signs.


import md5, base64, time, string
from urllib import quote
from whrandom import choice
def unique_id(self):
    id=md5.new()
    id.update(self.absolute_url())
    id.update(str(time.time()))
    id=id.digest()
    id=string.strip(id)
    id=string.strip(base64.encodestring(id))
    id=quote(id[:-2])
    seq = string.hexdigits + string.lowercase + string.uppercase
    new_id = ''
    for l in id:
        if l == '/' or l == '%':
            new_id = new_id + choice(seq)
        else:
            new_id = new_id + l
    return new_id


If anyone has a more elegant solution I would love to set my tired eyes
on it. ;-)

All my best,


-- 
Jason Spisak
444@hiretechs.com