Exemple #1
0
def query_to_dict(query):
    """
    >>> sorted(query_to_dict('/service?bar=baz&foo=bizz').items())
    [('bar', 'baz'), ('foo', 'bizz')]
    >>> sorted(query_to_dict('bar=baz&foo=bizz').items())
    [('bar', 'baz'), ('foo', 'bizz')]
    """
    if not ('&' in query or '=' in query):
        return {}
    d = {}
    if '?' in query:
        query = query.split('?', 1)[-1]
    for key, value in parse_qsl(query):
        d[key.lower()] = value
    return d
Exemple #2
0
def url_decode(qs, charset='utf-8', decode_keys=False, include_empty=True,
               errors='ignore'):
    """
    Parse query string `qs` and return a `NoCaseMultiDict`.
    """
    tmp = []
    for key, value in parse_qsl(qs, include_empty):
        if PY2:
            if decode_keys:
                key = key.decode(charset, errors)
            tmp.append((key, value.decode(charset, errors)))
        else:
            if not isinstance(key, text_type):
                key = key.decode(charset, errors)
            if not isinstance(value, text_type):
                value = value.decode(charset, errors)
            tmp.append((key, value))
    return NoCaseMultiDict(tmp)