1. cherrypy
  2. CherryPy


fs  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)

File cherrypy/filters/sessionfilter.py

View file
  • Ignore whitespace
 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 sha.new('%s' % random.random()).hexdigest()
+        return sha1('%s' % random.random()).hexdigest()
     def generate_session_id():
         """Return a new session id."""

File cherrypy/lib/cptools.py

View file
  • Ignore whitespace
 """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"' % md5.new(etag).hexdigest()
+            etag = '"%s"' % md5(etag).hexdigest()
             response.headers['ETag'] = etag
     response.ETag = etag