mirror of
https://github.com/sivel/speedtest-cli.git
synced 2026-10-01 01:01:19 +02:00
Use vendored create_connection when socket doesn't have it, or socket.create_connection is too old
This commit is contained in:
+12
-10
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user