def parse_host_port(address, default_port=None):
 if (address[0] == '['):
  (_host, _port) = address[1:].split(']')
  host = _host
  if (':' in _port):
   port = _port.split(':')[1]
  else:
   port = default_port
 elif (address.count(':') == 1):
  (host, port) = address.split(':')
 else:
  host = address
  port = default_port
 return (host, (None if (port is None) else int(port)))

def parse_host_port ( address , default_port = None ) : if ( address [ 0 ] == '[' ) : ( _host , _port ) = address [ 1 : ] . split ( ']' ) host = _host if ( ':' in _port ) : port = _port . split ( ':' ) [ 1 ] else : port = default_port elif ( address . count ( ':' ) == 1 ) : ( host , port ) = address . split ( ':' ) else : host = address port = default_port return ( host , ( None if ( port is None ) else int ( port ) ) )
interpret a string as a host:port pair .