Skip to content

Commit

Permalink
path_with_added_args now preserves order in Python 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw authored and Simon Willison committed May 14, 2018
1 parent eaf715a commit 2b79f2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 3 additions & 4 deletions datasette/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ def path_with_added_args(request, args, path=None):
args = args.items()
arg_keys = set(a[0] for a in args)
current = []
for key, values in request.args.items():
current.extend(
[(key, value) for value in values if key not in arg_keys]
)
for key, value in urllib.parse.parse_qsl(request.query_string):
if key not in arg_keys:
current.append((key, value))
current.extend([
(key, value)
for key, value in args
Expand Down
9 changes: 6 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ def test_urlsafe_components(path, expected):
('/foo?bar=1&bar=2', {'baz': 3}, '/foo?bar=1&bar=2&baz=3'),
('/foo?bar=1', {'bar': None}, '/foo'),
# Test order is preserved
('/?_facet=prim_state&_facet=area_name', {
'prim_state': 'GA'
}, '/?_facet=prim_state&_facet=area_name&prim_state=GA'),
('/?_facet=prim_state&_facet=area_name', (
('prim_state', 'GA'),
), '/?_facet=prim_state&_facet=area_name&prim_state=GA'),
('/?_facet=state&_facet=city&state=MI', (
('city', 'Detroit'),
), '/?_facet=state&_facet=city&state=MI&city=Detroit'),
])
def test_path_with_added_args(path, added_args, expected):
request = Request(
Expand Down

0 comments on commit 2b79f2b

Please sign in to comment.