[zopeorg-checkins] CVS: Products/ZopeOrg-NV - __init__.py:1.36

Brian Lloyd brian at zope.com
Mon Aug 25 10:23:27 EDT 2003


Update of /cvs-zopeorg/Products/ZopeOrg-NV
In directory cvs.zope.org:/tmp/cvs-serv8488

Modified Files:
	__init__.py 
Log Message:
Fixed md5 bugs


=== Products/ZopeOrg-NV/__init__.py 1.35 => 1.36 ===
 # Hack to fix MD5 sums for CMFPackage SW release files. This really
 # should go back into that product, once the owner is identified.
 
+def _calculateMD5(self):
+    """monkey patch"""
+    body = str(self)
+    hash = md5.new(body).digest()
+    func = lambda x: '%0.2x' % ord(x)
+    self._md5 = ''.join(map(func, hash))
+    self._md5_ok = 1
+
 def MD5(self, RESPONSE=None):
     """monkey patch"""
-    v = getattr(aq_base(self), '_md5', '')
-    if v and v[0] == '0':
-        return v[1:]
-    return v
+    # This is evil - write on read, but avoids a conversion effort.
+    if not getattr(self, '_md5_ok', 0):
+        self._calculateMD5()
+    return getattr(aq_base(self), '_md5', '')
+
 
 from Products.CMFPackage.SoftwareReleaseFile import SoftwareReleaseFile
+SoftwareReleaseFile._calculateMD5 = _calculateMD5
 SoftwareReleaseFile.MD5 = MD5
 
 





More information about the zopeorg-checkins mailing list