MCPcopy Index your code
hub / github.com/RustPython/RustPython / _parse_header_lines

Function _parse_header_lines

Lib/http/client.py:236–248  ·  view source on GitHub ↗

Parses only RFC 5322 headers from header lines. email Parser wants to see strings rather than bytes. But a TextIOWrapper around self.rfile would buffer too many bytes from the stream, bytes which we later need to read as bytes. So we read the correct bytes here, as bytes, for e

(header_lines, _class=HTTPMessage)

Source from the content-addressed store, hash-verified

234 return headers
235
236def _parse_header_lines(header_lines, _class=HTTPMessage):
237 """
238 Parses only RFC 5322 headers from header lines.
239
240 email Parser wants to see strings rather than bytes.
241 But a TextIOWrapper around self.rfile would buffer too many bytes
242 from the stream, bytes which we later need to read as bytes.
243 So we read the correct bytes here, as bytes, for email Parser
244 to parse.
245
246 """
247 hstring = b''.join(header_lines).decode('iso-8859-1')
248 return email.parser.Parser(_class=_class).parsestr(hstring)
249
250def parse_headers(fp, _class=HTTPMessage):
251 """Parses only RFC 5322 headers from a file pointer."""

Callers 2

parse_headersFunction · 0.85

Calls 3

decodeMethod · 0.45
joinMethod · 0.45
parsestrMethod · 0.45

Tested by

no test coverage detected