Browse Source

Fixed a Python 2.6 deprecation warning on use of the "sha" module.

Mike Naberezny 15 years ago
parent
commit
2a0f8dc7c6
3 changed files with 13 additions and 10 deletions
  1. 2 0
      CHANGES.txt
  2. 6 2
      src/supervisor/http.py
  3. 5 8
      src/supervisor/tests/test_http.py

+ 2 - 0
CHANGES.txt

@@ -39,6 +39,8 @@ Next Release
   - Fixed a bug where the FCGI socket reference count was not getting 
     decremented on spawn error.  (Roger Hoover)
 
+  - Fixed a Python 2.6 deprecation warning on use of the "sha" module.
+
 3.0a7 (2009-05-24)
  
   - We now bundle our own patched version of Medusa contributed by Jason

+ 6 - 2
src/supervisor/http.py

@@ -21,6 +21,11 @@ import errno
 import pwd
 import urllib
 
+try:
+    from hashlib import sha1
+except ImportError:
+    from sha import new as sha1
+
 from supervisor.medusa import asyncore_25 as asyncore
 from supervisor.medusa import http_date
 from supervisor.medusa import http_server
@@ -850,8 +855,7 @@ class encrypted_dictionary_authorizer:
         if self.dict.has_key(username):
             stored_password = self.dict[username]
             if stored_password.startswith('{SHA}'):
-                import sha
-                password_hash = sha.new(password).hexdigest()
+                password_hash = sha1(password).hexdigest()
                 return stored_password[5:] == password_hash
             else:
                 return stored_password == password

+ 5 - 8
src/supervisor/tests/test_http.py

@@ -4,6 +4,11 @@ import socket
 import tempfile
 import unittest
 
+try:
+    from hashlib import sha1
+except ImportError:
+    from sha import new as sha1
+
 from supervisor.tests.base import DummySupervisor
 from supervisor.tests.base import PopulatedDummySupervisor
 from supervisor.tests.base import DummyRPCInterfaceFactory
@@ -271,19 +276,11 @@ class EncryptedDictionaryAuthorizedTests(unittest.TestCase):
         self.assertEqual(authorizer.authorize(('foo', 'password')), True)
     
     def test_authorize_gooduser_badpassword_sha(self):
-        try:
-            from hashlib import sha1
-        except ImportError:
-            from sha import new as sha1
         password = '{SHA}' + sha1('password').hexdigest()
         authorizer = self._makeOne({'foo':password})
         self.assertEqual(authorizer.authorize(('foo', 'bar')), False)
 
     def test_authorize_gooduser_goodpassword_sha(self):
-        try:
-            from hashlib import sha1
-        except ImportError:
-            from sha import new as sha1
         password = '{SHA}' + sha1('password').hexdigest()
         authorizer = self._makeOne({'foo':password})
         self.assertEqual(authorizer.authorize(('foo', 'password')), True)