diff options
author | Matt Martz <matt@sivel.net> | 2018-05-22 15:28:00 -0500 |
---|---|---|
committer | Matt Martz <matt@sivel.net> | 2018-05-22 15:28:00 -0500 |
commit | 9e185e8f88db6f733f16b2bc41d6c5976394355e (patch) | |
tree | 15553312cd27984625e21d4d6c7aa5d9d3b744d2 | |
parent | 9c2977acfcfc782846fcecac2af39b9b50d43d48 (diff) |
Properly handle older HTTPSConnection. Fixes #513
-rwxr-xr-x | speedtest.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/speedtest.py b/speedtest.py index 0fe067b..d874adf 100755 --- a/speedtest.py +++ b/speedtest.py @@ -389,13 +389,11 @@ class SpeedtestHTTPConnection(HTTPConnection): """ def __init__(self, *args, **kwargs): source_address = kwargs.pop('source_address', None) - context = kwargs.pop('context', None) timeout = kwargs.pop('timeout', 10) HTTPConnection.__init__(self, *args, **kwargs) self.source_address = source_address - self._context = context self.timeout = timeout def connect(self): @@ -420,6 +418,17 @@ if HTTPSConnection: """Custom HTTPSConnection to support source_address across Python 2.4 - Python 3 """ + def __init__(self, *args, **kwargs): + source_address = kwargs.pop('source_address', None) + context = kwargs.pop('context', None) + timeout = kwargs.pop('timeout', 10) + + HTTPSConnection.__init__(self, *args, **kwargs) + + self.source_address = source_address + self._context = context + self.timeout = timeout + def connect(self): "Connect to a host on a given (SSL) port." @@ -428,8 +437,7 @@ if HTTPSConnection: kwargs = {} if hasattr(ssl, 'SSLContext'): kwargs['server_hostname'] = self.host - - self.sock = self._context.wrap_socket(self.sock, **kwargs) + self.sock = self._context.wrap_socket(self.sock, **kwargs) def _build_connection(connection, source_address, timeout, context=None): |