diff options
Diffstat (limited to 'waitress/compat.py')
-rw-r--r-- | waitress/compat.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/waitress/compat.py b/waitress/compat.py index 9e06cde..700f7a1 100644 --- a/waitress/compat.py +++ b/waitress/compat.py @@ -1,5 +1,7 @@ import sys import types +import platform +import warnings try: import urlparse @@ -7,8 +9,12 @@ except ImportError: # pragma: no cover from urllib import parse as urlparse # True if we are running on Python 3. +PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 +# True if we are running on Windows +WIN = platform.system() == 'Windows' + if PY3: # pragma: no cover string_types = str, integer_types = int, @@ -109,3 +115,26 @@ try: MAXINT = sys.maxint except AttributeError: # pragma: no cover MAXINT = sys.maxsize + + +# Fix for issue reported in https://github.com/Pylons/waitress/issues/138, +# Python on Windows may not define IPPROTO_IPV6 in socket. +import socket + +HAS_IPV6 = socket.has_ipv6 + +if hasattr(socket, 'IPPROTO_IPV6') and hasattr(socket, 'IPV6_V6ONLY'): + IPPROTO_IPV6 = socket.IPPROTO_IPV6 + IPV6_V6ONLY = socket.IPV6_V6ONLY +else: # pragma: no cover + if WIN: + IPPROTO_IPV6 = 41 + IPV6_V6ONLY = 27 + else: + warnings.warn( + 'OS does not support required IPv6 socket flags. This is requirement ' + 'for Waitress. Please open an issue at https://github.com/Pylons/waitress. ' + 'IPv6 support has been disabled.', + RuntimeWarning + ) + HAS_IPV6 = False |