MCPcopy
hub / github.com/tornadoweb/tornado / parse_qs_bytes

Function parse_qs_bytes

tornado/escape.py:173–193  ·  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

171
172
173def parse_qs_bytes(
174 qs: Union[str, bytes], keep_blank_values: bool = False, strict_parsing: bool = False
175) -> Dict[str, List[bytes]]:
176 """Parses a query string like urlparse.parse_qs,
177 but takes bytes and returns the values as byte strings.
178
179 Keys still become type str (interpreted as latin1 in python3!)
180 because it's too painful to keep them as byte strings in
181 python3 and in practice they're nearly always ascii anyway.
182 """
183 # This is gross, but python3 doesn't give us another way.
184 # Latin1 is the universal donor of character encodings.
185 if isinstance(qs, bytes):
186 qs = qs.decode("latin1")
187 result = urllib.parse.parse_qs(
188 qs, keep_blank_values, strict_parsing, encoding="latin1", errors="strict"
189 )
190 encoded = {}
191 for k, v in result.items():
192 encoded[k] = [i.encode("latin1") for i in v]
193 return encoded
194
195
196_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