1"""
2_ssl_compat.py
3websocket - WebSocket client library for Python
4
5Copyright 2025 engn33r
6
7Licensed under the Apache License, Version 2.0 (the "License");
8you may not use this file except in compliance with the License.
9You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13Unless required by applicable law or agreed to in writing, software
14distributed under the License is distributed on an "AS IS" BASIS,
15WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16See the License for the specific language governing permissions and
17limitations under the License.
18"""
19
20from typing import TYPE_CHECKING
21
22if TYPE_CHECKING:
23 import ssl as _ssl_module
24 from ssl import (
25 SSLError as _SSLErrorType,
26 SSLEOFError as _SSLEOFErrorType,
27 SSLWantReadError as _SSLWantReadErrorType,
28 SSLWantWriteError as _SSLWantWriteErrorType,
29 )
30else:
31 _ssl_module = None
32 _SSLErrorType = None
33 _SSLEOFErrorType = None
34 _SSLWantReadErrorType = None
35 _SSLWantWriteErrorType = None
36
37__all__ = [
38 "HAVE_SSL",
39 "ssl",
40 "SSLError",
41 "SSLEOFError",
42 "SSLWantReadError",
43 "SSLWantWriteError",
44]
45
46try:
47 import ssl
48 from ssl import SSLError, SSLEOFError, SSLWantReadError, SSLWantWriteError # type: ignore[attr-defined]
49
50 HAVE_SSL = True
51except ImportError:
52 # dummy class of SSLError for environment without ssl support
53 class SSLError(Exception): # type: ignore[no-redef]
54 pass
55
56 class SSLEOFError(Exception): # type: ignore[no-redef]
57 pass
58
59 class SSLWantReadError(Exception): # type: ignore[no-redef]
60 pass
61
62 class SSLWantWriteError(Exception): # type: ignore[no-redef]
63 pass
64
65 ssl = None # type: ignore[assignment,no-redef]
66 HAVE_SSL = False