def normalize_query_parameters(query_string):
if query_string == "<STR_LIT>":<EOL><INDENT>return {}<EOL><DEDENT>components = query_string.split("<STR_LIT:&>")<EOL>result = {}<EOL>for component in components:<EOL><INDENT>try:<EOL><INDENT>key, value = component.split("<STR_LIT:=>", <NUM_LIT:1>)<EOL><DEDENT>except ValueError:<EOL><INDENT>key = component<EOL>value = "<STR_LIT>"<EOL><DEDENT>if component == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>key = normalize_uri_path_component(key)<EOL>value = normalize_uri_path_component(value)<EOL>if key in result:<EOL><INDENT>result[key].append(value)<EOL><DEDENT>else:<EOL><INDENT>result[key] = [value]<EOL><DEDENT><DEDENT>return dict([(key, sorted(values))<EOL>for key, values in iteritems(result)])<EOL>
normalize_query_parameters(query_string) -> dict

Converts a query string into a dictionary mapping parameter names to a
list of the sorted values.  This ensurses that the query string follows
% encoding rules according to RFC 3986 and checks for duplicate keys.

A ValueError exception is raised if a percent encoding is invalid.