Commit 8707190c authored by Denis Bilenko's avatar Denis Bilenko

fix spurious failures in test__socket_dns6.py

parent bd902f49
...@@ -75,24 +75,27 @@ def log_call(result, time, function, *args): ...@@ -75,24 +75,27 @@ def log_call(result, time, function, *args):
log_fresult(result, time) log_fresult(result, time)
google_host_re = re.compile('^arn[a-z0-9-]+.1e100.net$') def compare_relaxed(a, b):
def compare_ipv6(a, b):
""" """
>>> compare_ipv6('2a00:1450:400f:801::1010', '2a00:1450:400f:800::1011') >>> compare_relaxed('2a00:1450:400f:801::1010', '2a00:1450:400f:800::1011')
True True
>>> compare_ipv6('2a00:1450:400f:801::1010', '2aXX:1450:400f:900::1011')
>>> compare_relaxed('2a00:1450:400f:801::1010', '2aXX:1450:400f:900::1011')
False False
>>> compare_ipv6('2a00:1450:4016:800::1013', '2a00:1450:4008:c01::93')
>>> compare_relaxed('2a00:1450:4016:800::1013', '2a00:1450:4008:c01::93')
True True
>>> compare_relaxed('a.surfly.com', 'b.surfly.com')
True
>>> compare_relaxed('a.surfly.com', 'a.gevent.org')
False
""" """
if a.count(':') == 5 and b.count(':') == 5: if a.count(':') == 5 and b.count(':') == 5:
# QQQ not actually sure if this is right thing to do # QQQ not actually sure if this is right thing to do
return a.rsplit(':')[:2] == b.rsplit(':')[:2] return a.rsplit(':')[:2] == b.rsplit(':')[:2]
if google_host_re.match(a) and google_host_re.match(b): return a.split('.', 1)[-1] == b.split('.', 1)[-1]
return True
return a == b
def contains_5tuples(lst): def contains_5tuples(lst):
...@@ -106,24 +109,29 @@ def relaxed_is_equal(a, b): ...@@ -106,24 +109,29 @@ def relaxed_is_equal(a, b):
""" """
>>> relaxed_is_equal([(10, 1, 6, '', ('2a00:1450:400f:801::1010', 80, 0, 0))], [(10, 1, 6, '', ('2a00:1450:400f:800::1011', 80, 0, 0))]) >>> relaxed_is_equal([(10, 1, 6, '', ('2a00:1450:400f:801::1010', 80, 0, 0))], [(10, 1, 6, '', ('2a00:1450:400f:800::1011', 80, 0, 0))])
True True
>>> relaxed_is_equal([1, '2'], (1, '2')) >>> relaxed_is_equal([1, '2'], (1, '2'))
False False
>>> relaxed_is_equal([1, '2'], [1, '2']) >>> relaxed_is_equal([1, '2'], [1, '2'])
True True
>>> relaxed_is_equal(('wi-in-x93.1e100.net', 'http'), ('we-in-x68.1e100.net', 'http'))
True
""" """
if type(a) is not type(b): if type(a) is not type(b):
return False return False
if a == b:
return True
if isinstance(a, basestring): if isinstance(a, basestring):
return compare_ipv6(a, b) return compare_relaxed(a, b)
if hasattr(a, '__iter__'): if len(a) != len(b):
if len(a) != len(b): return False
return False if contains_5tuples(a) and contains_5tuples(b):
if contains_5tuples(a) and contains_5tuples(b): # getaddrinfo results
# getaddrinfo results a = sorted(a)
a = sorted(a) b = sorted(b)
b = sorted(b) return all(relaxed_is_equal(x, y) for (x, y) in zip(a, b))
return all(relaxed_is_equal(x, y) for (x, y) in zip(a, b))
return a == b
def add(klass, hostname, name=None): def add(klass, hostname, name=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment