[Erp5-report] r25615 - /erp5/trunk/products/ERP5Type/Utils.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Feb 18 18:43:47 CET 2009


Author: vincent
Date: Wed Feb 18 18:43:47 2009
New Revision: 25615

URL: http://svn.erp5.org?rev=25615&view=rev
Log:
Make it possible to compute SHA and MD5 sums from restricted code.

Modified:
    erp5/trunk/products/ERP5Type/Utils.py

Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=25615&r1=25614&r2=25615&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Wed Feb 18 18:43:47 2009
@@ -31,6 +31,8 @@
 import re
 import string
 import time
+from md5 import new as md5_new
+from sha import new as sha_new
 
 from Globals import package_home
 from Globals import DevelopmentMode
@@ -38,6 +40,8 @@
 from Acquisition import aq_inner
 from Acquisition import aq_parent
 from Acquisition import aq_self
+
+from AccessControl.SecurityInfo import allow_class
 
 from Products.CMFCore import utils
 from Products.CMFCore.Expression import Expression
@@ -2726,3 +2730,35 @@
     raise TypeError, 'do not know how to handle type %s' % type(x)
   return x
 
+#####################################################
+# Hashing
+#####################################################
+
+class GenericSum:
+  def __init__(self, sum):
+    self.sum = sum
+
+  def digest(self):
+    return self.sum.digest()
+
+  def hexdigest(self):
+    return self.sum.hexdigest()
+
+  def update(self, data):
+    self.sum.update(data)
+
+  def copy(self):
+    return self.__class__(self.sum.copy())
+
+class md5(GenericSum):
+  def __init__(self, *args):
+    GenericSum.__init__(self, md5_new(*args))
+
+allow_class(md5)
+
+class sha(GenericSum):
+  def __init__(self, *args):
+    GenericSum.__init__(self, sha_new(*args))
+
+allow_class(sha)
+




More information about the Erp5-report mailing list