Use vendored create_connection when socket doesn't have it, or socket.create_connection is too old
This commit is contained in:
parent
10b3b09f02
commit
fe864f6dce
22
speedtest.py
22
speedtest.py
|
@ -373,18 +373,20 @@ class SpeedtestHTTPConnection(HTTPConnection):
|
|||
self._context = context
|
||||
self.timeout = timeout
|
||||
|
||||
try:
|
||||
self._create_connection = socket.create_connection
|
||||
except AttributeError:
|
||||
self._create_connection = create_connection
|
||||
|
||||
def connect(self):
|
||||
"""Connect to the host and port specified in __init__."""
|
||||
self.sock = self._create_connection(
|
||||
(self.host, self.port),
|
||||
self.timeout,
|
||||
self.source_address
|
||||
)
|
||||
try:
|
||||
self.sock = socket.create_connection(
|
||||
(self.host, self.port),
|
||||
self.timeout,
|
||||
self.source_address
|
||||
)
|
||||
except (AttributeError, TypeError):
|
||||
self.sock = create_connection(
|
||||
(self.host, self.port),
|
||||
self.timeout,
|
||||
self.source_address
|
||||
)
|
||||
|
||||
|
||||
if HTTPSConnection:
|
||||
|
|
Loading…
Reference in New Issue