summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2013-11-23 21:43:47 (GMT)
committerChristian Heimes <christian@cheimes.de>2013-11-23 21:43:47 (GMT)
commit67986f94311ffb46fe5b3efce74d749029041b73 (patch)
tree70aeabba17581022cb3dfcd1c9a59a284a0c1bca /Lib/smtplib.py
parent32eddc1bbc47479a3639b9191ffc82a52903c5f4 (diff)
downloadcpython-67986f94311ffb46fe5b3efce74d749029041b73.zip
cpython-67986f94311ffb46fe5b3efce74d749029041b73.tar.gz
cpython-67986f94311ffb46fe5b3efce74d749029041b73.tar.bz2
Issue #19735: Implement private function ssl._create_stdlib_context() to
create SSLContext objects in Python's stdlib module. It provides a single configuration point and makes use of SSLContext.load_default_certs().
Diffstat (limited to 'Lib/smtplib.py')
-rw-r--r--Lib/smtplib.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 69ae845..6fc65f6 100644
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -664,10 +664,10 @@ class SMTP:
if context is not None and certfile is not None:
raise ValueError("context and certfile arguments are mutually "
"exclusive")
- if context is not None:
- self.sock = context.wrap_socket(self.sock)
- else:
- self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
+ if context is None:
+ context = ssl._create_stdlib_context(certfile=certfile,
+ keyfile=keyfile)
+ self.sock = context.wrap_socket(self.sock)
self.file = None
# RFC 3207:
# The client MUST discard any knowledge obtained from
@@ -880,6 +880,9 @@ if _have_ssl:
"exclusive")
self.keyfile = keyfile
self.certfile = certfile
+ if context is None:
+ context = ssl._create_stdlib_context(certfile=certfile,
+ keyfile=keyfile)
self.context = context
SMTP.__init__(self, host, port, local_hostname, timeout,
source_address)
@@ -889,10 +892,7 @@ if _have_ssl:
print('connect:', (host, port), file=stderr)
new_socket = socket.create_connection((host, port), timeout,
self.source_address)
- if self.context is not None:
- new_socket = self.context.wrap_socket(new_socket)
- else:
- new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
+ new_socket = self.context.wrap_socket(new_socket)
return new_socket
__all__.append("SMTP_SSL")