[Zodb-checkins] SVN: ZODB/branches/matt-python2.6/src/Z Began fixing deprecation errors, non-functional check-in.

matt@zope.com cvs-admin at zope.org
Fri Nov 14 12:20:54 EST 2008


Log message for revision 92935:
  Began fixing deprecation errors, non-functional check-in.
  

Changed:
  U   ZODB/branches/matt-python2.6/src/ZEO/auth/auth_digest.py
  U   ZODB/branches/matt-python2.6/src/ZEO/auth/base.py
  U   ZODB/branches/matt-python2.6/src/ZEO/tests/auth_plaintext.py
  U   ZODB/branches/matt-python2.6/src/ZEO/zrpc/smac.py
  U   ZODB/branches/matt-python2.6/src/ZODB/POSException.py

-=-
Modified: ZODB/branches/matt-python2.6/src/ZEO/auth/auth_digest.py
===================================================================
--- ZODB/branches/matt-python2.6/src/ZEO/auth/auth_digest.py	2008-11-14 16:59:00 UTC (rev 92934)
+++ ZODB/branches/matt-python2.6/src/ZEO/auth/auth_digest.py	2008-11-14 17:20:54 UTC (rev 92935)
@@ -37,7 +37,6 @@
 
 import os
 import random
-import sha
 import struct
 import time
 
@@ -45,6 +44,18 @@
 from ZEO.StorageServer import ZEOStorage
 from ZEO.Exceptions import AuthError
 
+# In Python 2.6 and onward, the "sha" and "md5" modules have been deprecated
+# in favor of "hashlib".
+
+import sys
+if sys.version_info[:2] >= (2,6):
+    import hashlib
+    hash = hashlib.sha1
+else:
+    import sha
+    hash = sha
+
+
 def get_random_bytes(n=8):
     if os.path.exists("/dev/urandom"):
         f = open("/dev/urandom")
@@ -56,8 +67,9 @@
     return s
 
 def hexdigest(s):
-    return sha.new(s).hexdigest()
+    return hash(s).hexdigest()
 
+
 class DigestDatabase(Database):
     def __init__(self, filename, realm=None):
         Database.__init__(self, filename, realm)
@@ -76,7 +88,7 @@
     # HMAC wants a 64-byte key.  We don't want to use h_up
     # directly because it would never change over time.  Instead
     # use the hash plus part of h_up.
-    return sha.new("%s:%s" % (h_up, nonce)).digest() + h_up[:44]
+    return hash.new("%s:%s" % (h_up, nonce)).digest() + h_up[:44]
 
 class StorageClass(ZEOStorage):
     def set_database(self, database):
@@ -92,7 +104,7 @@
     def _get_nonce(self):
         # RFC 2069 recommends a nonce of the form
         # H(client-IP ":" time-stamp ":" private-key)
-        dig = sha.sha()
+        dig = hash.sha()
         dig.update(str(self.connection.addr))
         dig.update(self._get_time())
         dig.update(self.noncekey)

Modified: ZODB/branches/matt-python2.6/src/ZEO/auth/base.py
===================================================================
--- ZODB/branches/matt-python2.6/src/ZEO/auth/base.py	2008-11-14 16:59:00 UTC (rev 92934)
+++ ZODB/branches/matt-python2.6/src/ZEO/auth/base.py	2008-11-14 17:20:54 UTC (rev 92935)
@@ -18,8 +18,18 @@
 """
 
 import os
-import sha
 
+# In Python 2.6 and onward, the "sha" and "md5" modules have been deprecated
+# in favor of "hashlib".
+
+import sys
+if sys.version_info[:2] >= (2,6):
+    import hashlib
+    hash = hashlib.sha1
+else:
+    import sha
+    hash = sha
+
 class Client:
     # Subclass should override to list the names of methods that
     # will be called on the server.
@@ -44,7 +54,8 @@
 
     The password file is a simple, colon-separated text file mapping
     usernames to password hashes. The hashes are SHA hex digests
-    produced from the password string.
+    produced from the password string. Beyond Python 2.5, the sha
+   module has been changed to import hashlib.
     """
     realm = None
     def __init__(self, filename, realm=None):
@@ -113,7 +124,7 @@
         return self._users[username]
 
     def hash(self, s):
-        return sha.new(s).hexdigest()
+        return hash(s).hexdigest()
 
     def add_user(self, username, password):
         if self._users.has_key(username):

Modified: ZODB/branches/matt-python2.6/src/ZEO/tests/auth_plaintext.py
===================================================================
--- ZODB/branches/matt-python2.6/src/ZEO/tests/auth_plaintext.py	2008-11-14 16:59:00 UTC (rev 92934)
+++ ZODB/branches/matt-python2.6/src/ZEO/tests/auth_plaintext.py	2008-11-14 17:20:54 UTC (rev 92935)
@@ -19,14 +19,23 @@
 is provided by not storing plaintext passwords on disk.
 """
 
-import sha
+# In Python 2.6 and onward, the "sha" and "md5" modules have been deprecated
+# in favor of "hashlib".
 
+import sys
+if sys.version_info[:2] >= (2,6):
+    import hashlib
+    hash = hashlib.sha1
+else:
+    import sha
+    hash = sha
+
 from ZEO.StorageServer import ZEOStorage
 from ZEO.auth import register_module
 from ZEO.auth.base import Client, Database
 
 def session_key(username, realm, password):
-    return sha.new("%s:%s:%s" % (username, realm, password)).hexdigest()
+    return hash.new("%s:%s:%s" % (username, realm, password)).hexdigest()
 
 class StorageClass(ZEOStorage):
 
@@ -36,7 +45,7 @@
         except LookupError:
             return 0
 
-        password_dig = sha.new(password).hexdigest()
+        password_dig = hash.new(password).hexdigest()
         if dbpw == password_dig:
             self.connection.setSessionKey(session_key(username,
                                                       self.database.realm,

Modified: ZODB/branches/matt-python2.6/src/ZEO/zrpc/smac.py
===================================================================
--- ZODB/branches/matt-python2.6/src/ZEO/zrpc/smac.py	2008-11-14 16:59:00 UTC (rev 92934)
+++ ZODB/branches/matt-python2.6/src/ZEO/zrpc/smac.py	2008-11-14 17:20:54 UTC (rev 92935)
@@ -31,9 +31,9 @@
     import hmac
 except ImportError:
     import _hmac as hmac
-import sha
 import socket
 import struct
+import sys
 import threading
 import logging
 from types import StringType
@@ -43,7 +43,16 @@
 from ZEO.zrpc.log import log, short_repr
 from ZEO.zrpc.error import DisconnectedError
 
+# In Python 2.6 and onward, the "sha" and "md5" modules have been deprecated
+# in favor of "hashlib".
 
+if sys.version_info[:2] >= (2,6):
+    import hashlib
+    hash = hashlib.sha1
+else:
+    import sha
+    hash = sha
+
 # Use the dictionary to make sure we get the minimum number of errno
 # entries.   We expect that EWOULDBLOCK == EAGAIN on most systems --
 # or that only one is actually used.
@@ -147,8 +156,8 @@
         # and thus iterator, because it contains a yield statement.
 
         def hack():
-            self.__hmac_send = hmac.HMAC(sesskey, digestmod=sha)
-            self.__hmac_recv = hmac.HMAC(sesskey, digestmod=sha)
+            self.__hmac_send = hmac.HMAC(sesskey, digestmod=hash)
+            self.__hmac_recv = hmac.HMAC(sesskey, digestmod=hash)
             if False:
                 yield ''
 

Modified: ZODB/branches/matt-python2.6/src/ZODB/POSException.py
===================================================================
--- ZODB/branches/matt-python2.6/src/ZODB/POSException.py	2008-11-14 16:59:00 UTC (rev 92934)
+++ ZODB/branches/matt-python2.6/src/ZODB/POSException.py	2008-11-14 17:20:54 UTC (rev 92935)
@@ -31,7 +31,21 @@
     return err
 _recon.__no_side_effects__ = True
 
-class POSError(StandardError):
+class DepError(object):
+    """Allows us to use 'message' property, deprecated by Python 2.6."""
+
+    def __set_message(self, v):
+        self.__dict__['message'] = v
+
+    def __get_message(self):
+        return self.__dict__['message']
+
+    def __del_message(self):
+        del self.__dict__['message']
+
+    message = property(__get_message, __set_message, __del_message)
+
+class POSError(DepError, StandardError):
     """Persistent object system error."""
 
     def __reduce__(self):
@@ -42,14 +56,14 @@
 
         return (_recon, (self.__class__, state))
 
-class POSKeyError(KeyError, POSError):
+class POSKeyError(POSError, KeyError):
     """Key not found in database."""
 
     def __str__(self):
         return oid_repr(self.args[0])
 
 
-class ConflictError(TransactionError):
+class ConflictError(DepError, TransactionError):
     """Two transactions tried to modify the same object at once.
 
     This transaction should be resubmitted.
@@ -213,7 +227,7 @@
         return "BTrees conflict error at %d/%d/%d: %s" % (
             self.p1, self.p2, self.p3, self.msgs[self.reason])
 
-class DanglingReferenceError(TransactionError):
+class DanglingReferenceError(DepError, TransactionError):
     """An object has a persistent reference to a missing object.
 
     If an object is stored and it has a reference to another object



More information about the Zodb-checkins mailing list