3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

get_hostname_type: return 0 for hostnames instead of False for consistency

This commit is contained in:
James Lu 2018-06-15 14:02:30 -07:00
parent 4524aebbac
commit e38cd0ada2
2 changed files with 9 additions and 9 deletions

View File

@ -140,14 +140,14 @@ class UtilsTestCase(unittest.TestCase):
self.assertEqual(utils.get_hostname_type("fc00::1234"), 2) self.assertEqual(utils.get_hostname_type("fc00::1234"), 2)
self.assertEqual(utils.get_hostname_type("1111:2222:3333:4444:5555:6666:7777:8888"), 2) self.assertEqual(utils.get_hostname_type("1111:2222:3333:4444:5555:6666:7777:8888"), 2)
self.assertEqual(utils.get_hostname_type("example.com"), False) self.assertEqual(utils.get_hostname_type("example.com"), 0)
self.assertEqual(utils.get_hostname_type("abc.mynet.local"), False) self.assertEqual(utils.get_hostname_type("abc.mynet.local"), 0)
self.assertEqual(utils.get_hostname_type("123.example"), False) self.assertEqual(utils.get_hostname_type("123.example"), 0)
self.assertEqual(utils.get_hostname_type("123.456.789.000"), False) self.assertEqual(utils.get_hostname_type("123.456.789.000"), 0)
self.assertEqual(utils.get_hostname_type("1::2::3"), False) self.assertEqual(utils.get_hostname_type("1::2::3"), 0)
self.assertEqual(utils.get_hostname_type("1:"), False) self.assertEqual(utils.get_hostname_type("1:"), 0)
self.assertEqual(utils.get_hostname_type(":5"), False) self.assertEqual(utils.get_hostname_type(":5"), 0)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -755,12 +755,12 @@ def remove_range(rangestr, mylist):
def get_hostname_type(address): def get_hostname_type(address):
""" """
Returns whether the given address is an IPv4 address (1), IPv6 address (2), or neither Returns whether the given address is an IPv4 address (1), IPv6 address (2), or neither
(False; assumed to be a hostname instead). (0; assumed to be a hostname instead).
""" """
try: try:
ip = ipaddress.ip_address(address) ip = ipaddress.ip_address(address)
except ValueError: except ValueError:
return False return 0
else: else:
if isinstance(ip, ipaddress.IPv4Address): if isinstance(ip, ipaddress.IPv4Address):
return 1 return 1