|
36 | 36 | gzip = None |
37 | 37 | GZIP_BASE = object |
38 | 38 |
|
39 | | -__version__ = '2.0.1' |
| 39 | +__version__ = '2.0.2a' |
40 | 40 |
|
41 | 41 |
|
42 | 42 | class FakeShutdownEvent(object): |
@@ -85,9 +85,9 @@ def isSet(): |
85 | 85 | HTTPErrorProcessor, OpenerDirector) |
86 | 86 |
|
87 | 87 | try: |
88 | | - from httplib import HTTPConnection |
| 88 | + from httplib import HTTPConnection, BadStatusLine |
89 | 89 | except ImportError: |
90 | | - from http.client import HTTPConnection |
| 90 | + from http.client import HTTPConnection, BadStatusLine |
91 | 91 |
|
92 | 92 | try: |
93 | 93 | from httplib import HTTPSConnection |
@@ -266,10 +266,13 @@ def write(data): |
266 | 266 | except AttributeError: |
267 | 267 | CERT_ERROR = tuple() |
268 | 268 |
|
269 | | - HTTP_ERRORS = ((HTTPError, URLError, socket.error, ssl.SSLError) + |
270 | | - CERT_ERROR) |
| 269 | + HTTP_ERRORS = ( |
| 270 | + (HTTPError, URLError, socket.error, ssl.SSLError, BadStatusLine) + |
| 271 | + CERT_ERROR |
| 272 | + ) |
271 | 273 | except ImportError: |
272 | | - HTTP_ERRORS = (HTTPError, URLError, socket.error) |
| 274 | + ssl = None |
| 275 | + HTTP_ERRORS = (HTTPError, URLError, socket.error, BadStatusLine) |
273 | 276 |
|
274 | 277 |
|
275 | 278 | class SpeedtestException(Exception): |
@@ -420,24 +423,26 @@ class SpeedtestHTTPSConnection(HTTPSConnection, |
420 | 423 | """ |
421 | 424 | def __init__(self, *args, **kwargs): |
422 | 425 | source_address = kwargs.pop('source_address', None) |
423 | | - context = kwargs.pop('context', None) |
424 | 426 | timeout = kwargs.pop('timeout', 10) |
425 | 427 |
|
426 | 428 | HTTPSConnection.__init__(self, *args, **kwargs) |
427 | 429 |
|
428 | | - self.source_address = source_address |
429 | | - self._context = context |
430 | 430 | self.timeout = timeout |
| 431 | + self.source_address = source_address |
431 | 432 |
|
432 | 433 | def connect(self): |
433 | 434 | "Connect to a host on a given (SSL) port." |
434 | 435 |
|
435 | 436 | SpeedtestHTTPConnection.connect(self) |
436 | 437 |
|
437 | 438 | kwargs = {} |
438 | | - if hasattr(ssl, 'SSLContext'): |
439 | | - kwargs['server_hostname'] = self.host |
440 | | - self.sock = self._context.wrap_socket(self.sock, **kwargs) |
| 439 | + if ssl: |
| 440 | + if hasattr(ssl, 'SSLContext'): |
| 441 | + kwargs['server_hostname'] = self.host |
| 442 | + try: |
| 443 | + self.sock = self._context.wrap_socket(self.sock, **kwargs) |
| 444 | + except AttributeError: |
| 445 | + self.sock = ssl.wrap_socket(self.sock, **kwargs) |
441 | 446 |
|
442 | 447 |
|
443 | 448 | def _build_connection(connection, source_address, timeout, context=None): |
|
0 commit comments