Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(204)

Unified Diff: Lib/smtplib.py

Issue 19689: ssl.create_default_context()
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/poplib.py ('k') | Lib/ssl.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/smtplib.py Fri Nov 22 16:20:53 2013 +0100
+++ b/Lib/smtplib.py Fri Nov 22 18:04:20 2013 +0100
@@ -664,10 +664,10 @@
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_default_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 @@
"exclusive")
self.keyfile = keyfile
self.certfile = certfile
+ if context is None:
+ context = ssl.create_default_context(certfile=self.certfile,
+ keyfile=self.keyfile)
self.context = context
SMTP.__init__(self, host, port, local_hostname, timeout,
source_address)
@@ -889,10 +892,7 @@
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")
« no previous file with comments | « Lib/poplib.py ('k') | Lib/ssl.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+