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
14
speedtest.py
14
speedtest.py
|
@ -373,14 +373,16 @@ 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(
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue