def _normalize_query(uri):
    query = uri.query

    try:
        items = urlparse.parse_qsl(query, keep_blank_values=True, strict_parsing=True)
    except __HOLE__:
        # If we can't parse the query string, we better preserve it as it was.
        return query

    # Python sorts are stable, so preserving relative ordering of items with
    # the same key doesn't require any work from us
    items = sorted(items, key=lambda x: x[0])

    # Remove query params that are blacklisted
    items = [i for i in items if not _blacklisted_query_param(i[0])]

    # Normalise percent-encoding for query items
    query = _normalize_queryitems(items)

    return query
dataset/ETHPy150Open hypothesis/h/h/api/uri.py/_normalize_query