diff --git a/Doc/library/email.parser.rst b/Doc/library/email.parser.rst --- a/Doc/library/email.parser.rst +++ b/Doc/library/email.parser.rst @@ -94,12 +94,14 @@ The :class:`Parser` class, imported from the :mod:`email.parser` module, provides an API that can be used to parse a message when the complete contents of the message are available in a string or file. The :mod:`email.parser` -module also provides a second class, called :class:`HeaderParser` which can be -used if you're only interested in the headers of the message. -:class:`HeaderParser` can be much faster in these situations, since it does not -attempt to parse the message body, instead setting the payload to the raw body -as a string. :class:`HeaderParser` has the same API as the :class:`Parser` -class. +module also provides header-only parsers, called :class:`HeaderParser` and +:class:`BytesHeaderParser`, which can be used if you're only interested in +the headers of the message. +:class:`HeaderParser` and :class:`BytesHeaderParser` can be much faster in +these situations, since they do not attempt to parse the message body, +instead setting the payload to the raw body as a string. +They do have the same API as the :class:`Parser` and :class:`BytesParser` +classes. .. class:: Parser(_class=email.message.Message, strict=None) @@ -154,7 +156,7 @@ the :class:`Parser` constructor. *strict* is supported only to make porting code easier; it is deprecated. - .. method:: parse(fp, headeronly=False) + .. method:: parse(fp, headersonly=False) Read all the data from the binary file-like object *fp*, parse the resulting bytes, and return the message object. *fp* must support diff --git a/Lib/email/parser.py b/Lib/email/parser.py --- a/Lib/email/parser.py +++ b/Lib/email/parser.py @@ -134,3 +134,12 @@ """ text = text.decode('ASCII', errors='surrogateescape') return self.parser.parsestr(text, headersonly) + + +class BytesHeaderParser(BytesParser): + def parse(self, fp, headersonly=True): + return BytesParser.parse(self, fp, headersonly=True) + + def parsestr(self, text, headersonly=True): + return BytesParser.parsestr(self, text, headersonly=True) +