changeset 5520:aa99f8e782dc

backport hmac compatibility code from moin/1.8
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 08 Feb 2010 17:49:21 +0100
parents 28d3928f6e6e
children 8a19e015d6b2
files MoinMoin/support/python_compatibility.py
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/support/python_compatibility.py	Sun Feb 07 23:04:09 2010 +0100
+++ b/MoinMoin/support/python_compatibility.py	Mon Feb 08 17:49:21 2010 +0100
@@ -76,18 +76,28 @@
             else:
                 d = kw or self.kw
             return self.fn(*(self.args + args), **d)
+
 """
 This is a feature from python 2.5, needed for compatibility with python 2.3 and 2.4,
 although it may not be 100% compatible.
 """
 try:
-    from hashlib import new as hash_new
-except (NameError,  ImportError):
+    import hashlib, hmac
+    hash_new = hashlib.new
+    def hmac_new(key, msg, digestmod=hashlib.sha1):
+        return hmac.new(key, msg, digestmod)
+
+except (NameError, ImportError):
+    import sha
     def hash_new(name, string=''):
         if name in ('SHA1', 'sha1'):
-            import sha
             return sha.new(string)
         elif name in ('MD5', 'md5'):
             import md5
             return md5.new(string)
         raise ValueError("unsupported hash type")
+
+    def hmac_new(key, msg, digestmod=sha):
+        import hmac
+        return hmac.new(key, msg, digestmod)
+