summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-12-19 23:18:17 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-12-19 23:18:17 -0500
commite83370460e245ea8d68a06feed459043c035569c (patch)
tree908db7f72ba5b6b6bef5b3a6cea6c4be00d9597e
parent4b5473e43731bb3978bc77d1a87e7ca5ad968443 (diff)
downloadcherrypy-e83370460e245ea8d68a06feed459043c035569c.tar.gz
Replace usage of md5 and sha with canonical imports
-rw-r--r--cherrypy/_cpcompat.py25
-rw-r--r--cherrypy/lib/auth_digest.py3
-rw-r--r--cherrypy/lib/cptools.py3
-rw-r--r--cherrypy/lib/httpauth.py4
-rw-r--r--cherrypy/test/test_auth_basic.py4
-rw-r--r--cherrypy/test/test_httpauth.py8
6 files changed, 18 insertions, 29 deletions
diff --git a/cherrypy/_cpcompat.py b/cherrypy/_cpcompat.py
index 8a98b38b..57c2f5c3 100644
--- a/cherrypy/_cpcompat.py
+++ b/cherrypy/_cpcompat.py
@@ -137,17 +137,6 @@ def base64_decode(n, encoding='ISO-8859-1'):
else:
return b
-try:
- # Python 2.5+
- from hashlib import md5
-except ImportError:
- from md5 import new as md5
-
-try:
- # Python 2.5+
- from hashlib import sha1 as sha
-except ImportError:
- from sha import new as sha
try:
sorted = sorted
@@ -333,18 +322,10 @@ except ImportError:
# In Python 3, pickle is the sped-up C version.
import pickle
-try:
- os.urandom(20)
- import binascii
-
- def random20():
- return binascii.hexlify(os.urandom(20)).decode('ascii')
-except (AttributeError, NotImplementedError):
- import random
- # os.urandom not available until Python 2.4. Fall back to random.random.
+import binascii
- def random20():
- return sha('%s' % random.random()).hexdigest()
+def random20():
+ return binascii.hexlify(os.urandom(20)).decode('ascii')
try:
from _thread import get_ident as get_thread_ident
diff --git a/cherrypy/lib/auth_digest.py b/cherrypy/lib/auth_digest.py
index e06535dc..e833ff77 100644
--- a/cherrypy/lib/auth_digest.py
+++ b/cherrypy/lib/auth_digest.py
@@ -23,10 +23,11 @@ __date__ = 'April 2009'
import time
+from hashlib import md5
from cherrypy._cpcompat import parse_http_list, parse_keqv_list
import cherrypy
-from cherrypy._cpcompat import md5, ntob
+from cherrypy._cpcompat import ntob
md5_hex = lambda s: md5(ntob(s)).hexdigest()
qop_auth = 'auth'
diff --git a/cherrypy/lib/cptools.py b/cherrypy/lib/cptools.py
index f376282c..601b44bc 100644
--- a/cherrypy/lib/cptools.py
+++ b/cherrypy/lib/cptools.py
@@ -2,9 +2,10 @@
import logging
import re
+from hashlib import md5
import cherrypy
-from cherrypy._cpcompat import basestring, md5, set, unicodestr
+from cherrypy._cpcompat import basestring, set, unicodestr
from cherrypy.lib import httputil as _httputil
from cherrypy.lib import is_iterator
diff --git a/cherrypy/lib/httpauth.py b/cherrypy/lib/httpauth.py
index 0897ea2a..6d519907 100644
--- a/cherrypy/lib/httpauth.py
+++ b/cherrypy/lib/httpauth.py
@@ -62,7 +62,9 @@ __all__ = ("digestAuth", "basicAuth", "doAuth", "checkResponse",
##########################################################################
import time
-from cherrypy._cpcompat import base64_decode, ntob, md5
+from hashlib import md5
+
+from cherrypy._cpcompat import base64_decode, ntob
from cherrypy._cpcompat import parse_http_list, parse_keqv_list
MD5 = "MD5"
diff --git a/cherrypy/test/test_auth_basic.py b/cherrypy/test/test_auth_basic.py
index 7ba11dfc..d03b1321 100644
--- a/cherrypy/test/test_auth_basic.py
+++ b/cherrypy/test/test_auth_basic.py
@@ -2,8 +2,10 @@
# -*- coding: utf-8 -*-
# vim:ts=4:sw=4:expandtab:fileencoding=utf-8
+from hashlib import md5
+
import cherrypy
-from cherrypy._cpcompat import md5, ntob
+from cherrypy._cpcompat import ntob
from cherrypy.lib import auth_basic
from cherrypy.test import helper
diff --git a/cherrypy/test/test_httpauth.py b/cherrypy/test/test_httpauth.py
index 98a300f0..8be48b6b 100644
--- a/cherrypy/test/test_httpauth.py
+++ b/cherrypy/test/test_httpauth.py
@@ -1,5 +1,7 @@
+from hashlib import md5, sha1
+
import cherrypy
-from cherrypy._cpcompat import md5, sha, ntob
+from cherrypy._cpcompat import ntob
from cherrypy.lib import httpauth
from cherrypy.test import helper
@@ -39,10 +41,10 @@ class HTTPAuthTest(helper.CPWebCase):
return {'test': 'test'}
def sha_password_encrypter(password):
- return sha(ntob(password)).hexdigest()
+ return sha1(ntob(password)).hexdigest()
def fetch_password(username):
- return sha(ntob('test')).hexdigest()
+ return sha1(ntob('test')).hexdigest()
conf = {
'/digest': {