def is_ip(string): """ Returns True if the given string is an IPv4 or IPv6 address, False otherwise. :type string: string :param string: Any string. :rtype: bool :return: True if the string is an IP address, False otherwise. """ return ipv4.is_ip(string) or ipv6.is_ip(string)
def is_ip(string): """ Returns True if the given string is an IPv4 or IPv6 address, False otherwise. @type string: string @param string: Any string. @rtype: bool @return: True if the string is an IP address, False otherwise. """ return ipv4.is_ip(string) or ipv6.is_ip(string)
def testIsIp(self): from Exscript.util.ipv6 import is_ip self.assertTrue(is_ip('::')) self.assertTrue(is_ip('1::')) self.assertTrue(is_ip('::A')) self.assertTrue(is_ip('1234::2222')) self.assertTrue(is_ip('1234:0:01:02::')) self.assertTrue(is_ip('1:2:3:4:5:6:7:8')) self.assertFalse(is_ip(':::')) self.assertFalse(is_ip('1:2:3:4:5:6:7:8:9')) self.assertFalse(is_ip('1::A::2')) self.assertFalse(is_ip('1::A::')) self.assertFalse(is_ip('::A::')) self.assertFalse(is_ip('::A::1')) self.assertFalse(is_ip('A')) self.assertFalse(is_ip('X::'))
def _call_func(funcname, ip, *args): if ipv4.is_ip(ip): return ipv4.__dict__[funcname](ip, *args) elif ipv6.is_ip(ip): return ipv6.__dict__[funcname](ip, *args) raise ValueError('neither ipv4 nor ipv6: ' + repr(ip))