[Zodb-checkins] SVN: ZODB/branches/matt-python2.6/src/ZEO/ Checkpoint
matt@zope.com
cvs-admin at zope.org
Fri Nov 14 13:47:29 EST 2008
Log message for revision 92939:
Checkpoint
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
-=-
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 18:26:25 UTC (rev 92938)
+++ ZODB/branches/matt-python2.6/src/ZEO/auth/auth_digest.py 2008-11-14 18:47:29 UTC (rev 92939)
@@ -38,6 +38,7 @@
import os
import random
import struct
+import sys
import time
from ZEO.auth.base import Database, Client
@@ -46,16 +47,23 @@
# 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
+ def hash(s):
+ import hashlib
+ if not s:
+ return hashlib.sha1()
+ else:
+ return hashlib.sha1(s)
else:
- import sha
- hash = sha
+ 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")
@@ -88,7 +96,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 hash.new("%s:%s" % (h_up, nonce)).digest() + h_up[:44]
+ return hash("%s:%s" % (h_up, nonce)).digest() + h_up[:44]
class StorageClass(ZEOStorage):
def set_database(self, database):
@@ -104,7 +112,7 @@
def _get_nonce(self):
# RFC 2069 recommends a nonce of the form
# H(client-IP ":" time-stamp ":" private-key)
- dig = hash.sha()
+ 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 18:26:25 UTC (rev 92938)
+++ ZODB/branches/matt-python2.6/src/ZEO/auth/base.py 2008-11-14 18:47:29 UTC (rev 92939)
@@ -18,17 +18,26 @@
"""
import os
+import sys
# 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
+ def hash(s):
+ import hashlib
+ if not s:
+ return hashlib.sha1()
+ else:
+ return hashlib.sha1(s)
else:
- import sha
- hash = sha
+ def hash(s):
+ import sha
+ if not s:
+ hash = sha.new()
+ return hash
+ else:
+ hash = sha.new(s)
+ return hash
class Client:
# Subclass should override to list the names of methods that
@@ -55,7 +64,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 has been changed to import hashlib.
+ module is retrieved from hashlib.
"""
realm = None
def __init__(self, filename, realm=None):
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 18:26:25 UTC (rev 92938)
+++ ZODB/branches/matt-python2.6/src/ZEO/tests/auth_plaintext.py 2008-11-14 18:47:29 UTC (rev 92939)
@@ -19,23 +19,33 @@
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".
-
-import sys
if sys.version_info[:2] >= (2,6):
- import hashlib
- hash = hashlib.sha1
+ def hash(s):
+ import hashlib
+ if not s:
+ return hashlib.sha1()
+ else:
+ return hashlib.sha1(s)
else:
- import sha
- hash = sha
+ 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
def session_key(username, realm, password):
- return hash.new("%s:%s:%s" % (username, realm, password)).hexdigest()
+ return hash("%s:%s:%s" % (username, realm, password)).hexdigest()
class StorageClass(ZEOStorage):
@@ -45,7 +55,7 @@
except LookupError:
return 0
- password_dig = hash.new(password).hexdigest()
+ password_dig = hash(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 18:26:25 UTC (rev 92938)
+++ ZODB/branches/matt-python2.6/src/ZEO/zrpc/smac.py 2008-11-14 18:47:29 UTC (rev 92939)
@@ -45,13 +45,22 @@
# 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
+ def hash(s):
+ import hashlib
+ if not s:
+ return hashlib.sha1()
+ else:
+ return hashlib.sha1(s)
else:
- import sha
- hash = sha
+ 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 --
More information about the Zodb-checkins
mailing list