3939 stacklevel = 2 ,
4040 )
4141try :
42- import pymongo .ssl_context as _stdssl
42+ import pymongo .ssl_context as _ssl
4343except ImportError :
4444 HAVE_SSL = False
4545
5555 IPADDR_SAFE = True
5656
5757 if HAVE_PYSSL :
58- HAS_SNI = _pyssl .HAS_SNI | _stdssl .HAS_SNI
58+ # # We have to pass hostname / ip address to wrap_socket
59+ # # to use SSLContext.check_hostname.
60+ # if ssl_context.has_sni:
61+ # ...
62+ HAS_SNI = _pyssl .HAS_SNI and _ssl .HAS_SNI
5963 PYSSLError : Any = _pyssl .SSLError
60- BLOCKING_IO_ERRORS : tuple = _pyssl .BLOCKING_IO_ERRORS + _stdssl .BLOCKING_IO_ERRORS
64+ BLOCKING_IO_ERRORS : tuple = _pyssl .BLOCKING_IO_ERRORS + _ssl .BLOCKING_IO_ERRORS
6165 BLOCKING_IO_READ_ERROR : tuple = (
6266 _pyssl .BLOCKING_IO_READ_ERROR ,
63- _stdssl .BLOCKING_IO_READ_ERROR ,
67+ _ssl .BLOCKING_IO_READ_ERROR ,
6468 )
6569 BLOCKING_IO_WRITE_ERROR : tuple = (
6670 _pyssl .BLOCKING_IO_WRITE_ERROR ,
67- _stdssl .BLOCKING_IO_WRITE_ERROR ,
71+ _ssl .BLOCKING_IO_WRITE_ERROR ,
6872 )
6973 else :
70- HAS_SNI = _stdssl .HAS_SNI
71- PYSSLError = _stdssl .SSLError
72- BLOCKING_IO_ERRORS = _stdssl .BLOCKING_IO_ERRORS
73- BLOCKING_IO_READ_ERROR = (_stdssl .BLOCKING_IO_READ_ERROR ,)
74- BLOCKING_IO_WRITE_ERROR = (_stdssl .BLOCKING_IO_WRITE_ERROR ,)
75- SSLError = _stdssl .SSLError
74+ HAS_SNI = _ssl .HAS_SNI
75+ PYSSLError = _ssl .SSLError
76+ BLOCKING_IO_ERRORS = _ssl .BLOCKING_IO_ERRORS
77+ BLOCKING_IO_READ_ERROR = (_ssl .BLOCKING_IO_READ_ERROR ,)
78+ BLOCKING_IO_WRITE_ERROR = (_ssl .BLOCKING_IO_WRITE_ERROR ,)
79+ SSLError = _ssl .SSLError
7680 BLOCKING_IO_LOOKUP_ERROR = BLOCKING_IO_READ_ERROR
7781
7882 def get_ssl_context (
@@ -84,12 +88,10 @@ def get_ssl_context(
8488 allow_invalid_hostnames : bool ,
8589 disable_ocsp_endpoint_check : bool ,
8690 is_sync : bool ,
87- ) -> Union [_pyssl .SSLContext , _stdssl .SSLContext ]: # type: ignore[name-defined]
91+ ) -> Union [_pyssl .SSLContext , _ssl .SSLContext ]: # type: ignore[name-defined]
8892 """Create and return an SSLContext object."""
8993 if is_sync and HAVE_PYSSL :
9094 _ssl : types .ModuleType = _pyssl
91- else :
92- _ssl = _stdssl
9395 verify_mode = CERT_NONE if allow_invalid_certificates else CERT_REQUIRED
9496 ctx = _ssl .SSLContext (_ssl .PROTOCOL_SSLv23 )
9597 if verify_mode != CERT_NONE :
0 commit comments