Mercurial > hg
changeset 29248:e6de6ef3e426
sslutil: remove ui from sslkwargs (API)
Arguments to sslutil.wrapsocket() are partially determined by
calling sslutil.sslkwargs(). This function receives a ui and
a hostname and determines what settings, if any, need to be
applied when the socket is wrapped.
Both the ui and hostname are passed into wrapsocket(). The
other arguments to wrapsocket() provided by sslkwargs() (ca_certs
and cert_reqs) are not looked at or modified anywhere outside
of sslutil.py. So, sslkwargs() doesn't need to exist as a
separate public API called before wrapsocket().
This commit starts the process of removing external consumers of
sslkwargs() by removing the "ui" key/argument from its return.
All callers now pass the ui argument explicitly.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 25 May 2016 19:43:22 -0700 |
parents | 3e438497edca |
children | cca59ef27e60 |
files | mercurial/httpconnection.py mercurial/mail.py mercurial/sslutil.py mercurial/url.py |
diffstat | 4 files changed, 15 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/httpconnection.py Wed May 25 16:09:07 2016 -0700 +++ b/mercurial/httpconnection.py Wed May 25 19:43:22 2016 -0700 @@ -285,5 +285,6 @@ con = HTTPConnection(host, port, use_ssl=True, ssl_wrap_socket=sslutil.wrapsocket, ssl_validator=sslutil.validatesocket, + ui=self.ui, **kwargs) return con
--- a/mercurial/mail.py Wed May 25 16:09:07 2016 -0700 +++ b/mercurial/mail.py Wed May 25 19:43:22 2016 -0700 @@ -48,8 +48,9 @@ This class allows to pass any keyword arguments to SSL socket creation. ''' - def __init__(self, sslkwargs, host=None, **kwargs): + def __init__(self, ui, sslkwargs, host=None, **kwargs): smtplib.SMTP.__init__(self, **kwargs) + self._ui = ui self._sslkwargs = sslkwargs self._host = host @@ -60,6 +61,7 @@ (resp, reply) = self.docmd("STARTTLS") if resp == 220: self.sock = sslutil.wrapsocket(self.sock, keyfile, certfile, + ui=self._ui, serverhostname=self._host, **self._sslkwargs) self.file = smtplib.SSLFakeFile(self.sock) @@ -74,13 +76,14 @@ This class allows to pass any keyword arguments to SSL socket creation. ''' - def __init__(self, sslkwargs, keyfile=None, certfile=None, host=None, + def __init__(self, ui, sslkwargs, keyfile=None, certfile=None, host=None, **kwargs): self.keyfile = keyfile self.certfile = certfile smtplib.SMTP.__init__(self, **kwargs) self._host = host self.default_port = smtplib.SMTP_SSL_PORT + self._ui = ui self._sslkwargs = sslkwargs def _get_socket(self, host, port, timeout): @@ -89,6 +92,7 @@ new_socket = socket.create_connection((host, port), timeout) new_socket = sslutil.wrapsocket(new_socket, self.keyfile, self.certfile, + ui=self._ui, serverhostname=self._host, **self._sslkwargs) self.file = smtplib.SSLFakeFile(new_socket) @@ -115,13 +119,14 @@ if (starttls or smtps) and verifycert: sslkwargs = sslutil.sslkwargs(ui, mailhost) else: - # 'ui' is required by sslutil.wrapsocket() and set by sslkwargs() - sslkwargs = {'ui': ui} + sslkwargs = {} + if smtps: ui.note(_('(using smtps)\n')) - s = SMTPS(sslkwargs, local_hostname=local_hostname, host=mailhost) + s = SMTPS(ui, sslkwargs, local_hostname=local_hostname, host=mailhost) elif starttls: - s = STARTTLS(sslkwargs, local_hostname=local_hostname, host=mailhost) + s = STARTTLS(ui, sslkwargs, local_hostname=local_hostname, + host=mailhost) else: s = smtplib.SMTP(local_hostname=local_hostname) if smtps:
--- a/mercurial/sslutil.py Wed May 25 16:09:07 2016 -0700 +++ b/mercurial/sslutil.py Wed May 25 19:43:22 2016 -0700 @@ -247,7 +247,7 @@ ``host`` is the hostname being connected to. """ - kws = {'ui': ui} + kws = {} # If a host key fingerprint is on file, it is the only thing that matters # and CA certs don't come into play.
--- a/mercurial/url.py Wed May 25 16:09:07 2016 -0700 +++ b/mercurial/url.py Wed May 25 19:43:22 2016 -0700 @@ -354,8 +354,8 @@ _generic_proxytunnel(self) host = self.realhostport.rsplit(':', 1)[0] self.sock = sslutil.wrapsocket( - self.sock, self.key_file, self.cert_file, serverhostname=host, - **sslutil.sslkwargs(self.ui, host)) + self.sock, self.key_file, self.cert_file, ui=self.ui, + serverhostname=host, **sslutil.sslkwargs(self.ui, host)) sslutil.validatesocket(self.sock) class httpshandler(keepalive.KeepAliveHandler, urlreq.httpshandler):