Created
December 11, 2012 12:34
-
-
Save bootandy/4258249 to your computer and use it in GitHub Desktop.
add a parameter to the url. Overwrite param if it is already there
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def _merge_new_params_with_referring_url(url, param_name=None, param_value=None): | |
| if not url: | |
| return '/' | |
| if not param_name or not param_value: | |
| return url | |
| scheme, network, path, query, fragment = urlparse.urlsplit(url) | |
| query_map = urlparse.parse_qs(query) | |
| query_map[param_name] = str(param_value) | |
| new_query = urllib.urlencode(query_map, doseq=True) | |
| return urlparse.urlunsplit((scheme, network, path, new_query, fragment)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment