summaryrefslogtreecommitdiffstats
path: root/Lib/ftplib.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/ftplib.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/ftplib.py')
-rw-r--r--Lib/ftplib.py17
1 files changed, 6 insertions, 11 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index 9538fec..1b16e0a 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -727,6 +727,10 @@ else:
"exclusive")
self.keyfile = keyfile
self.certfile = certfile
+ if context is None:
+ context = ssl._create_stdlib_context(self.ssl_version,
+ certfile=certfile,
+ keyfile=keyfile)
self.context = context
self._prot_p = False
FTP.__init__(self, host, user, passwd, acct, timeout, source_address)
@@ -744,12 +748,7 @@ else:
resp = self.voidcmd('AUTH TLS')
else:
resp = self.voidcmd('AUTH SSL')
- if self.context is not None:
- self.sock = self.context.wrap_socket(self.sock)
- else:
- self.sock = ssl.wrap_socket(self.sock, self.keyfile,
- self.certfile,
- ssl_version=self.ssl_version)
+ self.sock = self.context.wrap_socket(self.sock)
self.file = self.sock.makefile(mode='r', encoding=self.encoding)
return resp
@@ -788,11 +787,7 @@ else:
def ntransfercmd(self, cmd, rest=None):
conn, size = FTP.ntransfercmd(self, cmd, rest)
if self._prot_p:
- if self.context is not None:
- conn = self.context.wrap_socket(conn)
- else:
- conn = ssl.wrap_socket(conn, self.keyfile, self.certfile,
- ssl_version=self.ssl_version)
+ conn = self.context.wrap_socket(conn)
return conn, size
def abort(self):