MCPcopy Index your code
hub / github.com/python/cpython / _parse_header_lines

Function _parse_header_lines

Lib/http/client.py:237–249  ·  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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…