------------------------------------------------------------
revno: 1135
committer: Barry Warsaw <[EMAIL PROTECTED]>
branch nick: 2.1
timestamp: Wed 2008-11-12 23:02:29 -0500
message:
  Apply Heiko Rommel's patch for hashlib deprecation warnings for bug 293178.
  I've modified the patch to improve some of the stylistic issues.
modified:
  Mailman/Cgi/admin.py
  Mailman/Cgi/create.py
  Mailman/Handlers/Scrubber.py
  Mailman/LockFile.py
  Mailman/Pending.py
  Mailman/Queue/Switchboard.py
  Mailman/SecurityManager.py
  Mailman/Utils.py
  bin/change_pw
  bin/export.py
  bin/newlist
  bin/update
  tests/test_handlers.py
  tests/test_security_mgr.py

=== modified file 'Mailman/Cgi/admin.py'
--- a/Mailman/Cgi/admin.py      2008-07-30 16:09:29 +0000
+++ b/Mailman/Cgi/admin.py      2008-11-13 04:02:29 +0000
@@ -24,7 +24,6 @@
 import os
 import re
 import cgi
-import sha
 import urllib
 import signal
 from types import *
@@ -41,6 +40,7 @@
 from Mailman.htmlformat import *
 from Mailman.Cgi import Auth
 from Mailman.Logging.Syslog import syslog
+from Mailman.Utils import sha_new
 
 # Set up i18n
 _ = i18n._
@@ -1269,7 +1269,7 @@
     confirm = cgidata.getvalue('confirmmodpw', '').strip()
     if new or confirm:
         if new == confirm:
-            mlist.mod_password = sha.new(new).hexdigest()
+            mlist.mod_password = sha_new(new).hexdigest()
             # No re-authentication necessary because the moderator's
             # password doesn't get you into these pages.
         else:
@@ -1279,7 +1279,7 @@
     confirm = cgidata.getvalue('confirmpw', '').strip()
     if new or confirm:
         if new == confirm:
-            mlist.password = sha.new(new).hexdigest()
+            mlist.password = sha_new(new).hexdigest()
             # Set new cookie
             print mlist.MakeCookie(mm_cfg.AuthListAdmin)
         else:

=== modified file 'Mailman/Cgi/create.py'
--- a/Mailman/Cgi/create.py     2007-11-25 08:04:30 +0000
+++ b/Mailman/Cgi/create.py     2008-11-13 04:02:29 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2007 by the Free Software Foundation, Inc.
+# Copyright (C) 2001-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -21,7 +21,6 @@
 import os
 import signal
 import cgi
-import sha
 from types import ListType
 
 from Mailman import mm_cfg
@@ -31,6 +30,7 @@
 from Mailman import i18n
 from Mailman.htmlformat import *
 from Mailman.Logging.Syslog import syslog
+from Mailman.Utils import sha_new
 
 # Set up i18n
 _ = i18n._
@@ -180,7 +180,7 @@
         # Install the emergency shutdown signal handler
         signal.signal(signal.SIGTERM, sigterm_handler)
 
-        pw = sha.new(password).hexdigest()
+        pw = sha_new(password).hexdigest()
         # Guarantee that all newly created files have the proper permission.
         # proper group ownership should be assured by the autoconf script
         # enforcing that all directories have the group sticky bit set

=== modified file 'Mailman/Handlers/Scrubber.py'
--- a/Mailman/Handlers/Scrubber.py      2007-11-18 20:12:22 +0000
+++ b/Mailman/Handlers/Scrubber.py      2008-11-13 04:02:29 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2007 by the Free Software Foundation, Inc.
+# Copyright (C) 2001-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -21,7 +21,6 @@
 
 import os
 import re
-import sha
 import time
 import errno
 import binascii
@@ -41,6 +40,7 @@
 from Mailman.Errors import DiscardMessage
 from Mailman.i18n import _
 from Mailman.Logging.Syslog import syslog
+from Mailman.Utils import sha_new
 
 # Path characters for common platforms
 pre = re.compile(r'[/\\:]')
@@ -158,7 +158,7 @@
     if msgid is None:
         msgid = msg['Message-ID'] = Utils.unique_message_id(mlist)
     # We assume that the message id actually /is/ unique!
-    digest = sha.new(msgid).hexdigest()
+    digest = sha_new(msgid).hexdigest()
     return os.path.join('attachments', datedir, digest[:4] + digest[-4:])
 
 

=== modified file 'Mailman/LockFile.py'
--- a/Mailman/LockFile.py       2005-08-27 01:40:17 +0000
+++ b/Mailman/LockFile.py       2008-11-13 04:02:29 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 1998-2003 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -546,8 +546,8 @@
     except EnvironmentError, e:
         if e.errno <> errno.ENOENT:
             raise
-        import sha
-        d = sha.new(`os.getpid()`+`time.time()`).hexdigest()
+        from Mailman.Utils import sha_new
+        d = sha_new(`os.getpid()`+`time.time()`).hexdigest()
     random.seed(d)
 
 

=== modified file 'Mailman/Pending.py'
--- a/Mailman/Pending.py        2005-08-27 01:40:17 +0000
+++ b/Mailman/Pending.py        2008-11-13 04:02:29 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 1998-2004 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -17,13 +17,13 @@
 """Track pending actions which require confirmation."""
 
 import os
-import sha
 import time
 import errno
 import random
 import cPickle
 
 from Mailman import mm_cfg
+from Mailman.Utils import sha_new
 
 # Types of pending records
 SUBSCRIPTION = 'S'
@@ -72,7 +72,7 @@
         while True:
             now = time.time()
             x = random.random() + now % 1.0 + time.clock() % 1.0
-            cookie = sha.new(repr(x)).hexdigest()
+            cookie = sha_new(repr(x)).hexdigest()
             # We'll never get a duplicate, but we'll be anal about checking
             # anyway.
             if not db.has_key(cookie):

=== modified file 'Mailman/Queue/Switchboard.py'
--- a/Mailman/Queue/Switchboard.py      2008-04-27 00:56:17 +0000
+++ b/Mailman/Queue/Switchboard.py      2008-11-13 04:02:29 +0000
@@ -35,7 +35,6 @@
 # needs.
 
 import os
-import sha
 import time
 import email
 import errno
@@ -46,6 +45,7 @@
 from Mailman import Utils
 from Mailman import Message
 from Mailman.Logging.Syslog import syslog
+from Mailman.Utils import sha_new
 
 # 20 bytes of all bits set, maximum sha.digest() value
 shamax = 0xffffffffffffffffffffffffffffffffffffffffL
@@ -118,7 +118,7 @@
         # this system) and the sha hex digest.
         #rcvtime = data.setdefault('received_time', now)
         rcvtime = data.setdefault('received_time', now)
-        filebase = `rcvtime` + '+' + sha.new(hashfood).hexdigest()
+        filebase = `rcvtime` + '+' + sha_new(hashfood).hexdigest()
         filename = os.path.join(self.__whichq, filebase + '.pck')
         tmpfile = filename + '.tmp'
         # Always add the metadata schema version number

=== modified file 'Mailman/SecurityManager.py'
--- a/Mailman/SecurityManager.py        2006-07-30 19:35:36 +0000
+++ b/Mailman/SecurityManager.py        2008-11-13 04:02:29 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 1998-2006 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -49,7 +49,6 @@
 
 import os
 import re
-import sha
 import time
 import Cookie
 import marshal
@@ -62,12 +61,12 @@
     import crypt
 except ImportError:
     crypt = None
-import md5
 
 from Mailman import mm_cfg
 from Mailman import Utils
 from Mailman import Errors
 from Mailman.Logging.Syslog import syslog
+from Mailman.Utils import md5_new, sha_new
 
 try:
     True, False
@@ -171,11 +170,11 @@
                 key, secret = self.AuthContextInfo(ac)
                 if secret is None:
                     continue
-                sharesponse = sha.new(response).hexdigest()
+                sharesponse = sha_new(response).hexdigest()
                 upgrade = ok = False
                 if sharesponse == secret:
                     ok = True
-                elif md5.new(response).digest() == secret:
+                elif md5_new(response).digest() == secret:
                     ok = upgrade = True
                 elif cryptmatchp(response, secret):
                     ok = upgrade = True
@@ -196,7 +195,7 @@
             elif ac == mm_cfg.AuthListModerator:
                 # The list moderator password must be sha'd
                 key, secret = self.AuthContextInfo(ac)
-                if secret and sha.new(response).hexdigest() == secret:
+                if secret and sha_new(response).hexdigest() == secret:
                     return ac
             elif ac == mm_cfg.AuthUser:
                 if user is not None:
@@ -237,7 +236,7 @@
         # Timestamp
         issued = int(time.time())
         # Get a digest of the secret, plus other information.
-        mac = sha.new(secret + `issued`).hexdigest()
+        mac = sha_new(secret + `issued`).hexdigest()
         # Create the cookie object.
         c = Cookie.SimpleCookie()
         c[key] = binascii.hexlify(marshal.dumps((issued, mac)))
@@ -336,7 +335,7 @@
             return False
         # Calculate what the mac ought to be based on the cookie's timestamp
         # and the shared secret.
-        mac = sha.new(secret + `issued`).hexdigest()
+        mac = sha_new(secret + `issued`).hexdigest()
         if mac <> received_mac:
             return False
         # Authenticated!

=== modified file 'Mailman/Utils.py'
--- a/Mailman/Utils.py  2008-05-08 03:46:19 +0000
+++ b/Mailman/Utils.py  2008-11-13 04:02:29 +0000
@@ -27,9 +27,9 @@
 from __future__ import nested_scopes
 
 import os
+import sys
 import re
 import cgi
-import sha
 import time
 import errno
 import base64
@@ -56,6 +56,16 @@
 from Mailman.Logging.Syslog import syslog
 
 try:
+    import hashlib
+    md5_new = hashlib.md5
+    sha_new = hashlib.sha1
+except ImportError:
+    import md5
+    import sha
+    md5_new = md5.new
+    sha_new = sha.new
+
+try:
     True, False
 except NameError:
     True = 1
@@ -384,7 +394,7 @@
     omask = os.umask(026)
     try:
         fp = open(filename, 'w')
-        fp.write(sha.new(pw).hexdigest() + '\n')
+        fp.write(sha_new(pw).hexdigest() + '\n')
         fp.close()
     finally:
         os.umask(omask)
@@ -410,7 +420,7 @@
     challenge = get_global_password(siteadmin)
     if challenge is None:
         return None
-    return challenge == sha.new(response).hexdigest()
+    return challenge == sha_new(response).hexdigest()
 
 
 
@@ -1034,3 +1044,4 @@
         return True
     else:
         return False
+

=== modified file 'bin/change_pw'
--- a/bin/change_pw     2007-12-04 19:42:54 +0000
+++ b/bin/change_pw     2008-11-13 04:02:29 +0000
@@ -1,6 +1,6 @@
 #! @PYTHON@
 #
-# Copyright (C) 2001-2007 by the Free Software Foundation, Inc.
+# Copyright (C) 2001-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -66,7 +66,6 @@
 """
 
 import sys
-import sha
 import getopt
 
 import paths
@@ -147,7 +146,7 @@
     if password is not None:
         if not password:
             usage(1, _('Empty list passwords are not allowed'))
-        shapassword = sha.new(password).hexdigest()
+        shapassword = Utils.sha_new(password).hexdigest()
 
     if domains:
         for name in Utils.list_names():
@@ -167,7 +166,7 @@
             if password is None:
                 randompw = Utils.MakeRandomPassword(
                     mm_cfg.ADMIN_PASSWORD_LENGTH)
-                shapassword = sha.new(randompw).hexdigest()
+                shapassword = Utils.sha_new(randompw).hexdigest()
                 notifypassword = randompw
             else:
                 notifypassword = password

=== modified file 'bin/export.py'
--- a/bin/export.py     2007-01-02 02:35:38 +0000
+++ b/bin/export.py     2008-11-13 04:02:29 +0000
@@ -1,6 +1,6 @@
 #! @PYTHON@
 #
-# Copyright (C) 2006-2007 by the Free Software Foundation, Inc.
+# Copyright (C) 2006-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -21,7 +21,6 @@
 
 import os
 import sys
-import sha
 import base64
 import codecs
 import datetime
@@ -289,13 +288,13 @@
 
 
 def sha_password(password):
-    h = sha.new(password)
+    h = Utils.sha_new(password)
     return '{SHA}' + base64.b64encode(h.digest())
 
 
 def ssha_password(password):
     salt = os.urandom(SALT_LENGTH)
-    h = sha.new(password)
+    h = Utils.sha_new(password)
     h.update(salt)
     return '{SSHA}' + base64.b64encode(h.digest() + salt)
 

=== modified file 'bin/newlist'
--- a/bin/newlist       2008-03-03 18:06:28 +0000
+++ b/bin/newlist       2008-11-13 04:02:29 +0000
@@ -1,6 +1,6 @@
 #! @PYTHON@
 #
-# Copyright (C) 1998-2005 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -14,7 +14,8 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
 
 """Create a new, unpopulated mailing list.
 
@@ -93,7 +94,6 @@
 import os
 import getpass
 import getopt
-import sha
 
 import paths
 from Mailman import mm_cfg
@@ -186,7 +186,7 @@
 
     mlist = MailList.MailList()
     try:
-        pw = sha.new(listpasswd).hexdigest()
+        pw = Utils.sha_new(listpasswd).hexdigest()
         # Guarantee that all newly created files have the proper permission.
         # proper group ownership should be assured by the autoconf script
         # enforcing that all directories have the group sticky bit set

=== modified file 'bin/update'
--- a/bin/update        2008-06-29 20:31:47 +0000
+++ b/bin/update        2008-11-13 04:02:29 +0000
@@ -34,7 +34,6 @@
 """
 
 import os
-import md5
 import sys
 import time
 import errno
@@ -131,7 +130,7 @@
             # No global template
             continue
 
-        gcksum = md5.new(fp.read()).digest()
+        gcksum = Utils.md5_new(fp.read()).digest()
         fp.close()
         # Match against the lists/<list>/* template
         try:
@@ -139,7 +138,7 @@
         except IOError, e:
             if e.errno <> errno.ENOENT: raise
         else:
-            tcksum = md5.new(fp.read()).digest()
+            tcksum = Utils.md5_new(fp.read()).digest()
             fp.close()
             if gcksum == tcksum:
                 os.unlink(os.path.join(mlist.fullpath(), gtemplate))
@@ -149,7 +148,7 @@
         except IOError, e:
             if e.errno <> errno.ENOENT: raise
         else:
-            tcksum = md5.new(fp.read()).digest()
+            tcksum = Utils.md5_new(fp.read()).digest()
             fp.close()
             if gcksum == tcksum:
                 os.unlink(os.path.join(mlist.fullpath(), gtemplate + '.prev'))
@@ -159,7 +158,7 @@
         except IOError, e:
             if e.errno <> errno.ENOENT: raise
         else:
-            tcksum = md5.new(fp.read()).digest()
+            tcksum = Utils.md5_new(fp.read()).digest()
             fp.close()
             if gcksum == tcksum:
                 os.unlink(os.path.join(mlist.fullpath(), 'en', gtemplate))
@@ -169,7 +168,7 @@
         except IOError, e:
             if e.errno <> errno.ENOENT: raise
         else:
-            tcksum = md5.new(fp.read()).digest()
+            tcksum = Utils.md5_new(fp.read()).digest()
             fp.close()
             if gcksum == tcksum:
                 os.unlink(os.path.join(mm_cfg.TEMPLATE_DIR, gtemplate))
@@ -179,7 +178,7 @@
         except IOError, e:
             if e.errno <> errno.ENOENT: raise
         else:
-            tcksum = md5.new(fp.read()).digest()
+            tcksum = Utils.md5_new(fp.read()).digest()
             fp.close()
             if gcksum == tcksum:
                 os.unlink(os.path.join(mm_cfg.TEMPLATE_DIR,

=== modified file 'tests/test_handlers.py'
--- a/tests/test_handlers.py    2005-08-27 01:40:17 +0000
+++ b/tests/test_handlers.py    2008-11-13 04:02:29 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2003 by the Free Software Foundation, Inc.
+# Copyright (C) 2001-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -12,13 +12,13 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
 
 """Unit tests for the various Mailman/Handlers/*.py modules.
 """
 
 import os
-import sha
 import time
 import email
 import errno
@@ -53,13 +53,14 @@
 from Mailman.Handlers import ToDigest
 from Mailman.Handlers import ToOutgoing
 from Mailman.Handlers import ToUsenet
+from Mailman.Utils import sha_new
 
 from TestBase import TestBase
 
 
 
 def password(plaintext):
-    return sha.new(plaintext).hexdigest()
+    return sha_new(plaintext).hexdigest()
 
 
 

=== modified file 'tests/test_security_mgr.py'
--- a/tests/test_security_mgr.py        2005-08-27 01:40:17 +0000
+++ b/tests/test_security_mgr.py        2008-11-13 04:02:29 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2003 by the Free Software Foundation, Inc.
+# Copyright (C) 2001-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -12,7 +12,8 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
 
 """Unit tests for Mailman/SecurityManager.py
 """
@@ -20,8 +21,6 @@
 import os
 import unittest
 import errno
-import md5
-import sha
 import Cookie
 try:
     import crypt
@@ -33,13 +32,14 @@
 from Mailman import mm_cfg
 from Mailman import Utils
 from Mailman import Errors
+from Mailman.Utils import md5_new, sha_new
 
 from TestBase import TestBase
 
 
 
 def password(plaintext):
-    return sha.new(plaintext).hexdigest()
+    return sha_new(plaintext).hexdigest()
 
 
 
@@ -132,7 +132,7 @@
     def test_list_admin_upgrade(self):
         eq = self.assertEqual
         mlist = self._mlist
-        mlist.password = md5.new('ssSSss').digest()
+        mlist.password = md5_new('ssSSss').digest()
         eq(mlist.Authenticate(
             [mm_cfg.AuthListAdmin], 'ssSSss'), mm_cfg.AuthListAdmin)
         eq(mlist.password, password('ssSSss'))
@@ -146,10 +146,10 @@
     def test_list_admin_oldstyle_unauth(self):
         eq = self.assertEqual
         mlist = self._mlist
-        mlist.password = md5.new('ssSSss').digest()
+        mlist.password = md5_new('ssSSss').digest()
         eq(mlist.Authenticate(
             [mm_cfg.AuthListAdmin], 'xxxxxx'), mm_cfg.UnAuthorized)
-        eq(mlist.password, md5.new('ssSSss').digest())
+        eq(mlist.password, md5_new('ssSSss').digest())
         # Test crypt upgrades if crypt is supported
         if crypt:
             mlist.password = crypted = crypt.crypt('rrRRrr', 'zc')



--
Stable, maintained release series
https://code.launchpad.net/~mailman-coders/mailman/2.1

You are receiving this branch notification because you are subscribed to it.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to