Given a URL and a key/val pair, set or replace an item in the query parameters of the URL, and return the new URL.
(url, key, val)
| 4 | |
| 5 | |
| 6 | def replace_query_param(url, key, val): |
| 7 | """ |
| 8 | Given a URL and a key/val pair, set or replace an item in the query |
| 9 | parameters of the URL, and return the new URL. |
| 10 | """ |
| 11 | (scheme, netloc, path, query, fragment) = parse.urlsplit(force_str(url)) |
| 12 | query_dict = parse.parse_qs(query, keep_blank_values=True) |
| 13 | query_dict[force_str(key)] = [force_str(val)] |
| 14 | query = parse.urlencode(sorted(query_dict.items()), doseq=True) |
| 15 | return parse.urlunsplit((scheme, netloc, path, query, fragment)) |
| 16 | |
| 17 | |
| 18 | def remove_query_param(url, key): |
no outgoing calls