-
Notifications
You must be signed in to change notification settings - Fork 108
Add parameter without removing duplicated value in query string #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
8257ab2
dbe9267
c21da61
aad3c03
fa37abf
65cd7ca
c9ce0ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
import posixpath | ||
import warnings | ||
import string | ||
from collections import namedtuple, OrderedDict | ||
from collections import namedtuple | ||
import six | ||
from six.moves.urllib.parse import (urljoin, urlsplit, urlunsplit, | ||
urldefrag, urlencode, urlparse, | ||
|
@@ -199,13 +199,23 @@ def url_query_cleaner(url, parameterlist=(), sep='&', kvsep='=', remove=False, u | |
url += '#' + fragment | ||
return url | ||
|
||
|
||
def _add_or_replace_parameters(url, params): | ||
parsed = urlsplit(url) | ||
args = parse_qsl(parsed.query, keep_blank_values=True) | ||
|
||
new_args = OrderedDict(args) | ||
new_args.update(params) | ||
current_args = parse_qsl(parsed.query, keep_blank_values=True) | ||
new_args = [] | ||
changing_params = set(params) | ||
seen_params = set() | ||
|
||
for name, value in current_args: | ||
if name in params: | ||
if name not in seen_params: | ||
new_args.append((name, params[name])) | ||
seen_params.add(name) | ||
elif name not in changing_params: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was checking the coverage data, and I may be missing something, but I think this could be replaced by an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
new_args.append((name, value)) | ||
|
||
not_modified_args = [(name, value) for name, value in params.items() if name not in seen_params] | ||
new_args += not_modified_args | ||
|
||
query = urlencode(new_args) | ||
return urlunsplit(parsed._replace(query=query)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💄 It does not matter much, but…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's good 💅 :)