Merge and encode query parameters with an URL.

def _merge_params(url, params):
    """Merge and encode query parameters with an URL."""
    if isinstance(params, dict):
        params = list(params.items())

    scheme, netloc, path, query, fragment = urllib.parse.urlsplit(url)
    url_params = urllib.parse.parse_qsl(query, keep_blank_values=True)
    url_params.extend(params)

    query = _encode_data(url_params)

    return urllib.parse.urlunsplit((scheme, netloc, path, query, fragment))