From: Menno Smits Date: Wed, 17 Aug 2016 02:30:53 +0000 (+1200) Subject: Explicitly check that the required pyOpenSSL version is installed. X-Git-Tag: 1.0.2~8 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ea63ef489f3d7bac6ea08e27e0b8dad8373db95b;p=imapclient.git Explicitly check that the required pyOpenSSL version is installed. Closes #216. --HG-- branch : stable --- diff --git a/imapclient/tls.py b/imapclient/tls.py index 0144924..3611d73 100644 --- a/imapclient/tls.py +++ b/imapclient/tls.py @@ -14,6 +14,22 @@ import imaplib import socket import sys + +# Explicitly check that the required pyOpenSSL is installed. On some +# systems (particularly OS X) the system installed version will be +# seen before any user installed version. Using a virtualenv is +# recommended to work around this. +def check_pyopenssl_version(): + from distutils.version import LooseVersion as V + from OpenSSL import __version__ as installed_pyopenssl_version + from .version import min_pyopenssl_version + + if V(installed_pyopenssl_version) < V(min_pyopenssl_version): + raise ImportError("pyOpenSSL version (%s) is too old. Need at least %s." + % (installed_pyopenssl_version, min_pyopenssl_version)) + +check_pyopenssl_version() + try: from backports import ssl except ImportError: @@ -23,7 +39,6 @@ __all__ = ('create_default_context',) _ossl = ssl.ossl - if sys.platform == "win32": try: from ssl import enum_certificates, Purpose diff --git a/imapclient/version.py b/imapclient/version.py index 25fc818..0733a73 100644 --- a/imapclient/version.py +++ b/imapclient/version.py @@ -17,3 +17,5 @@ def _imapclient_version_string(vinfo): version = _imapclient_version_string(version_info) author = 'Menno Smits' author_email = 'menno@freshfoo.com' + +min_pyopenssl_version = '0.15.1' diff --git a/setup.py b/setup.py index d288e22..06834d0 100644 --- a/setup.py +++ b/setup.py @@ -66,7 +66,7 @@ class TestDiscoverCommand(TestCommand): main_deps = [ 'backports.ssl>=0.0.9', - 'pyopenssl>=0.15.1', + 'pyopenssl>=' + info["min_pyopenssl_version"], 'six', 'mock==1.3.0' ]