GIF89a;
Direktori : /usr/share/doc/python-docs-2.7.5/html/library/ |
Current File : //usr/share/doc/python-docs-2.7.5/html/library/mimetools.html |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>18.6. mimetools — Tools for parsing MIME messages — Python 2.7.5 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.7.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.5 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="top" title="Python 2.7.5 documentation" href="../index.html" /> <link rel="up" title="18. Internet Data Handling" href="netdata.html" /> <link rel="next" title="18.7. mimetypes — Map filenames to MIME types" href="mimetypes.html" /> <link rel="prev" title="18.5. mhlib — Access to MH mailboxes" href="mhlib.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="mimetypes.html" title="18.7. mimetypes — Map filenames to MIME types" accesskey="N">next</a> |</li> <li class="right" > <a href="mhlib.html" title="18.5. mhlib — Access to MH mailboxes" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="netdata.html" accesskey="U">18. Internet Data Handling</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-mimetools"> <span id="mimetools-tools-for-parsing-mime-messages"></span><h1>18.6. <a class="reference internal" href="#module-mimetools" title="mimetools: Tools for parsing MIME-style message bodies. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">mimetools</span></tt></a> — Tools for parsing MIME messages<a class="headerlink" href="#module-mimetools" title="Permalink to this headline">¶</a></h1> <p class="deprecated"> <span class="versionmodified">Deprecated since version 2.3: </span>The <a class="reference internal" href="email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><tt class="xref py py-mod docutils literal"><span class="pre">email</span></tt></a> package should be used in preference to the <a class="reference internal" href="#module-mimetools" title="mimetools: Tools for parsing MIME-style message bodies. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">mimetools</span></tt></a> module. This module is present only to maintain backward compatibility, and it has been removed in 3.x.</p> <p id="index-0">This module defines a subclass of the <a class="reference internal" href="rfc822.html#module-rfc822" title="rfc822: Parse 2822 style mail messages. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">rfc822</span></tt></a> module’s <a class="reference internal" href="#mimetools.Message" title="mimetools.Message"><tt class="xref py py-class docutils literal"><span class="pre">Message</span></tt></a> class and a number of utility functions that are useful for the manipulation for MIME multipart or encoded message.</p> <p>It defines the following items:</p> <dl class="class"> <dt id="mimetools.Message"> <em class="property">class </em><tt class="descclassname">mimetools.</tt><tt class="descname">Message</tt><big>(</big><em>fp</em><span class="optional">[</span>, <em>seekable</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#mimetools.Message" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new instance of the <a class="reference internal" href="#mimetools.Message" title="mimetools.Message"><tt class="xref py py-class docutils literal"><span class="pre">Message</span></tt></a> class. This is a subclass of the <a class="reference internal" href="rfc822.html#rfc822.Message" title="rfc822.Message"><tt class="xref py py-class docutils literal"><span class="pre">rfc822.Message</span></tt></a> class, with some additional methods (see below). The <em>seekable</em> argument has the same meaning as for <a class="reference internal" href="rfc822.html#rfc822.Message" title="rfc822.Message"><tt class="xref py py-class docutils literal"><span class="pre">rfc822.Message</span></tt></a>.</p> </dd></dl> <dl class="function"> <dt id="mimetools.choose_boundary"> <tt class="descclassname">mimetools.</tt><tt class="descname">choose_boundary</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.choose_boundary" title="Permalink to this definition">¶</a></dt> <dd><p>Return a unique string that has a high likelihood of being usable as a part boundary. The string has the form <tt class="docutils literal"><span class="pre">'hostipaddr.uid.pid.timestamp.random'</span></tt>.</p> </dd></dl> <dl class="function"> <dt id="mimetools.decode"> <tt class="descclassname">mimetools.</tt><tt class="descname">decode</tt><big>(</big><em>input</em>, <em>output</em>, <em>encoding</em><big>)</big><a class="headerlink" href="#mimetools.decode" title="Permalink to this definition">¶</a></dt> <dd><p>Read data encoded using the allowed MIME <em>encoding</em> from open file object <em>input</em> and write the decoded data to open file object <em>output</em>. Valid values for <em>encoding</em> include <tt class="docutils literal"><span class="pre">'base64'</span></tt>, <tt class="docutils literal"><span class="pre">'quoted-printable'</span></tt>, <tt class="docutils literal"><span class="pre">'uuencode'</span></tt>, <tt class="docutils literal"><span class="pre">'x-uuencode'</span></tt>, <tt class="docutils literal"><span class="pre">'uue'</span></tt>, <tt class="docutils literal"><span class="pre">'x-uue'</span></tt>, <tt class="docutils literal"><span class="pre">'7bit'</span></tt>, and <tt class="docutils literal"><span class="pre">'8bit'</span></tt>. Decoding messages encoded in <tt class="docutils literal"><span class="pre">'7bit'</span></tt> or <tt class="docutils literal"><span class="pre">'8bit'</span></tt> has no effect. The input is simply copied to the output.</p> </dd></dl> <dl class="function"> <dt id="mimetools.encode"> <tt class="descclassname">mimetools.</tt><tt class="descname">encode</tt><big>(</big><em>input</em>, <em>output</em>, <em>encoding</em><big>)</big><a class="headerlink" href="#mimetools.encode" title="Permalink to this definition">¶</a></dt> <dd><p>Read data from open file object <em>input</em> and write it encoded using the allowed MIME <em>encoding</em> to open file object <em>output</em>. Valid values for <em>encoding</em> are the same as for <a class="reference internal" href="#mimetools.decode" title="mimetools.decode"><tt class="xref py py-meth docutils literal"><span class="pre">decode()</span></tt></a>.</p> </dd></dl> <dl class="function"> <dt id="mimetools.copyliteral"> <tt class="descclassname">mimetools.</tt><tt class="descname">copyliteral</tt><big>(</big><em>input</em>, <em>output</em><big>)</big><a class="headerlink" href="#mimetools.copyliteral" title="Permalink to this definition">¶</a></dt> <dd><p>Read lines from open file <em>input</em> until EOF and write them to open file <em>output</em>.</p> </dd></dl> <dl class="function"> <dt id="mimetools.copybinary"> <tt class="descclassname">mimetools.</tt><tt class="descname">copybinary</tt><big>(</big><em>input</em>, <em>output</em><big>)</big><a class="headerlink" href="#mimetools.copybinary" title="Permalink to this definition">¶</a></dt> <dd><p>Read blocks until EOF from open file <em>input</em> and write them to open file <em>output</em>. The block size is currently fixed at 8192.</p> </dd></dl> <div class="admonition-see-also admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt>Module <a class="reference internal" href="email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><tt class="xref py py-mod docutils literal"><span class="pre">email</span></tt></a></dt> <dd>Comprehensive email handling package; supersedes the <a class="reference internal" href="#module-mimetools" title="mimetools: Tools for parsing MIME-style message bodies. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">mimetools</span></tt></a> module.</dd> <dt>Module <a class="reference internal" href="rfc822.html#module-rfc822" title="rfc822: Parse 2822 style mail messages. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">rfc822</span></tt></a></dt> <dd>Provides the base class for <a class="reference internal" href="#mimetools.Message" title="mimetools.Message"><tt class="xref py py-class docutils literal"><span class="pre">mimetools.Message</span></tt></a>.</dd> <dt>Module <a class="reference internal" href="multifile.html#module-multifile" title="multifile: Support for reading files which contain distinct parts, such as some MIME data. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">multifile</span></tt></a></dt> <dd>Support for reading files which contain distinct parts, such as MIME data.</dd> <dt><a class="reference external" href="http://faqs.cs.uu.nl/na-dir/mail/mime-faq/.html">http://faqs.cs.uu.nl/na-dir/mail/mime-faq/.html</a></dt> <dd>The MIME Frequently Asked Questions document. For an overview of MIME, see the answer to question 1.1 in Part 1 of this document.</dd> </dl> </div> <div class="section" id="additional-methods-of-message-objects"> <span id="mimetools-message-objects"></span><h2>18.6.1. Additional Methods of Message Objects<a class="headerlink" href="#additional-methods-of-message-objects" title="Permalink to this headline">¶</a></h2> <p>The <a class="reference internal" href="#mimetools.Message" title="mimetools.Message"><tt class="xref py py-class docutils literal"><span class="pre">Message</span></tt></a> class defines the following methods in addition to the <a class="reference internal" href="rfc822.html#rfc822.Message" title="rfc822.Message"><tt class="xref py py-class docutils literal"><span class="pre">rfc822.Message</span></tt></a> methods:</p> <dl class="method"> <dt id="mimetools.Message.getplist"> <tt class="descclassname">Message.</tt><tt class="descname">getplist</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.getplist" title="Permalink to this definition">¶</a></dt> <dd><p>Return the parameter list of the <em class="mailheader">Content-Type</em> header. This is a list of strings. For parameters of the form <tt class="docutils literal"><span class="pre">key=value</span></tt>, <em>key</em> is converted to lower case but <em>value</em> is not. For example, if the message contains the header <tt class="docutils literal"><span class="pre">Content-type:</span> <span class="pre">text/html;</span> <span class="pre">spam=1;</span> <span class="pre">Spam=2;</span> <span class="pre">Spam</span></tt> then <a class="reference internal" href="#mimetools.Message.getplist" title="mimetools.Message.getplist"><tt class="xref py py-meth docutils literal"><span class="pre">getplist()</span></tt></a> will return the Python list <tt class="docutils literal"><span class="pre">['spam=1',</span> <span class="pre">'spam=2',</span> <span class="pre">'Spam']</span></tt>.</p> </dd></dl> <dl class="method"> <dt id="mimetools.Message.getparam"> <tt class="descclassname">Message.</tt><tt class="descname">getparam</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#mimetools.Message.getparam" title="Permalink to this definition">¶</a></dt> <dd><p>Return the <em>value</em> of the first parameter (as returned by <a class="reference internal" href="#mimetools.Message.getplist" title="mimetools.Message.getplist"><tt class="xref py py-meth docutils literal"><span class="pre">getplist()</span></tt></a>) of the form <tt class="docutils literal"><span class="pre">name=value</span></tt> for the given <em>name</em>. If <em>value</em> is surrounded by quotes of the form ‘<tt class="docutils literal"><span class="pre"><</span></tt>...<tt class="docutils literal"><span class="pre">></span></tt>‘ or ‘<tt class="docutils literal"><span class="pre">"</span></tt>...<tt class="docutils literal"><span class="pre">"</span></tt>‘, these are removed.</p> </dd></dl> <dl class="method"> <dt id="mimetools.Message.getencoding"> <tt class="descclassname">Message.</tt><tt class="descname">getencoding</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.getencoding" title="Permalink to this definition">¶</a></dt> <dd><p>Return the encoding specified in the <em class="mailheader">Content-Transfer-Encoding</em> message header. If no such header exists, return <tt class="docutils literal"><span class="pre">'7bit'</span></tt>. The encoding is converted to lower case.</p> </dd></dl> <dl class="method"> <dt id="mimetools.Message.gettype"> <tt class="descclassname">Message.</tt><tt class="descname">gettype</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.gettype" title="Permalink to this definition">¶</a></dt> <dd><p>Return the message type (of the form <tt class="docutils literal"><span class="pre">type/subtype</span></tt>) as specified in the <em class="mailheader">Content-Type</em> header. If no such header exists, return <tt class="docutils literal"><span class="pre">'text/plain'</span></tt>. The type is converted to lower case.</p> </dd></dl> <dl class="method"> <dt id="mimetools.Message.getmaintype"> <tt class="descclassname">Message.</tt><tt class="descname">getmaintype</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.getmaintype" title="Permalink to this definition">¶</a></dt> <dd><p>Return the main type as specified in the <em class="mailheader">Content-Type</em> header. If no such header exists, return <tt class="docutils literal"><span class="pre">'text'</span></tt>. The main type is converted to lower case.</p> </dd></dl> <dl class="method"> <dt id="mimetools.Message.getsubtype"> <tt class="descclassname">Message.</tt><tt class="descname">getsubtype</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.getsubtype" title="Permalink to this definition">¶</a></dt> <dd><p>Return the subtype as specified in the <em class="mailheader">Content-Type</em> header. If no such header exists, return <tt class="docutils literal"><span class="pre">'plain'</span></tt>. The subtype is converted to lower case.</p> </dd></dl> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">18.6. <tt class="docutils literal"><span class="pre">mimetools</span></tt> — Tools for parsing MIME messages</a><ul> <li><a class="reference internal" href="#additional-methods-of-message-objects">18.6.1. Additional Methods of Message Objects</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="mhlib.html" title="previous chapter">18.5. <tt class="docutils literal"><span class="pre">mhlib</span></tt> — Access to MH mailboxes</a></p> <h4>Next topic</h4> <p class="topless"><a href="mimetypes.html" title="next chapter">18.7. <tt class="docutils literal"><span class="pre">mimetypes</span></tt> — Map filenames to MIME types</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li><a href="../_sources/library/mimetools.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="mimetypes.html" title="18.7. mimetypes — Map filenames to MIME types" >next</a> |</li> <li class="right" > <a href="mhlib.html" title="18.5. mhlib — Access to MH mailboxes" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="netdata.html" >18. Internet Data Handling</a> »</li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="http://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Jul 03, 2019. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>