def inet_ntop(address_family, packed_ip):
 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(packed_ip, byte_cls)):
  raise TypeError(unwrap(u'\n            packed_ip must be a byte string, not %s\n            ', type_name(packed_ip)))
 required_len = (4 if (address_family == socket.AF_INET) else 16)
 if (len(packed_ip) != required_len):
  raise ValueError(unwrap(u'\n            packed_ip must be %d bytes long - is %d\n            ', required_len, len(packed_ip)))
 if (address_family == socket.AF_INET):
  return (u'%d.%d.%d.%d' % tuple(bytes_to_list(packed_ip)))
 octets = struct.unpack('!HHHHHHHH', packed_ip)
 runs_of_zero = {}
 longest_run = 0
 zero_index = None
 for (i, octet) in enumerate((octets + ((-1),))):
  if (octet != 0):
   if (zero_index is not None):
    length = (i - zero_index)
    if (length not in runs_of_zero):
     runs_of_zero[length] = zero_index
    longest_run = max(longest_run, length)
    zero_index = None
  elif (zero_index is None):
   zero_index = i
 hexed = [hex(o)[2:] for o in octets]
 if (longest_run < 2):
  return u':'.join(hexed)
 zero_start = runs_of_zero[longest_run]
 zero_end = (zero_start + longest_run)
 return ((u':'.join(hexed[:zero_start]) + u'::') + u':'.join(hexed[zero_end:]))

def inet_ntop ( address_family , packed_ip ) : 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 ( packed_ip , byte_cls ) ) : raise TypeError ( unwrap ( u'\n            packed_ip must be a byte string, not %s\n            ' , type_name ( packed_ip ) ) ) required_len = ( 4 if ( address_family == socket . AF_INET ) else 16 ) if ( len ( packed_ip ) != required_len ) : raise ValueError ( unwrap ( u'\n            packed_ip must be %d bytes long - is %d\n            ' , required_len , len ( packed_ip ) ) ) if ( address_family == socket . AF_INET ) : return ( u'%d.%d.%d.%d' % tuple ( bytes_to_list ( packed_ip ) ) ) octets = struct . unpack ( '!HHHHHHHH' , packed_ip ) runs_of_zero = { } longest_run = 0 zero_index = None for ( i , octet ) in enumerate ( ( octets + ( ( - 1 ) , ) ) ) : if ( octet != 0 ) : if ( zero_index is not None ) : length = ( i - zero_index ) if ( length not in runs_of_zero ) : runs_of_zero [ length ] = zero_index longest_run = max ( longest_run , length ) zero_index = None elif ( zero_index is None ) : zero_index = i hexed = [ hex ( o ) [ 2 : ] for o in octets ] if ( longest_run < 2 ) : return u':' . join ( hexed ) zero_start = runs_of_zero [ longest_run ] zero_end = ( zero_start + longest_run ) return ( ( u':' . join ( hexed [ : zero_start ] ) + u'::' ) + u':' . join ( hexed [ zero_end : ] ) )
convert the binary form of a network address into its textual form .