summaryrefslogtreecommitdiffstats
path: root/Lib/email/feedparser.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/email/feedparser.py')
-rw-r--r--Lib/email/feedparser.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py
index 15db26d..16ed288 100644
--- a/Lib/email/feedparser.py
+++ b/Lib/email/feedparser.py
@@ -19,7 +19,7 @@ the current message. Defects are just instances that live on the message
object's .defects attribute.
"""
-__all__ = ['FeedParser']
+__all__ = ['FeedParser', 'BytesFeedParser']
import re
@@ -126,7 +126,7 @@ class BufferedSubFile(object):
def __iter__(self):
return self
- def next(self):
+ def __next__(self):
line = self.readline()
if line == '':
raise StopIteration
@@ -142,7 +142,7 @@ class FeedParser:
self._factory = _factory
self._input = BufferedSubFile()
self._msgstack = []
- self._parse = self._parsegen().next
+ self._parse = self._parsegen().__next__
self._cur = None
self._last = None
self._headersonly = False
@@ -368,12 +368,12 @@ class FeedParser:
end = len(mo.group(0))
self._last.epilogue = epilogue[:-end]
else:
- payload = self._last.get_payload()
- if isinstance(payload, basestring):
+ payload = self._last._payload
+ if isinstance(payload, str):
mo = NLCRE_eol.search(payload)
if mo:
payload = payload[:-len(mo.group(0))]
- self._last.set_payload(payload)
+ self._last._payload = payload
self._input.pop_eof_matcher()
self._pop_message()
# Set the multipart up for newline cleansing, which will
@@ -482,3 +482,10 @@ class FeedParser:
if lastheader:
# XXX reconsider the joining of folded lines
self._cur[lastheader] = EMPTYSTRING.join(lastvalue).rstrip('\r\n')
+
+
+class BytesFeedParser(FeedParser):
+ """Like FeedParser, but feed accepts bytes."""
+
+ def feed(self, data):
+ super().feed(data.decode('ascii', 'surrogateescape'))