Changeset View
Changeset View
Standalone View
Standalone View
mercurial/url.py
Show All 20 Lines | from . import ( | ||||
error, | error, | ||||
httpconnection as httpconnectionmod, | httpconnection as httpconnectionmod, | ||||
keepalive, | keepalive, | ||||
pycompat, | pycompat, | ||||
sslutil, | sslutil, | ||||
urllibcompat, | urllibcompat, | ||||
util, | util, | ||||
) | ) | ||||
from .utils import stringutil | from .utils import ( | ||||
stringutil, | |||||
urlutil, | |||||
) | |||||
httplib = util.httplib | httplib = util.httplib | ||||
stringio = util.stringio | stringio = util.stringio | ||||
urlerr = util.urlerr | urlerr = util.urlerr | ||||
urlreq = util.urlreq | urlreq = util.urlreq | ||||
def escape(s, quote=None): | def escape(s, quote=None): | ||||
Show All 32 Lines | def find_user_password(self, realm, authuri): | ||||
if not user or not passwd: | if not user or not passwd: | ||||
res = httpconnectionmod.readauthforuri(self.ui, authuri, user) | res = httpconnectionmod.readauthforuri(self.ui, authuri, user) | ||||
if res: | if res: | ||||
group, auth = res | group, auth = res | ||||
user, passwd = auth.get(b'username'), auth.get(b'password') | user, passwd = auth.get(b'username'), auth.get(b'password') | ||||
self.ui.debug(b"using auth.%s.* for authentication\n" % group) | self.ui.debug(b"using auth.%s.* for authentication\n" % group) | ||||
if not user or not passwd: | if not user or not passwd: | ||||
u = util.url(pycompat.bytesurl(authuri)) | u = urlutil.url(pycompat.bytesurl(authuri)) | ||||
u.query = None | u.query = None | ||||
if not self.ui.interactive(): | if not self.ui.interactive(): | ||||
raise error.Abort( | raise error.Abort( | ||||
_(b'http authorization required for %s') | _(b'http authorization required for %s') | ||||
% util.hidepassword(bytes(u)) | % urlutil.hidepassword(bytes(u)) | ||||
) | ) | ||||
self.ui.write( | self.ui.write( | ||||
_(b"http authorization required for %s\n") | _(b"http authorization required for %s\n") | ||||
% util.hidepassword(bytes(u)) | % urlutil.hidepassword(bytes(u)) | ||||
) | ) | ||||
self.ui.write(_(b"realm: %s\n") % pycompat.bytesurl(realm)) | self.ui.write(_(b"realm: %s\n") % pycompat.bytesurl(realm)) | ||||
if user: | if user: | ||||
self.ui.write(_(b"user: %s\n") % user) | self.ui.write(_(b"user: %s\n") % user) | ||||
else: | else: | ||||
user = self.ui.prompt(_(b"user:"), default=None) | user = self.ui.prompt(_(b"user:"), default=None) | ||||
if not passwd: | if not passwd: | ||||
Show All 26 Lines | def __init__(self, ui): | ||||
# XXX proxyauthinfo = None | # XXX proxyauthinfo = None | ||||
if proxyurl: | if proxyurl: | ||||
# proxy can be proper url or host[:port] | # proxy can be proper url or host[:port] | ||||
if not ( | if not ( | ||||
proxyurl.startswith(b'http:') or proxyurl.startswith(b'https:') | proxyurl.startswith(b'http:') or proxyurl.startswith(b'https:') | ||||
): | ): | ||||
proxyurl = b'http://' + proxyurl + b'/' | proxyurl = b'http://' + proxyurl + b'/' | ||||
proxy = util.url(proxyurl) | proxy = urlutil.url(proxyurl) | ||||
if not proxy.user: | if not proxy.user: | ||||
proxy.user = ui.config(b"http_proxy", b"user") | proxy.user = ui.config(b"http_proxy", b"user") | ||||
proxy.passwd = ui.config(b"http_proxy", b"passwd") | proxy.passwd = ui.config(b"http_proxy", b"passwd") | ||||
# see if we should use a proxy for this url | # see if we should use a proxy for this url | ||||
no_list = [b"localhost", b"127.0.0.1"] | no_list = [b"localhost", b"127.0.0.1"] | ||||
no_list.extend( | no_list.extend( | ||||
[p.lower() for p in ui.configlist(b"http_proxy", b"no")] | [p.lower() for p in ui.configlist(b"http_proxy", b"no")] | ||||
Show All 10 Lines | def __init__(self, ui): | ||||
self.no_list = [] | self.no_list = [] | ||||
else: | else: | ||||
self.no_list = no_list | self.no_list = no_list | ||||
# Keys and values need to be str because the standard library | # Keys and values need to be str because the standard library | ||||
# expects them to be. | # expects them to be. | ||||
proxyurl = str(proxy) | proxyurl = str(proxy) | ||||
proxies = {'http': proxyurl, 'https': proxyurl} | proxies = {'http': proxyurl, 'https': proxyurl} | ||||
ui.debug(b'proxying through %s\n' % util.hidepassword(bytes(proxy))) | ui.debug( | ||||
b'proxying through %s\n' % urlutil.hidepassword(bytes(proxy)) | |||||
) | |||||
else: | else: | ||||
proxies = {} | proxies = {} | ||||
urlreq.proxyhandler.__init__(self, proxies) | urlreq.proxyhandler.__init__(self, proxies) | ||||
self.ui = ui | self.ui = ui | ||||
def proxy_open(self, req, proxy, type_): | def proxy_open(self, req, proxy, type_): | ||||
host = pycompat.bytesurl(urllibcompat.gethost(req)).split(b':')[0] | host = pycompat.bytesurl(urllibcompat.gethost(req)).split(b':')[0] | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | if tunnel_host: | ||||
if tunnel_host[:7] not in ['http://', 'https:/']: | if tunnel_host[:7] not in ['http://', 'https:/']: | ||||
tunnel_host = 'https://' + tunnel_host | tunnel_host = 'https://' + tunnel_host | ||||
new_tunnel = True | new_tunnel = True | ||||
else: | else: | ||||
tunnel_host = urllibcompat.getselector(req) | tunnel_host = urllibcompat.getselector(req) | ||||
new_tunnel = False | new_tunnel = False | ||||
if new_tunnel or tunnel_host == urllibcompat.getfullurl(req): # has proxy | if new_tunnel or tunnel_host == urllibcompat.getfullurl(req): # has proxy | ||||
u = util.url(pycompat.bytesurl(tunnel_host)) | u = urlutil.url(pycompat.bytesurl(tunnel_host)) | ||||
if new_tunnel or u.scheme == b'https': # only use CONNECT for HTTPS | if new_tunnel or u.scheme == b'https': # only use CONNECT for HTTPS | ||||
h.realhostport = b':'.join([u.host, (u.port or b'443')]) | h.realhostport = b':'.join([u.host, (u.port or b'443')]) | ||||
h.headers = req.headers.copy() | h.headers = req.headers.copy() | ||||
h.headers.update(handler.parent.addheaders) | h.headers.update(handler.parent.addheaders) | ||||
return | return | ||||
h.realhostport = None | h.realhostport = None | ||||
h.headers = None | h.headers = None | ||||
▲ Show 20 Lines • Show All 439 Lines • ▼ Show 20 Line(s) | ): | ||||
# X-HgProto-<N> for advertising client support. | # X-HgProto-<N> for advertising client support. | ||||
if sendaccept: | if sendaccept: | ||||
opener.addheaders.append(('Accept', 'application/mercurial-0.1')) | opener.addheaders.append(('Accept', 'application/mercurial-0.1')) | ||||
return opener | return opener | ||||
def open(ui, url_, data=None, sendaccept=True): | def open(ui, url_, data=None, sendaccept=True): | ||||
u = util.url(url_) | u = urlutil.url(url_) | ||||
if u.scheme: | if u.scheme: | ||||
u.scheme = u.scheme.lower() | u.scheme = u.scheme.lower() | ||||
url_, authinfo = u.authinfo() | url_, authinfo = u.authinfo() | ||||
else: | else: | ||||
path = util.normpath(os.path.abspath(url_)) | path = util.normpath(os.path.abspath(url_)) | ||||
url_ = b'file://' + pycompat.bytesurl( | url_ = b'file://' + pycompat.bytesurl( | ||||
urlreq.pathname2url(pycompat.fsdecode(path)) | urlreq.pathname2url(pycompat.fsdecode(path)) | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |