MCPcopy Create free account
hub / github.com/EasyIME/PIME / parse_qs_bytes

Function parse_qs_bytes

python/python3/tornado/escape.py:147–167  ·  view source on GitHub ↗

Parses a query string like urlparse.parse_qs, but takes bytes and returns the values as byte strings. Keys still become type str (interpreted as latin1 in python3!) because it's too painful to keep them as byte strings in python3 and in practice they're nearly always ascii anyway.

(
    qs: Union[str, bytes], keep_blank_values: bool = False, strict_parsing: bool = False
)

Source from the content-addressed store, hash-verified

145
146
147def parse_qs_bytes(
148 qs: Union[str, bytes], keep_blank_values: bool = False, strict_parsing: bool = False
149) -> Dict[str, List[bytes]]:
150 """Parses a query string like urlparse.parse_qs,
151 but takes bytes and returns the values as byte strings.
152
153 Keys still become type str (interpreted as latin1 in python3!)
154 because it's too painful to keep them as byte strings in
155 python3 and in practice they're nearly always ascii anyway.
156 """
157 # This is gross, but python3 doesn't give us another way.
158 # Latin1 is the universal donor of character encodings.
159 if isinstance(qs, bytes):
160 qs = qs.decode("latin1")
161 result = urllib.parse.parse_qs(
162 qs, keep_blank_values, strict_parsing, encoding="latin1", errors="strict"
163 )
164 encoded = {}
165 for k, v in result.items():
166 encoded[k] = [i.encode("latin1") for i in v]
167 return encoded
168
169
170_UTF8_TYPES = (bytes, type(None))

Callers 2

__init__Method · 0.90
parse_body_argumentsFunction · 0.90

Calls 1

itemsMethod · 0.80

Tested by

no test coverage detected