path_with_added_args now preserves order in Python 3.5

pull/258/head
Simon Willison 2018-05-14 00:02:07 -03:00 zatwierdzone przez Simon Willison
rodzic eaf715a60a
commit 2b79f2bdeb
2 zmienionych plików z 9 dodań i 7 usunięć

Wyświetl plik

@ -151,10 +151,9 @@ def path_with_added_args(request, args, path=None):
args = args.items() args = args.items()
arg_keys = set(a[0] for a in args) arg_keys = set(a[0] for a in args)
current = [] current = []
for key, values in request.args.items(): for key, value in urllib.parse.parse_qsl(request.query_string):
current.extend( if key not in arg_keys:
[(key, value) for value in values if key not in arg_keys] current.append((key, value))
)
current.extend([ current.extend([
(key, value) (key, value)
for key, value in args for key, value in args

Wyświetl plik

@ -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=2', {'baz': 3}, '/foo?bar=1&bar=2&baz=3'),
('/foo?bar=1', {'bar': None}, '/foo'), ('/foo?bar=1', {'bar': None}, '/foo'),
# Test order is preserved # Test order is preserved
('/?_facet=prim_state&_facet=area_name', { ('/?_facet=prim_state&_facet=area_name', (
'prim_state': 'GA' ('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): def test_path_with_added_args(path, added_args, expected):
request = Request( request = Request(