From 54f92134aad6b6f4e45641ae32b170a054ebe260 Mon Sep 17 00:00:00 2001 From: SpotlightKid Date: Wed, 3 Sep 2014 23:54:49 +0200 Subject: [PATCH] Add tests and documentation updates for pull request #8 --- doc/src/conf.py | 5 ++++- imapclient/imapclient.py | 11 +++++++++++ imapclient/test/test_init.py | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/src/conf.py b/doc/src/conf.py index 7329c71..a50c1ca 100644 --- a/doc/src/conf.py +++ b/doc/src/conf.py @@ -17,7 +17,10 @@ import imapclient # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', + 'sphinx.ext.intersphinx'] + +intersphinx_mapping = {'python':('http://docs.python.org/3', None)} # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 5aef0f6..8288870 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -78,6 +78,17 @@ class IMAPClient(object): ``False``). This is useful for exotic connection or authentication setups. + Additional keyword arguments are passed to the constructor of the + :py:class:`imaplib.IMAP4` class, resp. :py:class:`imaplib.IMAP4_SSL` when + *ssl* is ``True``, which is used by ``IMAPClient`` internally. This allows + passing SSL related parameters, i.e. *keyfile* and *certfile* or an + :py:class:`ssl.SSLContext` instance with *ssl_context*. Please note that + some keyword arguments of the :py:class:`imaplib.IMP4_SSL` init method are + only supported in newer Python versions, in particular, the *ssl_context* + argument was added in Python 3.3. The class :py:class:`imaplib.IMAP4` (no + SSL) does not accept any additional keyword arguments. For details, see the + :py:mod:`imaplib` documentation in the standard library reference. + The *normalise_times* attribute specifies whether datetimes returned by ``fetch()`` are normalised to the local system time and include no timezone information (native), or are datetimes diff --git a/imapclient/test/test_init.py b/imapclient/test/test_init.py index 12061c8..e4b3ddf 100644 --- a/imapclient/test/test_init.py +++ b/imapclient/test/test_init.py @@ -40,6 +40,25 @@ class TestInit(unittest.TestCase): self.assertEqual(imap.ssl, True) self.assertEqual(imap.stream, False) + def test_SSL_kwargs(self): + self.imaplib.IMAP4_SSL.return_value = sentinel.IMAP4_SSL + + imap = IMAPClient('1.2.3.4', ssl=True, keyfile='key.pem', + certfile='cert.pem') + + self.assertEqual(imap._imap, sentinel.IMAP4_SSL) + self.imaplib.IMAP4_SSL.assert_called_with('1.2.3.4', 993, + keyfile='key.pem', certfile='cert.pem') + self.assertEqual(imap.ssl, True) + self.assertEqual(imap.stream, False) + + imap = IMAPClient('1.2.3.4', ssl=True, ssl_context=None) + self.imaplib.IMAP4_SSL.assert_called_with('1.2.3.4', 993, + ssl_context=None) + self.assertEqual(imap.ssl, True) + self.assertEqual(imap.stream, False) + + def test_stream(self): self.imaplib.IMAP4_stream.return_value = sentinel.IMAP4_stream -- 2.43.0