Commits

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

  • Participants
  • Parent commits 867475d
  • Branches cherrypy-2.x

Comments (0)

Files changed (2)

cherrypy/filters/sessionfilter.py

 except ImportError:
     import pickle
 import random
-import sha
+try:
+    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 sha.new('%s' % random.random()).hexdigest()
+        return sha1('%s' % random.random()).hexdigest()
 else:
     def generate_session_id():
         """Return a new session id."""

cherrypy/lib/cptools.py

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