      """
      (scheme, netloc, path, query, fragment) = urlparse.urlsplit(force_str(url))
      query_dict = urlparse.parse_qs(query, keep_blank_values=True)
      query_dict[force_str(key)] = [force_str(val)]
      query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
      return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
  
  
  def remove_query_param(url, key):
      """
      Given a URL and a key/val pair, remove an item in the query
 
</s> remove     (scheme, netloc, path, query, fragment) = urlparse.urlsplit(force_str(url))
    query_dict = urlparse.parse_qs(query, keep_blank_values=True)
 </s> add     (scheme, netloc, path, query, fragment) = parse.urlsplit(force_str(url))
    query_dict = parse.parse_qs(query, keep_blank_values=True) </s> remove     (scheme, netloc, path, query, fragment) = urlparse.urlsplit(force_str(url))
    query_dict = urlparse.parse_qs(query, keep_blank_values=True)
 </s> add     (scheme, netloc, path, query, fragment) = parse.urlsplit(force_str(url))
    query_dict = parse.parse_qs(query, keep_blank_values=True) </s> remove     query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
    return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
 </s> add     query = parse.urlencode(sorted(list(query_dict.items())), doseq=True)
    return parse.urlunsplit((scheme, netloc, path, query, fragment)) </s> remove from django.utils.six.moves.urllib import parse as urlparse
 </s> add  </s> remove             six.reraise(type(exc), exc, sys.exc_info()[2])
 </s> add             raise exc.with_traceback(sys.exc_info()[2])
    query = parse.urlencode(sorted(list(query_dict.items())), doseq=True)
    return parse.urlunsplit((scheme, netloc, path, query, fragment))
      """
      (scheme, netloc, path, query, fragment) = urlparse.urlsplit(force_str(url))
      query_dict = urlparse.parse_qs(query, keep_blank_values=True)
      query_dict[force_str(key)] = [force_str(val)]
    query = parse.urlencode(sorted(list(query_dict.items())), doseq=True)
    return parse.urlunsplit((scheme, netloc, path, query, fragment))
    query = parse.urlencode(sorted(list(query_dict.items())), doseq=True)
    return parse.urlunsplit((scheme, netloc, path, query, fragment))
  
  
  def remove_query_param(url, key):
      """
      Given a URL and a key/val pair, remove an item in the query
keep keep keep keep replace replace keep keep keep keep keep
 Dropped Python 2 compatibility. (#6615)

Thanks to Jon Dufresne (@jdufresne) for review.

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Rizwan Mansuri <Rizwan@webbyfox.com> 
rest_framework/utils/urls.py