[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/ using ZEO.hash

Andreas Jung andreas at andreas-jung.com
Mon Mar 30 16:40:10 EDT 2009


Log message for revision 98628:
  using ZEO.hash
  

Changed:
  A   ZODB/trunk/src/ZEO/hash.py
  U   ZODB/trunk/src/ZEO/tests/auth_plaintext.py

-=-
Added: ZODB/trunk/src/ZEO/hash.py
===================================================================
--- ZODB/trunk/src/ZEO/hash.py	                        (rev 0)
+++ ZODB/trunk/src/ZEO/hash.py	2009-03-30 20:40:10 UTC (rev 98628)
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+"""In Python 2.6, the "sha" and "md5" modules have been deprecated
+in favor of using hashlib for both. This class allows for compatibility
+between versions."""
+
+import sys
+
+if sys.version_info[:2] >= (2, 6):
+    import hashlib
+    sha1 = hashlib.sha1
+    new = sha1
+else:
+    import sha
+    sha1 = sha.new
+    new = sha1
+    digest_size = sha.digest_size

Modified: ZODB/trunk/src/ZEO/tests/auth_plaintext.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/auth_plaintext.py	2009-03-30 20:31:36 UTC (rev 98627)
+++ ZODB/trunk/src/ZEO/tests/auth_plaintext.py	2009-03-30 20:40:10 UTC (rev 98628)
@@ -19,17 +19,15 @@
 is provided by not storing plaintext passwords on disk.
 """
 
-try:
-    from hashlib import sha1 as sha
-except ImportError:
-    import sha
 
 from ZEO.StorageServer import ZEOStorage
 from ZEO.auth import register_module
 from ZEO.auth.base import Client, Database
 
+from ZEO.hash import sha1
+
 def session_key(username, realm, password):
-    return sha.new("%s:%s:%s" % (username, realm, password)).hexdigest()
+    return sha1.new("%s:%s:%s" % (username, realm, password)).hexdigest()
 
 class StorageClass(ZEOStorage):
 
@@ -39,7 +37,7 @@
         except LookupError:
             return 0
 
-        password_dig = sha.new(password).hexdigest()
+        password_dig = sha1.new(password).hexdigest()
         if dbpw == password_dig:
             self.connection.setSessionKey(session_key(username,
                                                       self.database.realm,



More information about the Zodb-checkins mailing list