diff MoinMoin/support/md5crypt.py @ 5731:8692137f2ccc

md5crypt: fix python 2.4 compatibility, untested
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 26 Nov 2010 21:21:16 +0100
parents 69668ad0cae7
children
line wrap: on
line diff
--- a/MoinMoin/support/md5crypt.py	Sun Nov 21 00:10:10 2010 +0100
+++ b/MoinMoin/support/md5crypt.py	Fri Nov 26 21:21:16 2010 +0100
@@ -41,7 +41,14 @@
 MAGIC = '$1$'                   # Magic string
 ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
 
-import hashlib
+try:
+    import hashlib
+    hash_md5 = hashlib.md5
+except ImportError:
+    # maybe we have python < 2.5 (no hashlib)
+    import md5
+    hash_md5 = md5.new
+
 
 def to64 (v, n):
     ret = ''
@@ -74,7 +81,7 @@
 
     ctx = pw + magic + salt
 
-    md5 = hashlib.md5()
+    md5 = hash_md5()
     md5.update(pw + salt + pw)
     final = md5.digest()
 
@@ -95,7 +102,7 @@
             ctx = ctx + pw[0]
         i = i >> 1
 
-    md5 = hashlib.md5()
+    md5 = hash_md5()
     md5.update(ctx)
     final = md5.digest()
 
@@ -123,7 +130,7 @@
             ctx1 = ctx1 + pw
 
 
-        md5 = hashlib.md5()
+        md5 = hash_md5()
         md5.update(ctx1)
         final = md5.digest()