Parses only RFC2822 headers from a file pointer. 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
(fp, _class=HTTPMessage)
| 229 | return headers |
| 230 | |
| 231 | def parse_headers(fp, _class=HTTPMessage): |
| 232 | """Parses only RFC2822 headers from a file pointer. |
| 233 | |
| 234 | email Parser wants to see strings rather than bytes. |
| 235 | But a TextIOWrapper around self.rfile would buffer too many bytes |
| 236 | from the stream, bytes which we later need to read as bytes. |
| 237 | So we read the correct bytes here, as bytes, for email Parser |
| 238 | to parse. |
| 239 | |
| 240 | """ |
| 241 | headers = _read_headers(fp) |
| 242 | hstring = b''.join(headers).decode('iso-8859-1') |
| 243 | return email.parser.Parser(_class=_class).parsestr(hstring) |
| 244 | |
| 245 | |
| 246 | class HTTPResponse(io.BufferedIOBase): |
no test coverage detected