[Checkins] SVN: zope.session/trunk/ Restore compatibility with Python 2.4.

Hanno Schlichting plone at hannosch.info
Mon Apr 20 16:28:51 EDT 2009


Log message for revision 99330:
  Restore compatibility with Python 2.4.
  

Changed:
  U   zope.session/trunk/CHANGES.txt
  U   zope.session/trunk/src/zope/session/http.py

-=-
Modified: zope.session/trunk/CHANGES.txt
===================================================================
--- zope.session/trunk/CHANGES.txt	2009-04-20 16:48:14 UTC (rev 99329)
+++ zope.session/trunk/CHANGES.txt	2009-04-20 20:28:50 UTC (rev 99330)
@@ -4,7 +4,8 @@
 3.9.1 (unreleased)
 ------------------
 
-- ...
+- Restore compatibility with Python 2.4.
+  [hannosch]
 
 3.9.0 (2009-03-19)
 ------------------

Modified: zope.session/trunk/src/zope/session/http.py
===================================================================
--- zope.session/trunk/src/zope/session/http.py	2009-04-20 16:48:14 UTC (rev 99329)
+++ zope.session/trunk/src/zope/session/http.py	2009-04-20 20:28:50 UTC (rev 99330)
@@ -26,7 +26,7 @@
     from hashlib import sha1
 except ImportError:
     # Python 2.4
-    from sha import new as sha1
+    import sha as sha1
 try:
     from email.utils import formatdate
 except ImportError:
@@ -257,7 +257,11 @@
 
         """
         data = "%.20f%.20f%.20f" % (random.random(), time.time(), time.clock())
-        digest = sha1(data).digest()
+        # BBB code for Python 2.4, inspired by the fallback in hmac
+        if hasattr(sha1, '__call__'):
+            digest = sha1(data).digest()
+        else:
+            digest = sha1.new(data).digest()
         s = digestEncode(digest)
         # we store a HMAC of the random value together with it, which makes
         # our session ids unforgeable.



More information about the Checkins mailing list