Permalink
Browse files

Add HAS_IPV6 to compat

Disable IPv6 support if there is no IPv6 support on the platform
  • Loading branch information...
1 parent d108896 commit 57ea8381ac0e95a3feff58655fade698e70f9eee @bertjwregeer bertjwregeer committed Oct 14, 2016
Showing with 16 additions and 5 deletions.
  1. +7 −1 waitress/adjustments.py
  2. +9 −4 waitress/compat.py
@@ -20,6 +20,7 @@
PY2,
WIN,
string_types,
+ HAS_IPV6,
)
truthy = frozenset(('t', 'true', 'y', 'yes', 'on', '1'))
@@ -228,10 +229,15 @@ def __init__(self, **kw):
enabled_families = socket.AF_UNSPEC
+ if not self.ipv4 and not HAS_IPV6: # pragma: no cover
+ raise ValueError(
+ 'IPv4 is disabled but IPv6 is not available. Cowardly refusing to start.'
+ )
+
if self.ipv4 and not self.ipv6:
enabled_families = socket.AF_INET
- if not self.ipv4 and self.ipv6:
+ if not self.ipv4 and self.ipv6 and HAS_IPV6:
enabled_families = socket.AF_INET6
wanted_sockets = []
View
@@ -1,6 +1,7 @@
import sys
import types
import platform
+import warnings
try:
import urlparse
@@ -120,16 +121,20 @@ def exec_(code, globs=None, locs=None):
# 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
- import os
- if os.name == 'nt':
+ if WIN:
IPPROTO_IPV6 = 41
IPV6_V6ONLY = 27
else:
- raise RuntimeError(
+ 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'
+ 'for Waitress. Please open an issue at https://github.com/Pylons/waitress. '
+ 'IPv6 support has been disabled.',
+ RuntimeWarning
)
+ HAS_IPV6 = False

0 comments on commit 57ea838

Please sign in to comment.