[Zope-Checkins] SVN: Zope/trunk/ Avoid deprecation warnings for the md5 and sha modules in Python 2.6 by adding conditional imports for the hashlib module.
Hanno Schlichting
plone at hannosch.info
Wed Jan 14 12:36:51 EST 2009
Log message for revision 94737:
Avoid deprecation warnings for the md5 and sha modules in Python 2.6 by adding conditional imports for the hashlib module.
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/AccessControl/AuthEncoding.py
U Zope/trunk/lib/python/Products/PythonScripts/help/ModuleAccess.stx
U Zope/trunk/lib/python/Shared/DC/ZRDB/DA.py
U Zope/trunk/lib/python/ZClasses/ZClass.py
U Zope/trunk/lib/python/ZServer/medusa/monitor.py
U Zope/trunk/lib/python/ZServer/medusa/monitor_client.py
U Zope/trunk/lib/python/ZServer/medusa/monitor_client_win32.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2009-01-14 17:28:52 UTC (rev 94736)
+++ Zope/trunk/doc/CHANGES.txt 2009-01-14 17:36:51 UTC (rev 94737)
@@ -9,6 +9,9 @@
Restructuring
+ - Avoid deprecation warnings for the md5 and sha modules in Python 2.6
+ by adding conditional imports for the hashlib module.
+
- Replaced imports from the 'Globals' module throughout the
tree with imports from the actual modules; the 'Globals' module
was always intended to be an area for shared data, rather than
Modified: Zope/trunk/lib/python/AccessControl/AuthEncoding.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/AuthEncoding.py 2009-01-14 17:28:52 UTC (rev 94736)
+++ Zope/trunk/lib/python/AccessControl/AuthEncoding.py 2009-01-14 17:36:51 UTC (rev 94737)
@@ -13,7 +13,12 @@
__version__='$Revision: 1.9 $'[11:-2]
-import sha, binascii
+try:
+ from hashlib import sha1 as sha
+except:
+ from sha import new as sha
+
+import binascii
from binascii import b2a_base64, a2b_base64
from random import choice, randrange
@@ -68,7 +73,7 @@
def encrypt(self, pw):
pw = str(pw)
salt = self.generate_salt()
- return b2a_base64(sha.new(pw + salt).digest() + salt)[:-1]
+ return b2a_base64(sha(pw + salt).digest() + salt)[:-1]
def validate(self, reference, attempt):
try:
@@ -77,7 +82,7 @@
# Not valid base64.
return 0
salt = ref[20:]
- compare = b2a_base64(sha.new(attempt + salt).digest() + salt)[:-1]
+ compare = b2a_base64(sha(attempt + salt).digest() + salt)[:-1]
return (compare == reference)
registerScheme('SSHA', SSHADigestScheme())
@@ -86,10 +91,10 @@
class SHADigestScheme:
def encrypt(self, pw):
- return b2a_base64(sha.new(pw).digest())[:-1]
+ return b2a_base64(sha(pw).digest())[:-1]
def validate(self, reference, attempt):
- compare = b2a_base64(sha.new(attempt).digest())[:-1]
+ compare = b2a_base64(sha(attempt).digest())[:-1]
return (compare == reference)
registerScheme('SHA', SHADigestScheme())
Modified: Zope/trunk/lib/python/Products/PythonScripts/help/ModuleAccess.stx
===================================================================
--- Zope/trunk/lib/python/Products/PythonScripts/help/ModuleAccess.stx 2009-01-14 17:28:52 UTC (rev 94736)
+++ Zope/trunk/lib/python/Products/PythonScripts/help/ModuleAccess.stx 2009-01-14 17:36:51 UTC (rev 94737)
@@ -21,7 +21,7 @@
from Products.PythonScripts.Utility import allow_module, allow_class
from AccessControl import ModuleSecurityInfo, ClassSecurityInfo
- from Globals import InitializeClass
+ from App.class_init import InitializeClass
4. For each module to which you want to allow access, add
security declarations in '__init__.py'.
Modified: Zope/trunk/lib/python/Shared/DC/ZRDB/DA.py
===================================================================
--- Zope/trunk/lib/python/Shared/DC/ZRDB/DA.py 2009-01-14 17:28:52 UTC (rev 94736)
+++ Zope/trunk/lib/python/Shared/DC/ZRDB/DA.py 2009-01-14 17:36:51 UTC (rev 94737)
@@ -18,7 +18,6 @@
from cPickle import loads
from cStringIO import StringIO
import marshal
-import md5
import os
import re
import string
@@ -61,7 +60,6 @@
from sqltest import SQLTest
from sqlvar import SQLVar
-md5new = md5.new
class DatabaseError(BadRequest):
" base class for external relational data base connection problems "
Modified: Zope/trunk/lib/python/ZClasses/ZClass.py
===================================================================
--- Zope/trunk/lib/python/ZClasses/ZClass.py 2009-01-14 17:28:52 UTC (rev 94736)
+++ Zope/trunk/lib/python/ZClasses/ZClass.py 2009-01-14 17:36:51 UTC (rev 94737)
@@ -345,9 +345,13 @@
self._zbases=copy._zbases
def _new_class_id(self):
- import md5, base64, time
+ try:
+ from hashlib import md5
+ except:
+ from md5 import new as md5
+ import base64, time
- id=md5.new()
+ id=md5()
id.update(self.absolute_url())
id.update(str(time.time()))
id=id.digest()
Modified: Zope/trunk/lib/python/ZServer/medusa/monitor.py
===================================================================
--- Zope/trunk/lib/python/ZServer/medusa/monitor.py 2009-01-14 17:28:52 UTC (rev 94736)
+++ Zope/trunk/lib/python/ZServer/medusa/monitor.py 2009-01-14 17:36:51 UTC (rev 94737)
@@ -7,12 +7,16 @@
RCS_ID = '$Id$'
-import md5
import socket
import string
import sys
import time
+try:
+ from hashlib import md5
+except:
+ from md5 import new as md5
+
if RCS_ID.startswith('$Id: '):
VERSION = string.split(RCS_ID)[2]
else:
@@ -195,7 +199,7 @@
)
def hex_digest (s):
- m = md5.md5()
+ m = md5()
m.update (s)
return string.joinfields (
map (lambda x: hex (ord (x))[2:], map (None, m.digest())),
Modified: Zope/trunk/lib/python/ZServer/medusa/monitor_client.py
===================================================================
--- Zope/trunk/lib/python/ZServer/medusa/monitor_client.py 2009-01-14 17:28:52 UTC (rev 94736)
+++ Zope/trunk/lib/python/ZServer/medusa/monitor_client.py 2009-01-14 17:36:51 UTC (rev 94737)
@@ -9,10 +9,13 @@
import string
import sys
import os
-
-import md5
import time
+try:
+ from hashlib import md5
+except:
+ from md5 import new as md5
+
class stdin_channel (asyncore.file_dispatcher):
def handle_read (self):
data = self.recv(512)
@@ -84,7 +87,7 @@
return data
def hex_digest (s):
- m = md5.md5()
+ m = md5()
m.update (s)
return string.join (
map (lambda x: hex (ord (x))[2:], map (None, m.digest())),
Modified: Zope/trunk/lib/python/ZServer/medusa/monitor_client_win32.py
===================================================================
--- Zope/trunk/lib/python/ZServer/medusa/monitor_client_win32.py 2009-01-14 17:28:52 UTC (rev 94736)
+++ Zope/trunk/lib/python/ZServer/medusa/monitor_client_win32.py 2009-01-14 17:36:51 UTC (rev 94737)
@@ -10,10 +10,14 @@
import string
import sys
import thread
-import md5
+try:
+ from hashlib import md5
+except:
+ from md5 import new as md5
+
def hex_digest (s):
- m = md5.md5()
+ m = md5()
m.update (s)
return string.join (
map (lambda x: hex (ord (x))[2:], map (None, m.digest())),
More information about the Zope-Checkins
mailing list