Commit 6b60b643 authored by Hanno Schlichting's avatar Hanno Schlichting

Avoid deprecation warnings for the md5 and sha modules in Python 2.6 by adding...

Avoid deprecation warnings for the md5 and sha modules in Python 2.6 by adding conditional imports for the hashlib module.
parent da1df526
......@@ -9,6 +9,9 @@ Zope Changes
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
......
......@@ -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 @@ class SSHADigestScheme:
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 @@ class SSHADigestScheme:
# 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 @@ registerScheme('SSHA', SSHADigestScheme())
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())
......
......@@ -21,7 +21,7 @@ Allowing Import of Modules
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'.
......
......@@ -18,7 +18,6 @@ from cPickle import dumps
from cPickle import loads
from cStringIO import StringIO
import marshal
import md5
import os
import re
import string
......@@ -61,7 +60,6 @@ from sqlgroup import SQLGroup
from sqltest import SQLTest
from sqlvar import SQLVar
md5new = md5.new
class DatabaseError(BadRequest):
" base class for external relational data base connection problems "
......
......@@ -345,9 +345,13 @@ class ZClass(Base, Collection, SimpleItem):
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()
......
......@@ -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 @@ class monitor_server (asyncore.dispatcher):
)
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())),
......
......@@ -9,10 +9,13 @@ import socket
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 @@ class encrypted_monitor_client (monitor_client):
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())),
......
......@@ -10,10 +10,14 @@ import socket
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())),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment