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:
parent
4524aebbac
commit
e38cd0ada2
@ -140,14 +140,14 @@ class UtilsTestCase(unittest.TestCase):
|
||||
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("example.com"), False)
|
||||
self.assertEqual(utils.get_hostname_type("abc.mynet.local"), False)
|
||||
self.assertEqual(utils.get_hostname_type("123.example"), False)
|
||||
self.assertEqual(utils.get_hostname_type("example.com"), 0)
|
||||
self.assertEqual(utils.get_hostname_type("abc.mynet.local"), 0)
|
||||
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("1::2::3"), False)
|
||||
self.assertEqual(utils.get_hostname_type("1:"), False)
|
||||
self.assertEqual(utils.get_hostname_type(":5"), False)
|
||||
self.assertEqual(utils.get_hostname_type("123.456.789.000"), 0)
|
||||
self.assertEqual(utils.get_hostname_type("1::2::3"), 0)
|
||||
self.assertEqual(utils.get_hostname_type("1:"), 0)
|
||||
self.assertEqual(utils.get_hostname_type(":5"), 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
4
utils.py
4
utils.py
@ -755,12 +755,12 @@ def remove_range(rangestr, mylist):
|
||||
def get_hostname_type(address):
|
||||
"""
|
||||
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:
|
||||
ip = ipaddress.ip_address(address)
|
||||
except ValueError:
|
||||
return False
|
||||
return 0
|
||||
else:
|
||||
if isinstance(ip, ipaddress.IPv4Address):
|
||||
return 1
|
||||
|
Loading…
Reference in New Issue
Block a user