Mercurial > hg
changeset 39025:569d662816de
mail: modernize check for Python-with-TLS
We used to be going indirectly through the socket module, but now we
just check for the ssl module.
Differential Revision: https://phab.mercurial-scm.org/D3955
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 16 Jul 2018 18:16:26 -0400 |
parents | eabdf3c25b8b |
children | a5e70c14214a |
files | mercurial/mail.py |
diffstat | 1 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/mail.py Mon Jul 16 17:49:17 2018 -0400 +++ b/mercurial/mail.py Mon Jul 16 18:16:26 2018 -0400 @@ -82,6 +82,15 @@ self.file = smtplib.SSLFakeFile(new_socket) return new_socket +def _pyhastls(): + """Returns true iff Python has TLS support, false otherwise.""" + try: + import ssl + getattr(ssl, 'HAS_TLS', False) + return True + except ImportError: + return False + def _smtp(ui): '''build an smtp connection and return a function to send mail''' local_hostname = ui.config('smtp', 'local_hostname') @@ -89,7 +98,7 @@ # backward compatible: when tls = true, we use starttls. starttls = tls == 'starttls' or stringutil.parsebool(tls) smtps = tls == 'smtps' - if (starttls or smtps) and not util.safehasattr(socket, 'ssl'): + if (starttls or smtps) and not _pyhastls(): raise error.Abort(_("can't use TLS: Python SSL support not installed")) mailhost = ui.config('smtp', 'host') if not mailhost: