[Zope] Generating unique keys
gtk
gtk@well.com
Mon, 11 Oct 1999 22:02:17 +1000
> > > I need to generate unique ID's for objects I'll be creating from DTML.
This
>
> application. Once when I needed to do something similar I generated an
> md5 checksum out of a property of the Zope object and its parent
> folder id. In my application such a combination was unique. If you have
I just tried this out, creating md5er.py in my extensions directory:
# md5er external method module for Zope
def md5(inputstring):
import md5
m=md5.new()
m.update(inputstring)
return m.digest()
... then creating external method md5er aimed at the module md5er, function
name md5. So far, not bad, since it's my first Zope external method and also
the first Python code I've ever written. I like this stuff. Nice and simple.
But I digress.
<dtml-var expr="md5er('ggdgfg')">
... works just as expected. The output is 8-bit garbage, though -- anyone
know of a nice unpack or hex conversion function I can call to clean that up
into a clean string?
Here's something wierd, though:
<dtml-var expr="md5er(id)">
... gives me an error:
Error Type: TypeError
Error Value: read-only buffer, Python Method
Any suggestions?