Commits

Robert Brewer committed 6ead127

Backport of [2106] (Got rid of all the DeprecationWarning's when using Python 2.6).

Comments (0)

Files changed (4)

cherrypy/_cperror.py

         self.status = status = int(status)
         if status < 400 or status > 599:
             raise ValueError("status must be between 400 and 599.")
-        self.message = message
+        # See http://www.python.org/dev/peps/pep-0352/
+        # self.message = message
+        self._message = message
         CherryPyException.__init__(self, status, message)
     
     def set_response(self):
         response.headers['Content-Type'] = "text/html"
         
         content = self.get_error_page(self.status, traceback=tb,
-                                      message=self.message)
+                                      message=self._message)
         response.body = content
         response.headers['Content-Length'] = len(content)
         

cherrypy/lib/cptools.py

 """Functions for builtin CherryPy tools."""
 
 import logging
-import md5
+
+try:
+    # Python 2.5+
+    from hashlib import md5
+except ImportError:
+    from md5 import new as md5
+
 import re
 
 import cherrypy
     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

cherrypy/lib/httpauth.py

            "calculateNonce", "SUPPORTED_QOP")
 
 ################################################################################
-import md5
+
+try:
+    # Python 2.5+
+    from hashlib import md5
+except ImportError:
+    from md5 import new as md5
+
 import time
 import base64
 import urllib2
 # doAuth
 #
 DIGEST_AUTH_ENCODERS = {
-    MD5: lambda val: md5.new (val).hexdigest (),
-    MD5_SESS: lambda val: md5.new (val).hexdigest (),
-#    SHA: lambda val: sha.new (val).hexdigest (),
+    MD5: lambda val: md5(val).hexdigest(),
+    MD5_SESS: lambda val: md5(val).hexdigest(),
+#    SHA: lambda val: sha(val).hexdigest(),
 }
 
 def calculateNonce (realm, algorithm = MD5):

cherrypy/lib/sessions.py

 except ImportError:
     import pickle
 import random
-import sha
+
+try:
+    # Python 2.5+
+    from hashlib import sha1 as sha
+except ImportError:
+    from sha import new as sha
+
 import time
 import threading
 import types
         # os.urandom not available until Python 2.4. Fall back to random.random.
         def generate_id(self):
             """Return a new session id."""
-            return sha.new('%s' % random.random()).hexdigest()
+            return sha('%s' % random.random()).hexdigest()
     else:
         def generate_id(self):
             """Return a new session id."""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.