Skip to content

Commit 6752a67

Browse files
committed
address review
1 parent 74f98c5 commit 6752a67

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

pymongo/asynchronous/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
from pymongo.network_layer import AsyncNetworkingInterface, async_receive_message, async_sendall
7777
from pymongo.pool_options import PoolOptions
7878
from pymongo.pool_shared import (
79+
SSLErrors,
7980
_CancellationContext,
8081
_configured_protocol_interface,
8182
_get_timeout_details,
@@ -86,7 +87,6 @@
8687
from pymongo.server_api import _add_to_command
8788
from pymongo.server_type import SERVER_TYPE
8889
from pymongo.socket_checker import SocketChecker
89-
from pymongo.ssl_support import PYSSLError, SSLError
9090

9191
if TYPE_CHECKING:
9292
from bson import CodecOptions

pymongo/network_layer.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@
6767
_UNPACK_COMPRESSION_HEADER = struct.Struct("<iiB").unpack
6868
_POLL_TIMEOUT = 0.5
6969
# Errors raised by sockets (and TLS sockets) when in non-blocking mode.
70-
BLOCKING_IO_ERRORS = (
71-
BlockingIOError,
72-
*BLOCKING_IO_LOOKUP_ERROR,
73-
*ssl_support.BLOCKING_IO_ERRORS,
74-
)
70+
BLOCKING_IO_ERRORS = (BlockingIOError, *BLOCKING_IO_LOOKUP_ERROR, *ssl_support.BLOCKING_IO_ERRORS)
7571

7672

7773
# These socket-based I/O methods are for KMS requests and any other network operations that do not use

pymongo/ssl_support.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,14 @@
5656

5757
if HAVE_PYSSL:
5858
PYSSLError: Any = _pyssl.SSLError
59-
BLOCKING_IO_ERRORS: tuple = _pyssl.BLOCKING_IO_ERRORS + _ssl.BLOCKING_IO_ERRORS
60-
BLOCKING_IO_READ_ERROR: tuple = (
61-
_pyssl.BLOCKING_IO_READ_ERROR,
62-
_ssl.BLOCKING_IO_READ_ERROR,
63-
)
64-
BLOCKING_IO_WRITE_ERROR: tuple = (
65-
_pyssl.BLOCKING_IO_WRITE_ERROR,
66-
_ssl.BLOCKING_IO_WRITE_ERROR,
67-
)
59+
BLOCKING_IO_ERRORS: Any = _ssl.BLOCKING_IO_ERRORS + _pyssl.BLOCKING_IO_ERRORS
60+
BLOCKING_IO_READ_ERROR: Any = _pyssl.BLOCKING_IO_READ_ERROR | _ssl.BLOCKING_IO_READ_ERROR
61+
BLOCKING_IO_WRITE_ERROR: Any = _pyssl.BLOCKING_IO_WRITE_ERROR | _ssl.BLOCKING_IO_WRITE_ERROR
6862
else:
6963
PYSSLError = _ssl.SSLError
7064
BLOCKING_IO_ERRORS = _ssl.BLOCKING_IO_ERRORS
71-
BLOCKING_IO_READ_ERROR = (_ssl.BLOCKING_IO_READ_ERROR,)
72-
BLOCKING_IO_WRITE_ERROR = (_ssl.BLOCKING_IO_WRITE_ERROR,)
65+
BLOCKING_IO_READ_ERROR = _ssl.BLOCKING_IO_READ_ERROR
66+
BLOCKING_IO_WRITE_ERROR = _ssl.BLOCKING_IO_WRITE_ERROR
7367
SSLError = _ssl.SSLError
7468
BLOCKING_IO_LOOKUP_ERROR = BLOCKING_IO_READ_ERROR
7569

pymongo/synchronous/pool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
from pymongo.network_layer import NetworkingInterface, receive_message, sendall
7474
from pymongo.pool_options import PoolOptions
7575
from pymongo.pool_shared import (
76+
SSLErrors,
7677
_CancellationContext,
7778
_configured_socket_interface,
7879
_get_timeout_details,
@@ -83,7 +84,6 @@
8384
from pymongo.server_api import _add_to_command
8485
from pymongo.server_type import SERVER_TYPE
8586
from pymongo.socket_checker import SocketChecker
86-
from pymongo.ssl_support import PYSSLError, SSLError
8787
from pymongo.synchronous.client_session import _validate_session_write_concern
8888
from pymongo.synchronous.helpers import _handle_reauth
8989
from pymongo.synchronous.network import command
@@ -636,7 +636,7 @@ def _raise_connection_failure(self, error: BaseException) -> NoReturn:
636636
reason = ConnectionClosedReason.ERROR
637637
self.close_conn(reason)
638638
# SSLError from PyOpenSSL inherits directly from Exception.
639-
if isinstance(error, (IOError, OSError, SSLError, PYSSLError)):
639+
if isinstance(error, (IOError, OSError, *SSLErrors)):
640640
details = _get_timeout_details(self.opts)
641641
_raise_connection_failure(self.address, error, timeout_details=details)
642642
else:
@@ -1048,7 +1048,7 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
10481048
reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR),
10491049
error=ConnectionClosedReason.ERROR,
10501050
)
1051-
if isinstance(error, (IOError, OSError, SSLError, PYSSLError)):
1051+
if isinstance(error, (IOError, OSError, *SSLErrors)):
10521052
details = _get_timeout_details(self.opts)
10531053
_raise_connection_failure(self.address, error, timeout_details=details)
10541054

0 commit comments

Comments
 (0)