diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py --- a/Lib/email/feedparser.py +++ b/Lib/email/feedparser.py @@ -23,6 +23,7 @@ import re +from collections import deque from email import errors from email import message from email._policybase import compat32 @@ -52,8 +53,8 @@ def __init__(self): # The last partial line pushed into this object. self._partial = '' - # The list of full, pushed lines, in reverse order - self._lines = [] + # A deque of full, pushed lines, in reverse order + self._lines = deque() # The stack of false-EOF checking predicates. self._eofstack = [] # A flag indicating whether the file has been closed or not. @@ -82,7 +83,7 @@ # RFC 2046, section 5.1.2 requires us to recognize outer level # boundaries at any level of inner nesting. Do this, but be sure it's # in the order of most to least nested. - for ateof in self._eofstack[::-1]: + for ateof in reversed(self._eofstack): if ateof(line): # We're at the false EOF. But push the last line back first. self._lines.append(line) @@ -110,7 +111,7 @@ def pushlines(self, lines): # Reverse and insert at the front of the lines. - self._lines[:0] = lines[::-1] + self._lines.extendleft(lines) def __iter__(self): return self