Use vendored create_connection when socket doesn't have it, or socket.create_connection is too old

This commit is contained in:
Matt Martz 2017-05-02 11:08:22 -05:00
parent 10b3b09f02
commit fe864f6dce
1 changed files with 12 additions and 10 deletions

View File

@ -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