_ssl_compat.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """
  2. _ssl_compat.py
  3. websocket - WebSocket client library for Python
  4. Copyright 2021 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. __all__ = ["HAVE_SSL", "ssl", "SSLError", "SSLWantReadError", "SSLWantWriteError"]
  16. try:
  17. import ssl
  18. from ssl import SSLError
  19. from ssl import SSLWantReadError
  20. from ssl import SSLWantWriteError
  21. HAVE_CONTEXT_CHECK_HOSTNAME = False
  22. if hasattr(ssl, 'SSLContext') and hasattr(ssl.SSLContext, 'check_hostname'):
  23. HAVE_CONTEXT_CHECK_HOSTNAME = True
  24. __all__.append("HAVE_CONTEXT_CHECK_HOSTNAME")
  25. HAVE_SSL = True
  26. except ImportError:
  27. # dummy class of SSLError for environment without ssl support
  28. class SSLError(Exception):
  29. pass
  30. class SSLWantReadError(Exception):
  31. pass
  32. class SSLWantWriteError(Exception):
  33. pass
  34. ssl = None
  35. HAVE_SSL = False