|
10 | 10 | import threading
|
11 | 11 | import warnings
|
12 | 12 |
|
13 |
| -try: |
14 |
| - import ssl |
15 |
| - ssl_available = True |
16 |
| -except ImportError: |
17 |
| - ssl_available = False |
18 |
| - |
19 | 13 | from redis._compat import (xrange, imap, byte_to_chr, unicode, long,
|
20 | 14 | nativestr, basestring, iteritems,
|
21 | 15 | LifoQueue, Empty, Full, urlparse, parse_qs,
|
|
34 | 28 | TimeoutError,
|
35 | 29 | )
|
36 | 30 | from redis.utils import HIREDIS_AVAILABLE
|
| 31 | + |
| 32 | +try: |
| 33 | + import ssl |
| 34 | + ssl_available = True |
| 35 | +except ImportError: |
| 36 | + ssl_available = False |
| 37 | + |
| 38 | +if ssl_available: |
| 39 | + blocking_exceptions = ( |
| 40 | + BlockingIOError, |
| 41 | + ssl.SSLWantReadError, |
| 42 | + ssl.SSLWantWriteError |
| 43 | + ) |
| 44 | +else: |
| 45 | + blocking_exceptions = (BlockingIOError,) |
| 46 | + |
| 47 | + |
37 | 48 | if HIREDIS_AVAILABLE:
|
38 | 49 | import hiredis
|
39 | 50 |
|
@@ -168,7 +179,7 @@ def _read_from_socket(self, length=None, timeout=SENTINEL,
|
168 | 179 | if length is not None and length > marker:
|
169 | 180 | continue
|
170 | 181 | return True
|
171 |
| - except BlockingIOError as ex: |
| 182 | + except blocking_exceptions as ex: |
172 | 183 | # if we're in nonblocking mode and the recv raises a
|
173 | 184 | # blocking error, simply return False indicating that
|
174 | 185 | # there's no data to be read. otherwise raise the
|
@@ -397,7 +408,7 @@ def read_from_socket(self, timeout=SENTINEL, raise_on_timeout=True):
|
397 | 408 | # data was read from the socket and added to the buffer.
|
398 | 409 | # return True to indicate that data was read.
|
399 | 410 | return True
|
400 |
| - except BlockingIOError as ex: |
| 411 | + except blocking_exceptions as ex: |
401 | 412 | # if we're in nonblocking mode and the recv raises a
|
402 | 413 | # blocking error, simply return False indicating that
|
403 | 414 | # there's no data to be read. otherwise raise the
|
|
0 commit comments