def get_ip_port_afi(host_and_port_str):
 host_and_port_str = host_and_port_str.strip()
 if host_and_port_str.startswith('['):
  af = socket.AF_INET6
  (host, rest) = host_and_port_str[1:].split(']')
  if rest:
   port = int(rest[1:])
  else:
   port = DEFAULT_KAFKA_PORT
  return (host, port, af)
 elif (':' not in host_and_port_str):
  af = _address_family(host_and_port_str)
  return (host_and_port_str, DEFAULT_KAFKA_PORT, af)
 else:
  try:
   socket.inet_pton(socket.AF_INET6, host_and_port_str)
   return (host_and_port_str, DEFAULT_KAFKA_PORT, socket.AF_INET6)
  except AttributeError:
   log.warning('socket.inet_pton not available on this platform. consider `pip install win_inet_pton`')
   pass
  except (ValueError, socket.error):
   pass
  (host, port) = host_and_port_str.rsplit(':', 1)
  port = int(port)
  af = _address_family(host)
  return (host, port, af)

def get_ip_port_afi ( host_and_port_str ) : host_and_port_str = host_and_port_str . strip ( ) if host_and_port_str . startswith ( '[' ) : af = socket . AF_INET6 ( host , rest ) = host_and_port_str [ 1 : ] . split ( ']' ) if rest : port = int ( rest [ 1 : ] ) else : port = DEFAULT_KAFKA_PORT return ( host , port , af ) elif ( ':' not in host_and_port_str ) : af = _address_family ( host_and_port_str ) return ( host_and_port_str , DEFAULT_KAFKA_PORT , af ) else : try : socket . inet_pton ( socket . AF_INET6 , host_and_port_str ) return ( host_and_port_str , DEFAULT_KAFKA_PORT , socket . AF_INET6 ) except AttributeError : log . warning ( 'socket.inet_pton not available on this platform. consider `pip install win_inet_pton`' ) pass except ( ValueError , socket . error ) : pass ( host , port ) = host_and_port_str . rsplit ( ':' , 1 ) port = int ( port ) af = _address_family ( host ) return ( host , port , af )
parse the ip and port from a string in the format of: * host_or_ip <- can be either ipv4 address literal or hostname/fqdn * host_or_ipv4:port <- can be either ipv4 address literal or hostname/fqdn * [host_or_ip] <- ipv6 address literal * [host_or_ip]:port .