codekingpro/portable-devtools
114k
1"""2_ssl_compat.py3websocket - WebSocket client library for Python4 5Copyright 2025 engn33r6 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 at10 11 http://www.apache.org/licenses/LICENSE-2.012 13Unless required by applicable law or agreed to in writing, software14distributed 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 and17limitations under the License.18"""19 20from typing import TYPE_CHECKING21 22if TYPE_CHECKING:23 import ssl as _ssl_module24 from ssl import (25 SSLError as _SSLErrorType,26 SSLEOFError as _SSLEOFErrorType,27 SSLWantReadError as _SSLWantReadErrorType,28 SSLWantWriteError as _SSLWantWriteErrorType,29 )30else:31 _ssl_module = None32 _SSLErrorType = None33 _SSLEOFErrorType = None34 _SSLWantReadErrorType = None35 _SSLWantWriteErrorType = None36 37__all__ = [38 "HAVE_SSL",39 "ssl",40 "SSLError",41 "SSLEOFError",42 "SSLWantReadError",43 "SSLWantWriteError",44]45 46try:47 import ssl48 from ssl import SSLError, SSLEOFError, SSLWantReadError, SSLWantWriteError # type: ignore[attr-defined]49 50 HAVE_SSL = True51except ImportError:52 # dummy class of SSLError for environment without ssl support53 class SSLError(Exception): # type: ignore[no-redef]54 pass55 56 class SSLEOFError(Exception): # type: ignore[no-redef]57 pass58 59 class SSLWantReadError(Exception): # type: ignore[no-redef]60 pass61 62 class SSLWantWriteError(Exception): # type: ignore[no-redef]63 pass64 65 ssl = None # type: ignore[assignment,no-redef]66 HAVE_SSL = False67 