From 95fe03875220a6f3caa631c23a633ed7a54e2a56 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 7 Mar 2016 17:02:11 -0600 Subject: [PATCH] Handle HTTPSConnection imports differently, don't bail unless we need it --- speedtest.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/speedtest.py b/speedtest.py index e5bd1c3..23c7ad5 100755 --- a/speedtest.py +++ b/speedtest.py @@ -81,17 +81,17 @@ except ImportError: from urllib.request import urlopen, Request, HTTPError, URLError try: - from httplib import HTTPConnection, HTTPSConnection + from httplib import HTTPConnection +except ImportError: + from http.client import HTTPConnection + +try: + from httplib import HTTPSConnection except ImportError: - e_http_py2 = sys.exc_info() try: - from http.client import HTTPConnection, HTTPSConnection + from http.client import HTTPSConnection except ImportError: - e_http_py3 = sys.exc_info() - raise SystemExit('Your python installation is missing required HTTP ' - 'client classes:\n\n' - 'Python 2: %s\n' - 'Python 3: %s' % (e_http_py2[1], e_http_py3[1])) + HTTPSConnection = None try: from Queue import Queue @@ -1148,12 +1148,13 @@ def validate_optional_args(args): with an error stating which module is missing. """ optional_args = { - 'json': ('json/simplejson', json), + 'json': ('json/simplejson python module', json), + 'secure': ('SSL support', HTTPSConnection), } for arg, info in optional_args.items(): if getattr(args, arg, False) and info[1] is None: - raise SystemExit('%s python module is not installed. --%s is ' + raise SystemExit('%s is not installed. --%s is ' 'unavailable' % (info[0], arg))