aboutsummaryrefslogtreecommitdiff
path: root/requests/auth.py
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:41:22 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:41:22 -0700
commit3a4ef8165fb2951781a7bcc4189e90faf26caf2d (patch)
tree5223d80835a57dad6b7b6e0c37f689441ccb4e1e /requests/auth.py
parent40337989ba5056432c9f2af3c42267e5ee9e3e18 (diff)
downloadpython-requests-3a4ef8165fb2951781a7bcc4189e90faf26caf2d.tar
python-requests-3a4ef8165fb2951781a7bcc4189e90faf26caf2d.tar.gz
Imported Upstream version 0.11.2
Diffstat (limited to 'requests/auth.py')
-rw-r--r--requests/auth.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/requests/auth.py b/requests/auth.py
index 385dd27..353180a 100644
--- a/requests/auth.py
+++ b/requests/auth.py
@@ -56,6 +56,8 @@ class HTTPDigestAuth(AuthBase):
def handle_401(self, r):
"""Takes the given response and tries digest-auth, if needed."""
+ r.request.deregister_hook('response', self.handle_401)
+
s_auth = r.headers.get('www-authenticate', '')
if 'digest' in s_auth.lower():
@@ -74,21 +76,21 @@ class HTTPDigestAuth(AuthBase):
algorithm = algorithm.upper()
# lambdas assume digest modules are imported at the top level
if algorithm == 'MD5':
- def h(x):
+ def md5_utf8(x):
if isinstance(x, str):
x = x.encode('utf-8')
return hashlib.md5(x).hexdigest()
- H = h
+ hash_utf8 = md5_utf8
elif algorithm == 'SHA':
- def h(x):
+ def sha_utf8(x):
if isinstance(x, str):
x = x.encode('utf-8')
return hashlib.sha1(x).hexdigest()
- H = h
+ hash_utf8 = sha_utf8
# XXX MD5-sess
- KD = lambda s, d: H("%s:%s" % (s, d))
+ KD = lambda s, d: hash_utf8("%s:%s" % (s, d))
- if H is None:
+ if hash_utf8 is None:
return None
# XXX not implemented yet
@@ -115,10 +117,10 @@ class HTTPDigestAuth(AuthBase):
s += randombytes(8)
cnonce = (hashlib.sha1(s).hexdigest()[:16])
- noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, H(A2))
- respdig = KD(H(A1), noncebit)
+ noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, hash_utf8(A2))
+ respdig = KD(hash_utf8(A1), noncebit)
elif qop is None:
- respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))
+ respdig = KD(hash_utf8(A1), "%s:%s" % (nonce, hash_utf8(A2)))
else:
# XXX handle auth-int.
return None