Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit 9e185e8

Browse files
committed
Properly handle older HTTPSConnection. Fixes #513
1 parent 9c2977a commit 9e185e8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

speedtest.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,11 @@ class SpeedtestHTTPConnection(HTTPConnection):
389389
"""
390390
def __init__(self, *args, **kwargs):
391391
source_address = kwargs.pop('source_address', None)
392-
context = kwargs.pop('context', None)
393392
timeout = kwargs.pop('timeout', 10)
394393

395394
HTTPConnection.__init__(self, *args, **kwargs)
396395

397396
self.source_address = source_address
398-
self._context = context
399397
self.timeout = timeout
400398

401399
def connect(self):
@@ -420,6 +418,17 @@ class SpeedtestHTTPSConnection(HTTPSConnection,
420418
"""Custom HTTPSConnection to support source_address across
421419
Python 2.4 - Python 3
422420
"""
421+
def __init__(self, *args, **kwargs):
422+
source_address = kwargs.pop('source_address', None)
423+
context = kwargs.pop('context', None)
424+
timeout = kwargs.pop('timeout', 10)
425+
426+
HTTPSConnection.__init__(self, *args, **kwargs)
427+
428+
self.source_address = source_address
429+
self._context = context
430+
self.timeout = timeout
431+
423432
def connect(self):
424433
"Connect to a host on a given (SSL) port."
425434

@@ -428,8 +437,7 @@ def connect(self):
428437
kwargs = {}
429438
if hasattr(ssl, 'SSLContext'):
430439
kwargs['server_hostname'] = self.host
431-
432-
self.sock = self._context.wrap_socket(self.sock, **kwargs)
440+
self.sock = self._context.wrap_socket(self.sock, **kwargs)
433441

434442

435443
def _build_connection(connection, source_address, timeout, context=None):

0 commit comments

Comments
 (0)