Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Attributes
email.feedparser.BufferedSubFile Class Reference
Inheritance diagram for email.feedparser.BufferedSubFile:
Inheritance graph
[legend]
Collaboration diagram for email.feedparser.BufferedSubFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def push_eof_matcher
def pop_eof_matcher
def close
def readline
def unreadline
def push
def pushlines
def is_closed
def __iter__
def __next__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Attributes

 _partial
 _lines
 _eofstack
 _closed

Detailed Description

A file-ish object that can have new data loaded into it.

You can also push and pop line-matching predicates onto a stack.  When the
current predicate matches the current line, a false EOF response
(i.e. empty string) is returned instead.  This lets the parser adhere to a
simple abstraction -- it parses until EOF closes the current message.

Definition at line 43 of file feedparser.py.


Constructor & Destructor Documentation

Definition at line 51 of file feedparser.py.

00051 
00052     def __init__(self):
00053         # The last partial line pushed into this object.
00054         self._partial = ''
00055         # The list of full, pushed lines, in reverse order
00056         self._lines = []
00057         # The stack of false-EOF checking predicates.
00058         self._eofstack = []
00059         # A flag indicating whether the file has been closed or not.
00060         self._closed = False

Here is the caller graph for this function:


Member Function Documentation

Definition at line 126 of file feedparser.py.

00126 
00127     def __iter__(self):
00128         return self

Definition at line 129 of file feedparser.py.

00129 
00130     def __next__(self):
00131         line = self.readline()
00132         if line == '':
00133             raise StopIteration
00134         return line
00135 
00136 


Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 67 of file feedparser.py.

00067 
00068     def close(self):
00069         # Don't forget any trailing partial line.
00070         self._lines.append(self._partial)
00071         self._partial = ''
00072         self._closed = True

Definition at line 123 of file feedparser.py.

00123 
00124     def is_closed(self):
00125         return self._closed

Definition at line 64 of file feedparser.py.

00064 
00065     def pop_eof_matcher(self):
00066         return self._eofstack.pop()

def email.feedparser.BufferedSubFile.push (   self,
  data 
)
Push some new data into this object.

Definition at line 96 of file feedparser.py.

00096 
00097     def push(self, data):
00098         """Push some new data into this object."""
00099         # Handle any previous leftovers
00100         data, self._partial = self._partial + data, ''
00101         # Crack into lines, but preserve the newlines on the end of each
00102         parts = NLCRE_crack.split(data)
00103         # The *ahem* interesting behaviour of re.split when supplied grouping
00104         # parentheses is that the last element of the resulting list is the
00105         # data after the final RE.  In the case of a NL/CR terminated string,
00106         # this is the empty string.
00107         self._partial = parts.pop()
00108         #GAN 29Mar09  bugs 1555570, 1721862  Confusion at 8K boundary ending with \r:
00109         # is there a \n to follow later?
00110         if not self._partial and parts and parts[-1].endswith('\r'):
00111             self._partial = parts.pop(-2)+parts.pop()
00112         # parts is a list of strings, alternating between the line contents
00113         # and the eol character(s).  Gather up a list of lines after
00114         # re-attaching the newlines.
00115         lines = []
00116         for i in range(len(parts) // 2):
00117             lines.append(parts[i*2] + parts[i*2+1])
00118         self.pushlines(lines)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 61 of file feedparser.py.

00061 
00062     def push_eof_matcher(self, pred):
00063         self._eofstack.append(pred)

def email.feedparser.BufferedSubFile.pushlines (   self,
  lines 
)

Definition at line 119 of file feedparser.py.

00119 
00120     def pushlines(self, lines):
00121         # Reverse and insert at the front of the lines.
00122         self._lines[:0] = lines[::-1]

Here is the caller graph for this function:

Definition at line 73 of file feedparser.py.

00073 
00074     def readline(self):
00075         if not self._lines:
00076             if self._closed:
00077                 return ''
00078             return NeedMoreData
00079         # Pop the line off the stack and see if it matches the current
00080         # false-EOF predicate.
00081         line = self._lines.pop()
00082         # RFC 2046, section 5.1.2 requires us to recognize outer level
00083         # boundaries at any level of inner nesting.  Do this, but be sure it's
00084         # in the order of most to least nested.
00085         for ateof in self._eofstack[::-1]:
00086             if ateof(line):
00087                 # We're at the false EOF.  But push the last line back first.
00088                 self._lines.append(line)
00089                 return ''
00090         return line

Here is the caller graph for this function:

def email.feedparser.BufferedSubFile.unreadline (   self,
  line 
)

Definition at line 91 of file feedparser.py.

00091 
00092     def unreadline(self, line):
00093         # Let the consumer push a line back into the buffer.
00094         assert line is not NeedMoreData
00095         self._lines.append(line)


Member Data Documentation

Definition at line 59 of file feedparser.py.

Definition at line 57 of file feedparser.py.

Definition at line 55 of file feedparser.py.

Definition at line 53 of file feedparser.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: