[Zodb-checkins] SVN: ZODB/branches/matt-python2.6/src/Z Checkpoint - reverted changes and created module to hold hashlib.
matt@zope.com
cvs-admin at zope.org
Fri Nov 14 15:28:55 EST 2008
Log message for revision 92942:
Checkpoint - reverted changes and created module to hold hashlib.
Changed:
U ZODB/branches/matt-python2.6/src/ZEO/auth/auth_digest.py
U ZODB/branches/matt-python2.6/src/ZEO/auth/base.py
A ZODB/branches/matt-python2.6/src/ZEO/hash.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 20:26:21 UTC (rev 92941)
+++ ZODB/branches/matt-python2.6/src/ZEO/auth/auth_digest.py 2008-11-14 20:28:55 UTC (rev 92942)
@@ -38,32 +38,13 @@
import os
import random
import struct
-import sys
import time
-from ZEO.auth.base import Database, Client
-from ZEO.StorageServer import ZEOStorage
from ZEO.Exceptions import AuthError
+from ZEO.StorageServer import ZEOStorage
+from ZEO.auth.base import Database, Client
+import ZEO.hash
-# 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):
- def hash(s):
- import hashlib
- if not s:
- return hashlib.sha1()
- else:
- return hashlib.sha1(s)
-else:
- def hash(s):
- import sha
- if not s:
- hash = sha.new()
- return hash
- else:
- hash = sha.new(s)
- return hash
-
def get_random_bytes(n=8):
if os.path.exists("/dev/urandom"):
f = open("/dev/urandom")
@@ -77,7 +58,6 @@
def hexdigest(s):
return hash(s).hexdigest()
-
class DigestDatabase(Database):
def __init__(self, filename, realm=None):
Database.__init__(self, filename, realm)
@@ -112,7 +92,7 @@
def _get_nonce(self):
# RFC 2069 recommends a nonce of the form
# H(client-IP ":" time-stamp ":" private-key)
- dig = hash
+ dig = hash()
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 20:26:21 UTC (rev 92941)
+++ ZODB/branches/matt-python2.6/src/ZEO/auth/base.py 2008-11-14 20:28:55 UTC (rev 92942)
@@ -18,26 +18,8 @@
"""
import os
-import sys
-# 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):
- def hash(s):
- import hashlib
- if not s:
- return hashlib.sha1()
- else:
- return hashlib.sha1(s)
-else:
- def hash(s):
- import sha
- if not s:
- hash = sha.new()
- return hash
- else:
- hash = sha.new(s)
- return hash
+import ZEO.hash
class Client:
# Subclass should override to list the names of methods that
@@ -63,8 +45,7 @@
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. Beyond Python 2.5, the sha
- module is retrieved from hashlib.
+ produced from the password string.
"""
realm = None
def __init__(self, filename, realm=None):
Added: ZODB/branches/matt-python2.6/src/ZEO/hash.py
===================================================================
--- ZODB/branches/matt-python2.6/src/ZEO/hash.py (rev 0)
+++ ZODB/branches/matt-python2.6/src/ZEO/hash.py 2008-11-14 20:28:55 UTC (rev 92942)
@@ -0,0 +1,25 @@
+##############################################################################
+#
+# Copyright (c) 2003 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
+ hash = hashlib.sha1
+else:
+ import sha
+ hash = sha.new
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 20:26:21 UTC (rev 92941)
+++ ZODB/branches/matt-python2.6/src/ZEO/tests/auth_plaintext.py 2008-11-14 20:28:55 UTC (rev 92942)
@@ -19,30 +19,10 @@
is provided by not storing plaintext passwords on disk.
"""
-import sys
-
-# 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):
- def hash(s):
- import hashlib
- if not s:
- return hashlib.sha1()
- else:
- return hashlib.sha1(s)
-else:
- def hash(s):
- import sha
- if not s:
- hash = sha.new()
- return hash
- else:
- hash = sha.new()
- return hash
-
from ZEO.StorageServer import ZEOStorage
from ZEO.auth import register_module
from ZEO.auth.base import Client, Database
+import ZEO.hash
def session_key(username, realm, password):
return hash("%s:%s:%s" % (username, realm, password)).hexdigest()
Modified: ZODB/branches/matt-python2.6/src/ZEO/zrpc/smac.py
===================================================================
--- ZODB/branches/matt-python2.6/src/ZEO/zrpc/smac.py 2008-11-14 20:26:21 UTC (rev 92941)
+++ ZODB/branches/matt-python2.6/src/ZEO/zrpc/smac.py 2008-11-14 20:28:55 UTC (rev 92942)
@@ -33,34 +33,16 @@
import _hmac as hmac
import socket
import struct
-import sys
import threading
import logging
from types import StringType
from ZODB.loglevels import TRACE
-from ZEO.zrpc.log import log, short_repr
from ZEO.zrpc.error import DisconnectedError
+from ZEO.zrpc.log import log, short_repr
+import ZEO.hash
-# 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):
- def hash(s):
- import hashlib
- if not s:
- return hashlib.sha1()
- else:
- return hashlib.sha1(s)
-else:
- def hash(s):
- import sha
- if not s:
- hash = sha.new()
- return hash
- else:
- hash = sha.new(s)
- return hash
# Use the dictionary to make sure we get the minimum number of errno
# entries. We expect that EWOULDBLOCK == EAGAIN on most systems --
Modified: ZODB/branches/matt-python2.6/src/ZODB/POSException.py
===================================================================
--- ZODB/branches/matt-python2.6/src/ZODB/POSException.py 2008-11-14 20:26:21 UTC (rev 92941)
+++ ZODB/branches/matt-python2.6/src/ZODB/POSException.py 2008-11-14 20:28:55 UTC (rev 92942)
@@ -31,9 +31,11 @@
return err
_recon.__no_side_effects__ = True
-class DepError(object):
- """Allows us to use 'message' property, deprecated by Python 2.6."""
+class POSError(StandardError):
+ """Persistent object system error."""
+ # The 'message' attribute was deprecated for BaseException with
+ # Python 2.6; here we create descriptor properties to continue using it
def __set_message(self, v):
self.__dict__['message'] = v
@@ -45,9 +47,6 @@
message = property(__get_message, __set_message, __del_message)
-class POSError(DepError, StandardError):
- """Persistent object system error."""
-
def __reduce__(self):
# Cope extra data from internal structures
state = self.__dict__.copy()
@@ -63,7 +62,7 @@
return oid_repr(self.args[0])
-class ConflictError(DepError, TransactionError):
+class ConflictError(POSError, TransactionError):
"""Two transactions tried to modify the same object at once.
This transaction should be resubmitted.
@@ -227,7 +226,7 @@
return "BTrees conflict error at %d/%d/%d: %s" % (
self.p1, self.p2, self.p3, self.msgs[self.reason])
-class DanglingReferenceError(DepError, TransactionError):
+class DanglingReferenceError(POSError, 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