'L{twisted.python.compat.inet_pton} parses IPv4 and IPv6 addresses in a
manner similar to that of L{socket.inet_pton}.'

def testPToN(self):

    from twisted.python.compat import inet_pton
    f = (lambda a: inet_pton(socket.AF_INET6, a))
    g = (lambda a: inet_pton(socket.AF_INET, a))
    self.assertEqual('\x00\x00\x00\x00', g('0.0.0.0'))
    self.assertEqual('\xff\x00\xff\x00', g('255.0.255.0'))
    self.assertEqual('\xaa\xaa\xaa\xaa', g('170.170.170.170'))
    self.assertEqual(('\x00' * 16), f('::'))
    self.assertEqual(('\x00' * 16), f('0::0'))
    self.assertEqual(('\x00\x01' + ('\x00' * 14)), f('1::'))
    self.assertEqual('E\xefv\xcb\x00\x1aV\xef\xaf\xeb\x0b\xac\x19$\xae\xae', f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae'))
    self.assertEqual('E\xefv\xcb\x00\x1aV\xef\xaf\xeb\x0b\xac\x19$\xae\xae', f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae%en0'))
    self.assertEqual((('\x00' * 14) + '\x00\x01'), f('::1'))
    self.assertEqual((('\x00' * 12) + '\x01\x02\x03\x04'), f('::1.2.3.4'))
    self.assertEqual('\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x01\x02\x03\xff', f('1:2:3:4:5:6:1.2.3.255'))
    for badaddr in ['1:2:3:4:5:6:7:8:', ':1:2:3:4:5:6:7:8', '1::2::3', '1:::3', ':::', '1:2', '::1.2', '1.2.3.4::', 'abcd:1.2.3.4:abcd:abcd:abcd:abcd:abcd', '1234:1.2.3.4:1234:1234:1234:1234:1234:1234', '1.2.3.4', '', '%eth0']:
        self.assertRaises(ValueError, f, badaddr)
