def set_query_param(url, param, value):
    '''Returns a new URL with the given query parameter set to ``value``.

    ``value`` may be a list.'''
    scheme, netloc, path, qs, frag = urlparse.urlsplit(url)
    params = urlparse.parse_qs(qs)
    params[param] = value
    qs = urllib.urlencode(params, doseq=True)
    return urlparse.urlunsplit((scheme, netloc, path, qs, frag))
Returns a new URL with the given query parameter set to ``value``.

    ``value`` may be a list.