def inet_pton(address_family, ip_string):
 if (address_family not in set([socket.AF_INET, socket.AF_INET6])):
  raise ValueError(unwrap(u'\n            address_family must be socket.AF_INET (%s) or socket.AF_INET6 (%s),\n            not %s\n            ', repr(socket.AF_INET), repr(socket.AF_INET6), repr(address_family)))
 if (not isinstance(ip_string, str_cls)):
  raise TypeError(unwrap(u'\n            ip_string must be a unicode string, not %s\n            ', type_name(ip_string)))
 if (address_family == socket.AF_INET):
  octets = ip_string.split(u'.')
  error = (len(octets) != 4)
  if (not error):
   ints = []
   for o in octets:
    o = int(o)
    if ((o > 255) or (o < 0)):
     error = True
     break
    ints.append(o)
  if error:
   raise ValueError(unwrap(u'\n                ip_string must be a dotted string with four integers in the\n                range of 0 to 255, got %s\n                ', repr(ip_string)))
  return struct.pack('!BBBB', *ints)
 error = False
 omitted = ip_string.count(u'::')
 if (omitted > 1):
  error = True
 elif (omitted == 0):
  octets = ip_string.split(u':')
  error = (len(octets) != 8)
 else:
  (begin, end) = ip_string.split(u'::')
  begin_octets = begin.split(u':')
  end_octets = end.split(u':')
  missing = ((8 - len(begin_octets)) - len(end_octets))
  octets = ((begin_octets + ([u'0'] * missing)) + end_octets)
 if (not error):
  ints = []
  for o in octets:
   o = int(o, 16)
   if ((o > 65535) or (o < 0)):
    error = True
    break
   ints.append(o)
  return struct.pack('!HHHHHHHH', *ints)
 raise ValueError(unwrap(u'\n        ip_string must be a valid ipv6 string, got %s\n        ', repr(ip_string)))

def inet_pton ( address_family , ip_string ) : if ( address_family not in set ( [ socket . AF_INET , socket . AF_INET6 ] ) ) : raise ValueError ( unwrap ( u'\n            address_family must be socket.AF_INET (%s) or socket.AF_INET6 (%s),\n            not %s\n            ' , repr ( socket . AF_INET ) , repr ( socket . AF_INET6 ) , repr ( address_family ) ) ) if ( not isinstance ( ip_string , str_cls ) ) : raise TypeError ( unwrap ( u'\n            ip_string must be a unicode string, not %s\n            ' , type_name ( ip_string ) ) ) if ( address_family == socket . AF_INET ) : octets = ip_string . split ( u'.' ) error = ( len ( octets ) != 4 ) if ( not error ) : ints = [ ] for o in octets : o = int ( o ) if ( ( o > 255 ) or ( o < 0 ) ) : error = True break ints . append ( o ) if error : raise ValueError ( unwrap ( u'\n                ip_string must be a dotted string with four integers in the\n                range of 0 to 255, got %s\n                ' , repr ( ip_string ) ) ) return struct . pack ( '!BBBB' , * ints ) error = False omitted = ip_string . count ( u'::' ) if ( omitted > 1 ) : error = True elif ( omitted == 0 ) : octets = ip_string . split ( u':' ) error = ( len ( octets ) != 8 ) else : ( begin , end ) = ip_string . split ( u'::' ) begin_octets = begin . split ( u':' ) end_octets = end . split ( u':' ) missing = ( ( 8 - len ( begin_octets ) ) - len ( end_octets ) ) octets = ( ( begin_octets + ( [ u'0' ] * missing ) ) + end_octets ) if ( not error ) : ints = [ ] for o in octets : o = int ( o , 16 ) if ( ( o > 65535 ) or ( o < 0 ) ) : error = True break ints . append ( o ) return struct . pack ( '!HHHHHHHH' , * ints ) raise ValueError ( unwrap ( u'\n        ip_string must be a valid ipv6 string, got %s\n        ' , repr ( ip_string ) ) )
convert the textual form of a network address into its binary form .