Mercurial > public > mercurial-scm > hg
comparison mercurial/url.py @ 34466:1232f7fa00c3
cleanup: use urllibcompat for renamed methods on urllib request objects
Differential Revision: https://phab.mercurial-scm.org/D891
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 01 Oct 2017 12:14:21 -0400 |
parents | 0ee9cf8d054a |
children | 2976cf87a60a |
comparison
equal
deleted
inserted
replaced
34465:80d4681150b9 | 34466:1232f7fa00c3 |
---|---|
19 error, | 19 error, |
20 httpconnection as httpconnectionmod, | 20 httpconnection as httpconnectionmod, |
21 keepalive, | 21 keepalive, |
22 pycompat, | 22 pycompat, |
23 sslutil, | 23 sslutil, |
24 urllibcompat, | |
24 util, | 25 util, |
25 ) | 26 ) |
26 | 27 |
27 httplib = util.httplib | 28 httplib = util.httplib |
28 stringio = util.stringio | 29 stringio = util.stringio |
117 | 118 |
118 urlreq.proxyhandler.__init__(self, proxies) | 119 urlreq.proxyhandler.__init__(self, proxies) |
119 self.ui = ui | 120 self.ui = ui |
120 | 121 |
121 def proxy_open(self, req, proxy, type_): | 122 def proxy_open(self, req, proxy, type_): |
122 host = req.get_host().split(':')[0] | 123 host = urllibcompat.gethost(req).split(':')[0] |
123 for e in self.no_list: | 124 for e in self.no_list: |
124 if host == e: | 125 if host == e: |
125 return None | 126 return None |
126 if e.startswith('*.') and host.endswith(e[2:]): | 127 if e.startswith('*.') and host.endswith(e[2:]): |
127 return None | 128 return None |
164 if tunnel_host: | 165 if tunnel_host: |
165 if tunnel_host[:7] not in ['http://', 'https:/']: | 166 if tunnel_host[:7] not in ['http://', 'https:/']: |
166 tunnel_host = 'https://' + tunnel_host | 167 tunnel_host = 'https://' + tunnel_host |
167 new_tunnel = True | 168 new_tunnel = True |
168 else: | 169 else: |
169 tunnel_host = req.get_selector() | 170 tunnel_host = urllibcompat.getselector(req) |
170 new_tunnel = False | 171 new_tunnel = False |
171 | 172 |
172 if new_tunnel or tunnel_host == req.get_full_url(): # has proxy | 173 if new_tunnel or tunnel_host == urllibcompat.getfullurl(req): # has proxy |
173 u = util.url(tunnel_host) | 174 u = util.url(tunnel_host) |
174 if new_tunnel or u.scheme == 'https': # only use CONNECT for HTTPS | 175 if new_tunnel or u.scheme == 'https': # only use CONNECT for HTTPS |
175 h.realhostport = ':'.join([u.host, (u.port or '443')]) | 176 h.realhostport = ':'.join([u.host, (u.port or '443')]) |
176 h.headers = req.headers.copy() | 177 h.headers = req.headers.copy() |
177 h.headers.update(handler.parent.addheaders) | 178 h.headers.update(handler.parent.addheaders) |
318 def _start_transaction(self, h, req): | 319 def _start_transaction(self, h, req): |
319 _generic_start_transaction(self, h, req) | 320 _generic_start_transaction(self, h, req) |
320 return keepalive.KeepAliveHandler._start_transaction(self, h, req) | 321 return keepalive.KeepAliveHandler._start_transaction(self, h, req) |
321 | 322 |
322 def https_open(self, req): | 323 def https_open(self, req): |
323 # req.get_full_url() does not contain credentials and we may | 324 # urllibcompat.getfullurl() does not contain credentials |
324 # need them to match the certificates. | 325 # and we may need them to match the certificates. |
325 url = req.get_full_url() | 326 url = urllibcompat.getfullurl(req) |
326 user, password = self.pwmgr.find_stored_password(url) | 327 user, password = self.pwmgr.find_stored_password(url) |
327 res = httpconnectionmod.readauthforuri(self.ui, url, user) | 328 res = httpconnectionmod.readauthforuri(self.ui, url, user) |
328 if res: | 329 if res: |
329 group, auth = res | 330 group, auth = res |
330 self.auth = auth | 331 self.auth = auth |
404 self.retried = 0 | 405 self.retried = 0 |
405 return urlreq.httpbasicauthhandler.http_error_auth_reqed( | 406 return urlreq.httpbasicauthhandler.http_error_auth_reqed( |
406 self, auth_header, host, req, headers) | 407 self, auth_header, host, req, headers) |
407 | 408 |
408 def retry_http_basic_auth(self, host, req, realm): | 409 def retry_http_basic_auth(self, host, req, realm): |
409 user, pw = self.passwd.find_user_password(realm, req.get_full_url()) | 410 user, pw = self.passwd.find_user_password( |
411 realm, urllibcompat.getfullurl(req)) | |
410 if pw is not None: | 412 if pw is not None: |
411 raw = "%s:%s" % (user, pw) | 413 raw = "%s:%s" % (user, pw) |
412 auth = 'Basic %s' % base64.b64encode(raw).strip() | 414 auth = 'Basic %s' % base64.b64encode(raw).strip() |
413 if req.get_header(self.auth_header, None) == auth: | 415 if req.get_header(self.auth_header, None) == auth: |
414 return None | 416 return None |