(hosts, scheme, username=None, password=None, database=None, options=None)
return urlunparse([scheme, netloc, path, path_params, query, fragment])
Build a server connection string from individual parts. Make sure that parts are properly URL-encoded.

    See https://docs.mongodb.com/manual/reference/connection-string/
Build a server connection string from individual parts. Make sure that parts are properly URL-encoded.
Build a server connection string from individual parts . Make sure that parts are properly URL - encoded .
def build_connection_string(hosts, scheme, username=None, password=None, database=None, options=None):
    # type: (list, str, str, str, str, dict) -> str
    """
    Build a server connection string from individual parts. Make sure that parts are properly URL-encoded.

    See https://docs.mongodb.com/manual/reference/connection-string/
    """

    host = ','.join(hosts)
    path = '/{}'.format(database) if database else '/'
    if username and password:
        netloc = '{}:{}@{}'.format(quote_plus(username), quote_plus(password), host)
    elif username:
        # Only makes sense when using X509 authentication. But specifying the username
        # is not a requirement of MongoDB anymore since v3.4
        netloc = '{}@{}'.format(quote_plus(username), host)
    else:
        netloc = host

    path_params = ""
    query = urlencode(options or {})
    fragment = ""

    return urlunparse([scheme, netloc, path, path_params, query, fragment])
def build_connection_string ( hosts , scheme , username = None , password = None , database = None , options = None ) : # type: (list, str, str, str, str, dict) -> str host = ',' . join ( hosts ) path = '/{}' . format ( database ) if database else '/' if username and password : netloc = '{}:{}@{}' . format ( quote_plus ( username ) , quote_plus ( password ) , host ) elif username : # Only makes sense when using X509 authentication. But specifying the username # is not a requirement of MongoDB anymore since v3.4 netloc = '{}@{}' . format ( quote_plus ( username ) , host ) else : netloc = host path_params = "" query = urlencode ( options or { } ) fragment = "" return urlunparse ( [ scheme , netloc , path , path_params , query , fragment ] )