MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / SmartHTTPBasicAuthHandler

Class SmartHTTPBasicAuthHandler

lib/request/basicauthhandler.py:10–38  ·  view source on GitHub ↗

Reference: http://selenic.com/hg/rev/6c51a5056020 Fix for a: http://bugs.python.org/issue8797

Source from the content-addressed store, hash-verified

8from thirdparty.six.moves import urllib as _urllib
9
10class SmartHTTPBasicAuthHandler(_urllib.request.HTTPBasicAuthHandler):
11 """
12 Reference: http://selenic.com/hg/rev/6c51a5056020
13 Fix for a: http://bugs.python.org/issue8797
14 """
15
16 def __init__(self, *args, **kwargs):
17 _urllib.request.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
18 self.retried_req = set()
19 self.retried_count = 0
20
21 def reset_retry_count(self):
22 # Python 2.6.5 will call this on 401 or 407 errors and thus loop
23 # forever. We disable reset_retry_count completely and reset in
24 # http_error_auth_reqed instead.
25 pass
26
27 def http_error_auth_reqed(self, auth_header, host, req, headers):
28 # Reset the retry counter once for each request.
29 if hash(req) not in self.retried_req:
30 self.retried_req.add(hash(req))
31 self.retried_count = 0
32 else:
33 if self.retried_count > 5:
34 raise _urllib.error.HTTPError(req.get_full_url(), 401, "basic auth failed", headers, None)
35 else:
36 self.retried_count += 1
37
38 return _urllib.request.HTTPBasicAuthHandler.http_error_auth_reqed(self, auth_header, host, req, headers)

Callers 1

_setHTTPAuthenticationFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…