def parse_host(entity, default_port=DEFAULT_PORT):
 host = entity
 port = default_port
 if (entity[0] == '['):
  (host, port) = parse_ipv6_literal_host(entity, default_port)
 elif entity.endswith('.sock'):
  return (entity, default_port)
 elif (entity.find(':') != (-1)):
  if (entity.count(':') > 1):
   raise ValueError("Reserved characters such as ':' must be escaped according RFC 2396. An IPv6 address literal must be enclosed in '[' and ']' according to RFC 2732.")
  (host, port) = host.split(':', 1)
 if isinstance(port, string_type):
  if ((not port.isdigit()) or (int(port) > 65535) or (int(port) <= 0)):
   raise ValueError(('Port must be an integer between 0 and 65535: %s' % (port,)))
  port = int(port)
 return (host.lower(), port)

def parse_host ( entity , default_port = DEFAULT_PORT ) : host = entity port = default_port if ( entity [ 0 ] == '[' ) : ( host , port ) = parse_ipv6_literal_host ( entity , default_port ) elif entity . endswith ( '.sock' ) : return ( entity , default_port ) elif ( entity . find ( ':' ) != ( - 1 ) ) : if ( entity . count ( ':' ) > 1 ) : raise ValueError ( "Reserved characters such as ':' must be escaped according RFC 2396. An IPv6 address literal must be enclosed in '[' and ']' according to RFC 2732." ) ( host , port ) = host . split ( ':' , 1 ) if isinstance ( port , string_type ) : if ( ( not port . isdigit ( ) ) or ( int ( port ) > 65535 ) or ( int ( port ) <= 0 ) ) : raise ValueError ( ( 'Port must be an integer between 0 and 65535: %s' % ( port , ) ) ) port = int ( port ) return ( host . lower ( ) , port )
parse a canonical host:port string into parts .