diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-05-06 18:49:52 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-05-06 18:49:52 +0200 |
commit | 0872816dc1fbe0bf3b126874a31afd8e37677ae3 (patch) | |
tree | c8dd24551a19d141485ba306d0817d1a5a9ad696 /Lib/imaplib.py | |
parent | merge from 3.2 (diff) | |
download | cpython-0872816dc1fbe0bf3b126874a31afd8e37677ae3.tar.gz cpython-0872816dc1fbe0bf3b126874a31afd8e37677ae3.tar.bz2 cpython-0872816dc1fbe0bf3b126874a31afd8e37677ae3.zip |
Issue #8808: The IMAP4_SSL constructor now allows passing an SSLContext
parameter to control parameters of the secure channel. Patch by Sijin
Joseph.
Diffstat (limited to 'Lib/imaplib.py')
-rw-r--r-- | Lib/imaplib.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 1022e77c4f6..142e27bc87b 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -1177,25 +1177,40 @@ if HAVE_SSL: """IMAP4 client class over SSL connection - Instantiate with: IMAP4_SSL([host[, port[, keyfile[, certfile]]]]) + Instantiate with: IMAP4_SSL([host[, port[, keyfile[, certfile[, ssl_context]]]]]) host - host's name (default: localhost); - port - port number (default: standard IMAP4 SSL port). + port - port number (default: standard IMAP4 SSL port); keyfile - PEM formatted file that contains your private key (default: None); certfile - PEM formatted certificate chain file (default: None); + ssl_context - a SSLContext object that contains your certificate chain + and private key (default: None) + Note: if ssl_context is provided, then parameters keyfile or + certfile should not be set otherwise ValueError is thrown. for more documentation see the docstring of the parent class IMAP4. """ - def __init__(self, host = '', port = IMAP4_SSL_PORT, keyfile = None, certfile = None): + def __init__(self, host='', port=IMAP4_SSL_PORT, keyfile=None, certfile=None, ssl_context=None): + if ssl_context is not None and keyfile is not None: + raise ValueError("ssl_context and keyfile arguments are mutually " + "exclusive") + if ssl_context is not None and certfile is not None: + raise ValueError("ssl_context and certfile arguments are mutually " + "exclusive") + self.keyfile = keyfile self.certfile = certfile + self.ssl_context = ssl_context IMAP4.__init__(self, host, port) def _create_socket(self): sock = IMAP4._create_socket(self) - return ssl.wrap_socket(sock, self.keyfile, self.certfile) + if self.ssl_context: + return self.ssl_context.wrap_socket(sock) + else: + return ssl.wrap_socket(sock, self.keyfile, self.certfile) def open(self, host='', port=IMAP4_SSL_PORT): """Setup connection to remote server on "host:port". |