Sophie

Sophie

distrib > Mandriva > 10.1 > i586 > by-pkgid > ccf83290023404568bb21aa0163b385f > files > 499

python-docs-2.3.4-6.2.101mdk.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.gif" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<LINK rel="next" href="node508.html">
<LINK rel="prev" href="module-email.Utils.html">
<LINK rel="parent" href="module-email.html">
<LINK rel="next" href="node508.html">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name='aesop' content='information' />
<META name="description" content="Iterators">
<META name="keywords" content="lib">
<META name="resource-type" content="document">
<META name="distribution" content="global">
<title>12.2.10 Iterators</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="12.2.9 Miscellaneous utilities" 
  href="module-email.Utils.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="12.2 email  " 
  href="module-email.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="12.2.11 Differences from email" 
  href="node508.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents" 
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index" 
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-email.Utils.html">12.2.9 Miscellaneous utilities</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-email.html">12.2 email  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="node508.html">12.2.11 Differences from email</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION00142100000000000000000">
12.2.10 Iterators</A>
</H2>
<A NAME="module-email.Iterators"><!--z--></A>

<P>
Iterating over a message object tree is fairly easy with the
<tt class="method">Message.walk()</tt> method.  The <tt class="module">email.Iterators</tt> module
provides some useful higher level iterations over message object
trees.

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3667' class="function">body_line_iterator</tt></b>(</nobr></td>
  <td><var>msg</var><big>[</big><var>, decode</var><big>]</big>)</td></tr></table></dt>
<dd>
This iterates over all the payloads in all the subparts of <var>msg</var>,
returning the string payloads line-by-line.  It skips over all the
subpart headers, and it skips over any subpart with a payload that
isn't a Python string.  This is somewhat equivalent to reading the
flat text representation of the message from a file using
<tt class="method">readline()</tt>, skipping over all the intervening headers.

<P>
Optional <var>decode</var> is passed through to <tt class="method">Message.get_payload()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3668' class="function">typed_subpart_iterator</tt></b>(</nobr></td>
  <td><var>msg</var><big>[</big><var>,
    maintype</var><big>[</big><var>, subtype</var><big>]</big><big>]</big>)</td></tr></table></dt>
<dd>
This iterates over all the subparts of <var>msg</var>, returning only those
subparts that match the MIME type specified by <var>maintype</var> and
<var>subtype</var>.

<P>
Note that <var>subtype</var> is optional; if omitted, then subpart MIME
type matching is done only with the main type.  <var>maintype</var> is
optional too; it defaults to <span class="mimetype">text</span>.

<P>
Thus, by default <tt class="function">typed_subpart_iterator()</tt> returns each
subpart that has a MIME type of <span class="mimetype">text/*</span>.
</dl>

<P>
The following function has been added as a useful debugging tool.  It
should <i>not</i> be considered part of the supported public interface
for the package.

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3669' class="function">_structure</tt></b>(</nobr></td>
  <td><var>msg</var><big>[</big><var>, fp</var><big>[</big><var>, level</var><big>]</big><big>]</big>)</td></tr></table></dt>
<dd>
Prints an indented representation of the content types of the
message object structure.  For example:

<P>
<div class="verbatim"><pre>
&gt;&gt;&gt; msg = email.message_from_file(somefile)
&gt;&gt;&gt; _structure(msg)
multipart/mixed
    text/plain
    text/plain
    multipart/digest
        message/rfc822
            text/plain
        message/rfc822
            text/plain
        message/rfc822
            text/plain
        message/rfc822
            text/plain
        message/rfc822
            text/plain
    text/plain
</pre></div>

<P>
Optional <var>fp</var> is a file-like object to print the output to.  It
must be suitable for Python's extended print statement.  <var>level</var>
is used internally.
</dl>

<P>

<DIV CLASS="navigation">
<div class='online-navigation'><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="12.2.9 Miscellaneous utilities" 
  rel="prev" title="12.2.9 Miscellaneous utilities" 
  href="module-email.Utils.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="12.2 email  " 
  rel="parent" title="12.2 email  " 
  href="module-email.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="12.2.11 Differences from email" 
  rel="next" title="12.2.11 Differences from email" 
  href="node508.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents" 
  rel="contents" title="Table of Contents" 
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index" 
  rel="index" title="Index" 
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-email.Utils.html">12.2.9 Miscellaneous utilities</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-email.html">12.2 email  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="node508.html">12.2.11 Differences from email</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.3.4, documentation updated on May 20, 2004.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>