[Common] Fix is_ipv6 when using ipaddress module
* The ipaddress module require unicode string for 'packed' addresses. * Also include minor corrections to the tests.
This commit is contained in:
parent
0edebda1c7
commit
7ebd69218f
|
@ -792,7 +792,7 @@ def is_ipv6(ip):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
return ipaddress.IPv6Address(ip)
|
return ipaddress.IPv6Address(decode_string(ip))
|
||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import os
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
from deluge.common import (VersionSplit, fdate, fpcnt, fpeer, fsize, fspeed, ftime, get_path_size, is_infohash, is_ip,
|
from deluge.common import (VersionSplit, fdate, fpcnt, fpeer, fsize, fspeed, ftime, get_path_size, is_infohash, is_ip,
|
||||||
is_magnet, is_url)
|
is_ipv4, is_ipv6, is_magnet, is_url)
|
||||||
from deluge.ui.util import lang
|
from deluge.ui.util import lang
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,12 +74,12 @@ class CommonTestCase(unittest.TestCase):
|
||||||
self.failIf(is_ip('2001:db8:'))
|
self.failIf(is_ip('2001:db8:'))
|
||||||
|
|
||||||
def test_is_ipv4(self):
|
def test_is_ipv4(self):
|
||||||
self.failUnless(is_ip('192.0.2.0'))
|
self.failUnless(is_ipv4('192.0.2.0'))
|
||||||
self.failIf(is_ip('192..0.0'))
|
self.failIf(is_ipv4('192..0.0'))
|
||||||
|
|
||||||
def test_is_ipv6(self):
|
def test_is_ipv6(self):
|
||||||
self.failUnless(is_ip('2001:db8::'))
|
self.failUnless(is_ipv6('2001:db8::'))
|
||||||
self.failIf(is_ip('2001:db8:'))
|
self.failIf(is_ipv6('2001:db8:'))
|
||||||
|
|
||||||
def test_version_split(self):
|
def test_version_split(self):
|
||||||
self.failUnless(VersionSplit('1.2.2') == VersionSplit('1.2.2'))
|
self.failUnless(VersionSplit('1.2.2') == VersionSplit('1.2.2'))
|
||||||
|
|
Loading…
Reference in New Issue