diff --git a/speedtest_cli.py b/speedtest_cli.py index 8abfea6..46d6c3c 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -44,19 +44,11 @@ except ImportError: # Begin import game to handle Python 2 and Python 3 try: - from urllib2 import urlopen, Request, HTTPError, URLError, HTTPErrorProcessor, build_opener + from urllib2 import urlopen, Request, HTTPError, URLError, \ + HTTPErrorProcessor, build_opener except ImportError: - from urllib.request import urlopen, Request, HTTPError, URLError, HTTPErrorProcessor, build_opener - - -class NoRedirection(HTTPErrorProcessor): - - def http_response(self, request, response): - return response - - https_response = http_response - - + from urllib.request import urlopen, Request, HTTPError, URLError, \ + HTTPErrorProcessor, build_opener try: from Queue import Queue @@ -175,6 +167,15 @@ def distance(origin, destination): return d +class NoRedirection(HTTPErrorProcessor): + """httplib class to ignore redirections""" + + def http_response(self, request, response): + return response + + https_response = http_response + + class FileGetter(threading.Thread): """Thread class for retrieving a URL""" @@ -448,7 +449,7 @@ def speedtest_auth(uid, pw): authlist = [] - noredir=build_opener(NoRedirection) + noredir = build_opener(NoRedirection) postData = urlencode({'email': uid, 'password': pw, 'action': 'login'})