Back to index

python3.2  3.2.2
Functions | Variables
email.iterators Namespace Reference

Functions

def walk
def body_line_iterator
def typed_subpart_iterator
def _structure

Variables

list __all__

Function Documentation

def email.iterators._structure (   msg,
  fp = None,
  level = 0,
  include_default = False 
) [private]
A handy debugging aid

Definition at line 61 of file iterators.py.

00061 
00062 def _structure(msg, fp=None, level=0, include_default=False):
00063     """A handy debugging aid"""
00064     if fp is None:
00065         fp = sys.stdout
00066     tab = ' ' * (level * 4)
00067     print(tab + msg.get_content_type(), end='', file=fp)
00068     if include_default:
00069         print(' [%s]' % msg.get_default_type(), file=fp)
00070     else:
00071         print(file=fp)
00072     if msg.is_multipart():
00073         for subpart in msg.get_payload():
00074             _structure(subpart, fp, level+1, include_default)

Here is the caller graph for this function:

def email.iterators.body_line_iterator (   msg,
  decode = False 
)
Iterate over the parts, returning string payloads line-by-line.

Optional decode (default False) is passed through to .get_payload().

Definition at line 35 of file iterators.py.

00035 
00036 def body_line_iterator(msg, decode=False):
00037     """Iterate over the parts, returning string payloads line-by-line.
00038 
00039     Optional decode (default False) is passed through to .get_payload().
00040     """
00041     for subpart in msg.walk():
00042         payload = subpart.get_payload(decode=decode)
00043         if isinstance(payload, str):
00044             for line in StringIO(payload):
00045                 yield line
00046 

def email.iterators.typed_subpart_iterator (   msg,
  maintype = 'text',
  subtype = None 
)
Iterate over the subparts with a given MIME type.

Use `maintype' as the main MIME type to match against; this defaults to
"text".  Optional `subtype' is the MIME subtype to match against; if
omitted, only the main type is matched.

Definition at line 47 of file iterators.py.

00047 
00048 def typed_subpart_iterator(msg, maintype='text', subtype=None):
00049     """Iterate over the subparts with a given MIME type.
00050 
00051     Use `maintype' as the main MIME type to match against; this defaults to
00052     "text".  Optional `subtype' is the MIME subtype to match against; if
00053     omitted, only the main type is matched.
00054     """
00055     for subpart in msg.walk():
00056         if subpart.get_content_maintype() == maintype:
00057             if subtype is None or subpart.get_content_subtype() == subtype:
00058                 yield subpart
00059 
00060 

def email.iterators.walk (   self)
Walk over the message tree, yielding each subpart.

The walk is performed in depth-first order.  This method is a
generator.

Definition at line 20 of file iterators.py.

00020 
00021 def walk(self):
00022     """Walk over the message tree, yielding each subpart.
00023 
00024     The walk is performed in depth-first order.  This method is a
00025     generator.
00026     """
00027     yield self
00028     if self.is_multipart():
00029         for subpart in self.get_payload():
00030             for subsubpart in subpart.walk():
00031                 yield subsubpart
00032 
00033 
00034 
# These two functions are imported into the Iterators.py interface module.

Variable Documentation

Initial value:
00001 [
00002     'body_line_iterator',
00003     'typed_subpart_iterator',
00004     'walk',
00005     # Do not include _structure() since it's part of the debugging API.
00006     ]

Definition at line 7 of file iterators.py.