def api_url(host, port, endpoint):
 hostname_list = [host]
 if (host.startswith('http://') or host.startswith('https://')):
  hostname = ''.join(hostname_list)
 else:
  hostname_list.insert(0, 'http://')
  hostname = ''.join(hostname_list)
 joined = urljoin('{hostname}:{port}'.format(hostname=hostname, port=port), endpoint)
 (scheme, netloc, path, query_string, fragment) = urlsplit(joined)
 query_params = parse_qs(query_string)
 query_params['format'] = ['json']
 new_query_string = urlencode(query_params, doseq=True)
 return urlunsplit((scheme, netloc, path, new_query_string, fragment))

def api_url ( host , port , endpoint ) : hostname_list = [ host ] if ( host . startswith ( 'http://' ) or host . startswith ( 'https://' ) ) : hostname = '' . join ( hostname_list ) else : hostname_list . insert ( 0 , 'http://' ) hostname = '' . join ( hostname_list ) joined = urljoin ( '{hostname}:{port}' . format ( hostname = hostname , port = port ) , endpoint ) ( scheme , netloc , path , query_string , fragment ) = urlsplit ( joined ) query_params = parse_qs ( query_string ) query_params [ 'format' ] = [ 'json' ] new_query_string = urlencode ( query_params , doseq = True ) return urlunsplit ( ( scheme , netloc , path , new_query_string , fragment ) )
returns a joined url .