--- a/mercurial/url.py Sun Oct 06 09:45:02 2019 -0400
+++ b/mercurial/url.py Sun Oct 06 09:48:39 2019 -0400
@@ -71,26 +71,26 @@
res = httpconnectionmod.readauthforuri(self.ui, authuri, user)
if res:
group, auth = res
- user, passwd = auth.get('username'), auth.get('password')
- self.ui.debug("using auth.%s.* for authentication\n" % group)
+ user, passwd = auth.get(b'username'), auth.get(b'password')
+ self.ui.debug(b"using auth.%s.* for authentication\n" % group)
if not user or not passwd:
u = util.url(pycompat.bytesurl(authuri))
u.query = None
if not self.ui.interactive():
raise error.Abort(
- _('http authorization required for %s')
+ _(b'http authorization required for %s')
% util.hidepassword(bytes(u))
)
self.ui.write(
- _("http authorization required for %s\n")
+ _(b"http authorization required for %s\n")
% util.hidepassword(bytes(u))
)
- self.ui.write(_("realm: %s\n") % pycompat.bytesurl(realm))
+ self.ui.write(_(b"realm: %s\n") % pycompat.bytesurl(realm))
if user:
- self.ui.write(_("user: %s\n") % user)
+ self.ui.write(_(b"user: %s\n") % user)
else:
- user = self.ui.prompt(_("user:"), default=None)
+ user = self.ui.prompt(_(b"user:"), default=None)
if not passwd:
passwd = self.ui.getpass()
@@ -100,8 +100,8 @@
return (pycompat.strurl(user), pycompat.strurl(passwd))
def _writedebug(self, user, passwd):
- msg = _('http auth: user %s, password %s\n')
- self.ui.debug(msg % (user, passwd and '*' * len(passwd) or 'not set'))
+ msg = _(b'http auth: user %s, password %s\n')
+ self.ui.debug(msg % (user, passwd and b'*' * len(passwd) or b'not set'))
def find_stored_password(self, authuri):
return self.passwddb.find_user_password(None, authuri)
@@ -109,36 +109,36 @@
class proxyhandler(urlreq.proxyhandler):
def __init__(self, ui):
- proxyurl = ui.config("http_proxy", "host") or encoding.environ.get(
- 'http_proxy'
+ proxyurl = ui.config(b"http_proxy", b"host") or encoding.environ.get(
+ b'http_proxy'
)
# XXX proxyauthinfo = None
if proxyurl:
# proxy can be proper url or host[:port]
if not (
- proxyurl.startswith('http:') or proxyurl.startswith('https:')
+ proxyurl.startswith(b'http:') or proxyurl.startswith(b'https:')
):
- proxyurl = 'http://' + proxyurl + '/'
+ proxyurl = b'http://' + proxyurl + b'/'
proxy = util.url(proxyurl)
if not proxy.user:
- proxy.user = ui.config("http_proxy", "user")
- proxy.passwd = ui.config("http_proxy", "passwd")
+ proxy.user = ui.config(b"http_proxy", b"user")
+ proxy.passwd = ui.config(b"http_proxy", b"passwd")
# see if we should use a proxy for this url
- no_list = ["localhost", "127.0.0.1"]
+ no_list = [b"localhost", b"127.0.0.1"]
no_list.extend(
- [p.lower() for p in ui.configlist("http_proxy", "no")]
+ [p.lower() for p in ui.configlist(b"http_proxy", b"no")]
)
no_list.extend(
[
p.strip().lower()
- for p in encoding.environ.get("no_proxy", '').split(',')
+ for p in encoding.environ.get(b"no_proxy", b'').split(b',')
if p.strip()
]
)
# "http_proxy.always" config is for running tests on localhost
- if ui.configbool("http_proxy", "always"):
+ if ui.configbool(b"http_proxy", b"always"):
self.no_list = []
else:
self.no_list = no_list
@@ -147,7 +147,7 @@
# expects them to be.
proxyurl = str(proxy)
proxies = {r'http': proxyurl, r'https': proxyurl}
- ui.debug('proxying through %s\n' % util.hidepassword(bytes(proxy)))
+ ui.debug(b'proxying through %s\n' % util.hidepassword(bytes(proxy)))
else:
proxies = {}
@@ -155,13 +155,13 @@
self.ui = ui
def proxy_open(self, req, proxy, type_):
- host = pycompat.bytesurl(urllibcompat.gethost(req)).split(':')[0]
+ host = pycompat.bytesurl(urllibcompat.gethost(req)).split(b':')[0]
for e in self.no_list:
if host == e:
return None
- if e.startswith('*.') and host.endswith(e[2:]):
+ if e.startswith(b'*.') and host.endswith(e[2:]):
return None
- if e.startswith('.') and host.endswith(e[1:]):
+ if e.startswith(b'.') and host.endswith(e[1:]):
return None
return urlreq.proxyhandler.proxy_open(self, req, proxy, type_)
@@ -181,7 +181,7 @@
return _sendfile
-has_https = util.safehasattr(urlreq, 'httpshandler')
+has_https = util.safehasattr(urlreq, b'httpshandler')
class httpconnection(keepalive.HTTPConnection):
@@ -212,8 +212,8 @@
if new_tunnel or tunnel_host == urllibcompat.getfullurl(req): # has proxy
u = util.url(pycompat.bytesurl(tunnel_host))
- if new_tunnel or u.scheme == 'https': # only use CONNECT for HTTPS
- h.realhostport = ':'.join([u.host, (u.port or '443')])
+ 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.headers = req.headers.copy()
h.headers.update(handler.parent.addheaders)
return
@@ -230,10 +230,10 @@
if x.lower().startswith(r'proxy-')
]
)
- self.send('CONNECT %s HTTP/1.0\r\n' % self.realhostport)
+ self.send(b'CONNECT %s HTTP/1.0\r\n' % self.realhostport)
for header in proxyheaders.iteritems():
- self.send('%s: %s\r\n' % header)
- self.send('\r\n')
+ self.send(b'%s: %s\r\n' % header)
+ self.send(b'\r\n')
# majority of the following code is duplicated from
# httplib.HTTPConnection as there are no adequate places to
@@ -241,7 +241,7 @@
# strict was removed in Python 3.4.
kwargs = {}
if not pycompat.ispy3:
- kwargs['strict'] = self.strict
+ kwargs[b'strict'] = self.strict
res = self.response_class(self.sock, method=self._method, **kwargs)
@@ -250,20 +250,20 @@
if status != httplib.CONTINUE:
break
# skip lines that are all whitespace
- list(iter(lambda: res.fp.readline().strip(), ''))
+ list(iter(lambda: res.fp.readline().strip(), b''))
res.status = status
res.reason = reason.strip()
if res.status == 200:
# skip lines until we find a blank line
- list(iter(res.fp.readline, '\r\n'))
+ list(iter(res.fp.readline, b'\r\n'))
return True
- if version == 'HTTP/1.0':
+ if version == b'HTTP/1.0':
res.version = 10
- elif version.startswith('HTTP/1.'):
+ elif version.startswith(b'HTTP/1.'):
res.version = 11
- elif version == 'HTTP/0.9':
+ elif version == b'HTTP/0.9':
res.version = 9
else:
raise httplib.UnknownProtocol(version)
@@ -279,8 +279,8 @@
res.msg.fp = None
# are we using the chunked-style of transfer encoding?
- trenc = res.msg.getheader('transfer-encoding')
- if trenc and trenc.lower() == "chunked":
+ trenc = res.msg.getheader(b'transfer-encoding')
+ if trenc and trenc.lower() == b"chunked":
res.chunked = 1
res.chunk_left = None
else:
@@ -292,7 +292,7 @@
# do we have a Content-Length?
# NOTE: RFC 2616, section 4.4, #3 says we ignore this if
# transfer-encoding is "chunked"
- length = res.msg.getheader('content-length')
+ length = res.msg.getheader(b'content-length')
if length and not res.chunked:
try:
res.length = int(length)
@@ -309,7 +309,7 @@
status == httplib.NO_CONTENT
or status == httplib.NOT_MODIFIED
or 100 <= status < 200
- or res._method == 'HEAD' # 1xx codes
+ or res._method == b'HEAD' # 1xx codes
):
res.length = 0
@@ -403,7 +403,7 @@
host = self.host
if self.realhostport: # use CONNECT proxy
_generic_proxytunnel(self)
- host = self.realhostport.rsplit(':', 1)[0]
+ host = self.realhostport.rsplit(b':', 1)[0]
self.sock = sslutil.wrapsocket(
self.sock,
self.key_file,
@@ -433,7 +433,7 @@
if res:
group, auth = res
self.auth = auth
- self.ui.debug("using auth.%s.* for authentication\n" % group)
+ self.ui.debug(b"using auth.%s.* for authentication\n" % group)
else:
self.auth = None
return self.do_open(self._makeconnection, req)
@@ -450,9 +450,9 @@
# if the user has specified different key/cert files in
# hgrc, we prefer these
- if self.auth and 'key' in self.auth and 'cert' in self.auth:
- keyfile = self.auth['key']
- certfile = self.auth['cert']
+ if self.auth and b'key' in self.auth and b'cert' in self.auth:
+ keyfile = self.auth[b'key']
+ certfile = self.auth[b'cert']
conn = httpsconnection(
host, port, keyfile, certfile, *args, **kwargs
@@ -520,7 +520,7 @@
realm, urllibcompat.getfullurl(req)
)
if pw is not None:
- raw = "%s:%s" % (pycompat.bytesurl(user), pycompat.bytesurl(pw))
+ raw = b"%s:%s" % (pycompat.bytesurl(user), pycompat.bytesurl(pw))
auth = r'Basic %s' % pycompat.strurl(base64.b64encode(raw).strip())
if req.get_header(self.auth_header, None) == auth:
return None
@@ -535,7 +535,7 @@
def __init__(self, ui):
self.cookiejar = None
- cookiefile = ui.config('auth', 'cookiefile')
+ cookiefile = ui.config(b'auth', b'cookiefile')
if not cookiefile:
return
@@ -549,8 +549,8 @@
except util.cookielib.LoadError as e:
ui.warn(
_(
- '(error loading cookie file %s: %s; continuing without '
- 'cookies)\n'
+ b'(error loading cookie file %s: %s; continuing without '
+ b'cookies)\n'
)
% (cookiefile, stringutil.forcebytestr(e))
)
@@ -595,7 +595,7 @@
``sendaccept`` allows controlling whether the ``Accept`` request header
is sent. The header is sent by default.
'''
- timeout = ui.configwith(float, 'http', 'timeout')
+ timeout = ui.configwith(float, b'http', b'timeout')
handlers = []
if loggingfh:
@@ -621,8 +621,8 @@
if user != saveduser or passwd:
passmgr.add_password(realm, uris, user, passwd)
ui.debug(
- 'http auth: user %s, password %s\n'
- % (user, passwd and '*' * len(passwd) or 'not set')
+ b'http auth: user %s, password %s\n'
+ % (user, passwd and b'*' * len(passwd) or b'not set')
)
handlers.extend(
@@ -653,7 +653,7 @@
# The custom user agent is for lfs, because unfortunately some servers
# do look at this value.
if not useragent:
- agent = 'mercurial/proto-1.0 (Mercurial %s)' % util.version()
+ agent = b'mercurial/proto-1.0 (Mercurial %s)' % util.version()
opener.addheaders = [(r'User-agent', pycompat.sysstr(agent))]
else:
opener.addheaders = [(r'User-agent', pycompat.sysstr(useragent))]
@@ -675,7 +675,7 @@
url_, authinfo = u.authinfo()
else:
path = util.normpath(os.path.abspath(url_))
- url_ = 'file://' + pycompat.bytesurl(urlreq.pathname2url(path))
+ url_ = b'file://' + pycompat.bytesurl(urlreq.pathname2url(path))
authinfo = None
return opener(ui, authinfo, sendaccept=sendaccept).open(
pycompat.strurl(url_), data
@@ -700,27 +700,27 @@
got = len(e.partial)
total = e.expected + got
msg = _(
- 'HTTP request error (incomplete response; '
- 'expected %d bytes got %d)'
+ b'HTTP request error (incomplete response; '
+ b'expected %d bytes got %d)'
) % (total, got)
else:
- msg = _('HTTP request error (incomplete response)')
+ msg = _(b'HTTP request error (incomplete response)')
raise error.PeerTransportError(
msg,
hint=_(
- 'this may be an intermittent network failure; '
- 'if the error persists, consider contacting the '
- 'network or server operator'
+ b'this may be an intermittent network failure; '
+ b'if the error persists, consider contacting the '
+ b'network or server operator'
),
)
except httplib.HTTPException as e:
raise error.PeerTransportError(
- _('HTTP request error (%s)') % e,
+ _(b'HTTP request error (%s)') % e,
hint=_(
- 'this may be an intermittent network failure; '
- 'if the error persists, consider contacting the '
- 'network or server operator'
+ b'this may be an intermittent network failure; '
+ b'if the error persists, consider contacting the '
+ b'network or server operator'
),
)