3838)
3939from pymongo .network_layer import AsyncNetworkingInterface , NetworkingInterface , PyMongoProtocol
4040from pymongo .pool_options import PoolOptions
41- from pymongo .ssl_support import HAS_SNI , SSLError
41+ from pymongo .ssl_support import PYSSLError , SSLError , _has_sni
4242
43+ SSLErrors = (PYSSLError , SSLError )
4344if TYPE_CHECKING :
4445 from pymongo .pyopenssl_context import _sslConn
4546 from pymongo .typings import _Address
@@ -138,7 +139,7 @@ def _raise_connection_failure(
138139 msg += format_timeout_details (timeout_details )
139140 if isinstance (error , socket .timeout ):
140141 raise NetworkTimeout (msg ) from error
141- elif isinstance (error , SSLError ) and "timed out" in str (error ):
142+ elif isinstance (error , SSLErrors ) and "timed out" in str (error ):
142143 # Eventlet does not distinguish TLS network timeouts from other
143144 # SSLErrors (https://github.com/eventlet/eventlet/issues/692).
144145 # Luckily, we can work around this limitation because the phrase
@@ -279,7 +280,7 @@ async def _async_configured_socket(
279280 try :
280281 # We have to pass hostname / ip address to wrap_socket
281282 # to use SSLContext.check_hostname.
282- if HAS_SNI :
283+ if _has_sni ( False ) :
283284 loop = asyncio .get_running_loop ()
284285 ssl_sock = await loop .run_in_executor (
285286 None ,
@@ -293,7 +294,7 @@ async def _async_configured_socket(
293294 # Raise _CertificateError directly like we do after match_hostname
294295 # below.
295296 raise
296- except (OSError , SSLError ) as exc :
297+ except (OSError , * SSLErrors ) as exc :
297298 sock .close ()
298299 # We raise AutoReconnect for transient and permanent SSL handshake
299300 # failures alike. Permanent handshake failures, like protocol
@@ -349,7 +350,7 @@ async def _configured_protocol_interface(
349350 # Raise _CertificateError directly like we do after match_hostname
350351 # below.
351352 raise
352- except (OSError , SSLError ) as exc :
353+ except (OSError , * SSLErrors ) as exc :
353354 # We raise AutoReconnect for transient and permanent SSL handshake
354355 # failures alike. Permanent handshake failures, like protocol
355356 # mismatch, will be turned into ServerSelectionTimeoutErrors later.
@@ -458,7 +459,7 @@ def _configured_socket(address: _Address, options: PoolOptions) -> Union[socket.
458459 try :
459460 # We have to pass hostname / ip address to wrap_socket
460461 # to use SSLContext.check_hostname.
461- if HAS_SNI :
462+ if _has_sni ( True ) :
462463 ssl_sock = ssl_context .wrap_socket (sock , server_hostname = host ) # type: ignore[assignment, misc, unused-ignore]
463464 else :
464465 ssl_sock = ssl_context .wrap_socket (sock ) # type: ignore[assignment, misc, unused-ignore]
@@ -467,7 +468,7 @@ def _configured_socket(address: _Address, options: PoolOptions) -> Union[socket.
467468 # Raise _CertificateError directly like we do after match_hostname
468469 # below.
469470 raise
470- except (OSError , SSLError ) as exc :
471+ except (OSError , * SSLErrors ) as exc :
471472 sock .close ()
472473 # We raise AutoReconnect for transient and permanent SSL handshake
473474 # failures alike. Permanent handshake failures, like protocol
@@ -507,7 +508,7 @@ def _configured_socket_interface(address: _Address, options: PoolOptions) -> Net
507508 try :
508509 # We have to pass hostname / ip address to wrap_socket
509510 # to use SSLContext.check_hostname.
510- if HAS_SNI :
511+ if _has_sni ( True ) :
511512 ssl_sock = ssl_context .wrap_socket (sock , server_hostname = host )
512513 else :
513514 ssl_sock = ssl_context .wrap_socket (sock )
@@ -516,7 +517,7 @@ def _configured_socket_interface(address: _Address, options: PoolOptions) -> Net
516517 # Raise _CertificateError directly like we do after match_hostname
517518 # below.
518519 raise
519- except (OSError , SSLError ) as exc :
520+ except (OSError , * SSLErrors ) as exc :
520521 sock .close ()
521522 # We raise AutoReconnect for transient and permanent SSL handshake
522523 # failures alike. Permanent handshake failures, like protocol
0 commit comments