diff mercurial/mail.py @ 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 dffe78d80a6c
children 31acc78c632a
line wrap: on
line diff
--- 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: