Exemplo n.º 1
0
Arquivo: uri.py Projeto: openbizgit/h
def _normalize_query(uri):
    query = uri.query

    try:
        items = urlparse.parse_qsl(query, keep_blank_values=True)
    except ValueError:
        # 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 i[0] not in BLACKLISTED_QUERY_PARAMS]

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

    return query
Exemplo n.º 2
0
Arquivo: uri.py Projeto: JJediny/h
def _normalize_query(uri):
    query = uri.query

    try:
        items = urlparse.parse_qsl(query, keep_blank_values=True)
    except ValueError:
        # 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