compat.py 867 B

1234567891011121314151617181920212223242526272829
  1. import platform
  2. # Fix for issue reported in https://github.com/Pylons/waitress/issues/138,
  3. # Python on Windows may not define IPPROTO_IPV6 in socket.
  4. import socket
  5. import sys
  6. import warnings
  7. # True if we are running on Windows
  8. WIN = platform.system() == "Windows"
  9. MAXINT = sys.maxsize
  10. HAS_IPV6 = socket.has_ipv6
  11. if hasattr(socket, "IPPROTO_IPV6") and hasattr(socket, "IPV6_V6ONLY"):
  12. IPPROTO_IPV6 = socket.IPPROTO_IPV6
  13. IPV6_V6ONLY = socket.IPV6_V6ONLY
  14. else: # pragma: no cover
  15. if WIN:
  16. IPPROTO_IPV6 = 41
  17. IPV6_V6ONLY = 27
  18. else:
  19. warnings.warn(
  20. "OS does not support required IPv6 socket flags. This is requirement "
  21. "for Waitress. Please open an issue at https://github.com/Pylons/waitress. "
  22. "IPv6 support has been disabled.",
  23. RuntimeWarning,
  24. )
  25. HAS_IPV6 = False