summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-03 17:32:25 (GMT)
committerGitHub <noreply@github.com>2022-11-03 17:32:25 (GMT)
commitef0e72b31d22f780d3a165d7d0471806061fe380 (patch)
treeb6c37400400dbca49c00466290a60122b6137ae9 /Lib/smtplib.py
parent9c4ae037b9c39312b792964497c090ce01570208 (diff)
downloadcpython-ef0e72b31d22f780d3a165d7d0471806061fe380.zip
cpython-ef0e72b31d22f780d3a165d7d0471806061fe380.tar.gz
cpython-ef0e72b31d22f780d3a165d7d0471806061fe380.tar.bz2
gh-94172: Remove keyfile, certfile and check_hostname parameters (#94173)
Remove the keyfile, certfile and check_hostname parameters, deprecated since Python 3.6, in modules: ftplib, http.client, imaplib, poplib and smtplib. Use the context parameter (ssl_context in imaplib) instead. Parameters following the removed parameters become keyword-only parameters. ftplib: Remove the FTP_TLS.ssl_version class attribute: use the context parameter instead.
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-xLib/smtplib.py42
1 files changed, 7 insertions, 35 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 324a1c1..05d2f8c 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -749,14 +749,14 @@ class SMTP:
# We could not login successfully. Return result of last attempt.
raise last_exception
- def starttls(self, keyfile=None, certfile=None, context=None):
+ def starttls(self, *, context=None):
"""Puts the connection to the SMTP server into TLS mode.
If there has been no previous EHLO or HELO command this session, this
method tries ESMTP EHLO first.
If the server supports TLS, this will encrypt the rest of the SMTP
- session. If you provide the keyfile and certfile parameters,
+ session. If you provide the context parameter,
the identity of the SMTP server and client can be checked. This,
however, depends on whether the socket module really checks the
certificates.
@@ -774,19 +774,8 @@ class SMTP:
if resp == 220:
if not _have_ssl:
raise RuntimeError("No SSL support included in this Python")
- if context is not None and keyfile is not None:
- raise ValueError("context and keyfile arguments are mutually "
- "exclusive")
- if context is not None and certfile is not None:
- raise ValueError("context and certfile arguments are mutually "
- "exclusive")
- if keyfile is not None or certfile is not None:
- import warnings
- warnings.warn("keyfile and certfile are deprecated, use a "
- "custom context instead", DeprecationWarning, 2)
if context is None:
- context = ssl._create_stdlib_context(certfile=certfile,
- keyfile=keyfile)
+ context = ssl._create_stdlib_context()
self.sock = context.wrap_socket(self.sock,
server_hostname=self._host)
self.file = None
@@ -1017,35 +1006,18 @@ if _have_ssl:
compiled with SSL support). If host is not specified, '' (the local
host) is used. If port is omitted, the standard SMTP-over-SSL port
(465) is used. local_hostname and source_address have the same meaning
- as they do in the SMTP class. keyfile and certfile are also optional -
- they can contain a PEM formatted private key and certificate chain file
- for the SSL connection. context also optional, can contain a
- SSLContext, and is an alternative to keyfile and certfile; If it is
- specified both keyfile and certfile must be None.
+ as they do in the SMTP class. context also optional, can contain a
+ SSLContext.
"""
default_port = SMTP_SSL_PORT
def __init__(self, host='', port=0, local_hostname=None,
- keyfile=None, certfile=None,
- timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
+ *, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None, context=None):
- if context is not None and keyfile is not None:
- raise ValueError("context and keyfile arguments are mutually "
- "exclusive")
- if context is not None and certfile is not None:
- raise ValueError("context and certfile arguments are mutually "
- "exclusive")
- if keyfile is not None or certfile is not None:
- import warnings
- warnings.warn("keyfile and certfile are deprecated, use a "
- "custom context instead", DeprecationWarning, 2)
- self.keyfile = keyfile
- self.certfile = certfile
if context is None:
- context = ssl._create_stdlib_context(certfile=certfile,
- keyfile=keyfile)
+ context = ssl._create_stdlib_context()
self.context = context
SMTP.__init__(self, host, port, local_hostname, timeout,
source_address)