Since Windows' version of Python doesn't build with IPV6 support, we have

to be careful about how we try to detect whether a string is IPV6.
This commit is contained in:
James Vega 2004-09-03 13:45:06 +00:00
parent 75dc3e804a
commit 911d9db4a4

View File

@ -612,15 +612,7 @@ def isIP(s):
except socket.error: except socket.error:
return False return False
def isIPV6(s): def bruteIsIPV6(s):
"""Returns whether or not a given string is an IPV6 address."""
try:
return bool(socket.inet_pton(socket.AF_INET6, s))
except socket.error:
try:
socket.inet_pton(socket.AF_INET6, '::')
except socket.error:
# We gotta fake it.
if s.count('::') <= 1: if s.count('::') <= 1:
L = s.split(':') L = s.split(':')
if len(L) <= 8: if len(L) <= 8:
@ -633,6 +625,21 @@ def isIPV6(s):
return True return True
return False return False
def isIPV6(s):
"""Returns whether or not a given string is an IPV6 address."""
try:
if hasattr(socket, 'inet_pton'):
return bool(socket.inet_pton(socket.AF_INET6, s))
else:
return bruteIsIPV6(s)
except socket.error:
try:
socket.inet_pton(socket.AF_INET6, '::')
except socket.error:
# We gotta fake it.
return bruteIsIPV6(s)
return False
class InsensitivePreservingDict(UserDict.DictMixin, object): class InsensitivePreservingDict(UserDict.DictMixin, object):
key = staticmethod(str.lower) key = staticmethod(str.lower)
def __init__(self, dict=None, key=None): def __init__(self, dict=None, key=None):