Anonymous committed 99b3b00

remove DeprecationWarnings on Python 2.6+ by importing hashlib first (instead of the md5/sha modules)

Patch by Toshio Kuratomi, imported from Fedora CVS, licensed under the same terms as CherryPy 2.3

Comments (0)

Files changed (2)


 except ImportError:
     import pickle
 import random
-import sha
+    from hashlib import sha1
+except ImportError:
+    from sha import new as sha1
 import time
 import thread
 import threading
     # os.urandom not available until Python 2.4. Fall back to random.random.
     def generate_session_id():
         """Return a new session id."""
-        return'%s' % random.random()).hexdigest()
+        return sha1('%s' % random.random()).hexdigest()
     def generate_session_id():
         """Return a new session id."""


 """Tools which both CherryPy and application developers may invoke."""
-import md5
+    from hashlib import md5
+except ImportError:
+    from md5 import new as md5
 import mimetools
 import mimetypes
     if (not etag) and autotags:
         if status == 200:
             etag = response.collapse_body()
-            etag = '"%s"' %
+            etag = '"%s"' % md5(etag).hexdigest()
             response.headers['ETag'] = etag
     response.ETag = etag