Show More
@@ -8,6 +8,7 b'' | |||||
8 | # GNU General Public License version 2 or any later version. |
|
8 | # GNU General Public License version 2 or any later version. | |
9 |
|
9 | |||
10 | import urllib, urllib2, httplib, os, socket, cStringIO |
|
10 | import urllib, urllib2, httplib, os, socket, cStringIO | |
|
11 | import base64 | |||
11 | from i18n import _ |
|
12 | from i18n import _ | |
12 | import keepalive, util, sslutil |
|
13 | import keepalive, util, sslutil | |
13 | import httpconnection as httpconnectionmod |
|
14 | import httpconnection as httpconnectionmod | |
@@ -418,9 +419,22 b' class httpdigestauthhandler(urllib2.HTTP' | |||||
418 |
|
419 | |||
419 | class httpbasicauthhandler(urllib2.HTTPBasicAuthHandler): |
|
420 | class httpbasicauthhandler(urllib2.HTTPBasicAuthHandler): | |
420 | def __init__(self, *args, **kwargs): |
|
421 | def __init__(self, *args, **kwargs): | |
|
422 | self.auth = None | |||
421 | urllib2.HTTPBasicAuthHandler.__init__(self, *args, **kwargs) |
|
423 | urllib2.HTTPBasicAuthHandler.__init__(self, *args, **kwargs) | |
422 | self.retried_req = None |
|
424 | self.retried_req = None | |
423 |
|
425 | |||
|
426 | def http_request(self, request): | |||
|
427 | if self.auth: | |||
|
428 | request.add_unredirected_header(self.auth_header, self.auth) | |||
|
429 | ||||
|
430 | return request | |||
|
431 | ||||
|
432 | def https_request(self, request): | |||
|
433 | if self.auth: | |||
|
434 | request.add_unredirected_header(self.auth_header, self.auth) | |||
|
435 | ||||
|
436 | return request | |||
|
437 | ||||
424 | def reset_retry_count(self): |
|
438 | def reset_retry_count(self): | |
425 | # Python 2.6.5 will call this on 401 or 407 errors and thus loop |
|
439 | # Python 2.6.5 will call this on 401 or 407 errors and thus loop | |
426 | # forever. We disable reset_retry_count completely and reset in |
|
440 | # forever. We disable reset_retry_count completely and reset in | |
@@ -435,6 +449,19 b' class httpbasicauthhandler(urllib2.HTTPB' | |||||
435 | return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed( |
|
449 | return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed( | |
436 | self, auth_header, host, req, headers) |
|
450 | self, auth_header, host, req, headers) | |
437 |
|
451 | |||
|
452 | def retry_http_basic_auth(self, host, req, realm): | |||
|
453 | user, pw = self.passwd.find_user_password(realm, host) | |||
|
454 | if pw is not None: | |||
|
455 | raw = "%s:%s" % (user, pw) | |||
|
456 | auth = 'Basic %s' % base64.b64encode(raw).strip() | |||
|
457 | if req.headers.get(self.auth_header, None) == auth: | |||
|
458 | return None | |||
|
459 | self.auth = auth | |||
|
460 | req.add_unredirected_header(self.auth_header, auth) | |||
|
461 | return self.parent.open(req, timeout=req.timeout) | |||
|
462 | else: | |||
|
463 | return None | |||
|
464 | ||||
438 | handlerfuncs = [] |
|
465 | handlerfuncs = [] | |
439 |
|
466 | |||
440 | def opener(ui, authinfo=None): |
|
467 | def opener(ui, authinfo=None): |
General Comments 0
You need to be logged in to leave comments.
Login now