_ssl_compat.py 1.8 KB

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