55
55
IPADDR_SAFE = True
56
56
57
57
if HAVE_PYSSL :
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
63
58
PYSSLError : Any = _pyssl .SSLError
64
59
BLOCKING_IO_ERRORS : tuple = _pyssl .BLOCKING_IO_ERRORS + _ssl .BLOCKING_IO_ERRORS
65
60
BLOCKING_IO_READ_ERROR : tuple = (
71
66
_ssl .BLOCKING_IO_WRITE_ERROR ,
72
67
)
73
68
else :
74
- HAS_SNI = _ssl .HAS_SNI
75
69
PYSSLError = _ssl .SSLError
76
70
BLOCKING_IO_ERRORS = _ssl .BLOCKING_IO_ERRORS
77
71
BLOCKING_IO_READ_ERROR = (_ssl .BLOCKING_IO_READ_ERROR ,)
78
72
BLOCKING_IO_WRITE_ERROR = (_ssl .BLOCKING_IO_WRITE_ERROR ,)
79
73
SSLError = _ssl .SSLError
80
74
BLOCKING_IO_LOOKUP_ERROR = BLOCKING_IO_READ_ERROR
81
75
76
+ def _has_sni (is_sync : bool ) -> bool :
77
+ if is_sync and HAVE_PYSSL :
78
+ return _pyssl .HAS_SNI
79
+ return _ssl .HAS_SNI
80
+
82
81
def get_ssl_context (
83
82
certfile : Optional [str ],
84
83
passphrase : Optional [str ],
@@ -92,6 +91,8 @@ def get_ssl_context(
92
91
"""Create and return an SSLContext object."""
93
92
if is_sync and HAVE_PYSSL :
94
93
_ssl : types .ModuleType = _pyssl
94
+ else :
95
+ _ssl = globals ()["_ssl" ]
95
96
verify_mode = CERT_NONE if allow_invalid_certificates else CERT_REQUIRED
96
97
ctx = _ssl .SSLContext (_ssl .PROTOCOL_SSLv23 )
97
98
if verify_mode != CERT_NONE :
@@ -132,10 +133,12 @@ def get_ssl_context(
132
133
class SSLError (Exception ): # type: ignore
133
134
pass
134
135
135
- HAS_SNI = False
136
136
IPADDR_SAFE = False
137
137
BLOCKING_IO_ERRORS = ()
138
138
139
+ def _has_sni (is_sync : bool ) -> bool : # noqa: ARG001
140
+ return False
141
+
139
142
def get_ssl_context (* dummy ): # type: ignore
140
143
"""No ssl module, raise ConfigurationError."""
141
144
raise ConfigurationError ("The ssl module is not available" )
0 commit comments