Module tenlib.transform.qs
Manipulates the query string.
Functions
def encode(data: bytes)-
Wrapper for
urllib.parse.quote_plus. def decode(data: str)-
Wrapper for
urllib.parse.unquote_plus. def decode_bytes(data: str) ‑> bytes-
Wrapper for
urllib.parse.unquote_to_bytes. def iis_encode(data: bytes)-
Performs an IIS encoding (
%u00XX). def iis_encode_all(data: bytes) ‑> strdef unparse(data: dict) ‑> str-
Converts a dictionary of parameters into a query string.
Examples
>>> unparse({'k1': 'v1', 'k2': '', 'k3[k4]': 'v3 //'}) 'k1=v1&k2=&k3[k4]=v3+%2F%2F' >>> unparse({'a': ['b', {'d': 'e'}]}) 'a[0]=b&a[1][d]=e' def parse(query: str, flat: bool = True) ‑> dict-
Splits the query string into a
dictof parameters. IfflatisFalsearray keys such ask[a][b]are parsed as a multi-dimensionaldict. Empty keys such ask[]take the next possible integer value.Args
flat:bool- If True, returns a one-dimensional
dict. Otherwise, returns nesteddictobjects.
Returns
dict
Examples
>>> parse('k1=v1&k2=v2&k3[k4]=v3+%2f%2f') {'k1': 'v1', 'k2': '', 'k3[k4]': 'v3 //'} >>> parse('k[0]=0&k[3]=3&k[]=1', flat=False) {'k': {'0': '0', '3': '3', '1': '1'}}