diff options
author | R David Murray <rdmurray@bitdance.com> | 2011-04-13 20:46:05 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2011-04-13 20:46:05 (GMT) |
commit | b35c850a3f7e2e6d470bb9543b9ba83aa33047f7 (patch) | |
tree | 9d7c221e58a8585d0721cc8498ef98d24c3dc269 /Lib/email | |
parent | f400ab40e4eb7dc6ad886920fb02ce4f7d1e929f (diff) | |
download | cpython-b35c850a3f7e2e6d470bb9543b9ba83aa33047f7.zip cpython-b35c850a3f7e2e6d470bb9543b9ba83aa33047f7.tar.gz cpython-b35c850a3f7e2e6d470bb9543b9ba83aa33047f7.tar.bz2 |
#11684: Complete parser bytes interface by adding BytesHeaderParser
Patch by Steffen Daode Nurpmeso.
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/generator.py | 4 | ||||
-rw-r--r-- | Lib/email/parser.py | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/Lib/email/generator.py b/Lib/email/generator.py index f0e7a95..fdd34e4 100644 --- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -297,10 +297,12 @@ class Generator: # message/rfc822. Such messages are generated by, for example, # Groupwise when forwarding unadorned messages. (Issue 7970.) So # in that case we just emit the string body. - payload = msg.get_payload() + payload = msg._payload if isinstance(payload, list): g.flatten(msg.get_payload(0), unixfrom=False, linesep=self._NL) payload = s.getvalue() + else: + payload = self._encode(payload) self._fp.write(payload) # This used to be a module level function; we use a classmethod for this diff --git a/Lib/email/parser.py b/Lib/email/parser.py index ef051fa..fc5090b 100644 --- a/Lib/email/parser.py +++ b/Lib/email/parser.py @@ -4,7 +4,7 @@ """A parser of RFC 2822 and MIME email messages.""" -__all__ = ['Parser', 'HeaderParser'] +__all__ = ['Parser', 'HeaderParser', 'BytesParser', 'BytesHeaderParser'] import warnings from io import StringIO, TextIOWrapper @@ -114,3 +114,11 @@ class BytesParser: """ 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 parsebytes(self, text, headersonly=True): + return BytesParser.parsebytes(self, text, headersonly=True) |