~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-3.5.1-docs-html/library/mailcap.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
 
 
4
 
 
5
 
<html xmlns="http://www.w3.org/1999/xhtml">
6
 
  <head>
7
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
 
    
9
 
    <title>19.3. mailcap — Mailcap file handling &mdash; Python 3.5.1 documentation</title>
10
 
    
11
 
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
12
 
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
 
    
14
 
    <script type="text/javascript">
15
 
      var DOCUMENTATION_OPTIONS = {
16
 
        URL_ROOT:    '../',
17
 
        VERSION:     '3.5.1',
18
 
        COLLAPSE_INDEX: false,
19
 
        FILE_SUFFIX: '.html',
20
 
        HAS_SOURCE:  true
21
 
      };
22
 
    </script>
23
 
    <script type="text/javascript" src="../_static/jquery.js"></script>
24
 
    <script type="text/javascript" src="../_static/underscore.js"></script>
25
 
    <script type="text/javascript" src="../_static/doctools.js"></script>
26
 
    <script type="text/javascript" src="../_static/sidebar.js"></script>
27
 
    <link rel="search" type="application/opensearchdescription+xml"
28
 
          title="Search within Python 3.5.1 documentation"
29
 
          href="../_static/opensearch.xml"/>
30
 
    <link rel="author" title="About these documents" href="../about.html" />
31
 
    <link rel="copyright" title="Copyright" href="../copyright.html" />
32
 
    <link rel="top" title="Python 3.5.1 documentation" href="../contents.html" />
33
 
    <link rel="up" title="19. Internet Data Handling" href="netdata.html" />
34
 
    <link rel="next" title="19.4. mailbox — Manipulate mailboxes in various formats" href="mailbox.html" />
35
 
    <link rel="prev" title="19.2. json — JSON encoder and decoder" href="json.html" />
36
 
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
 
    <script type="text/javascript" src="../_static/copybutton.js"></script>
38
 
    <script type="text/javascript" src="../_static/version_switch.js"></script>
39
 
    
40
 
 
41
 
 
42
 
  </head>
43
 
  <body role="document">  
44
 
    <div class="related" role="navigation" aria-label="related navigation">
45
 
      <h3>Navigation</h3>
46
 
      <ul>
47
 
        <li class="right" style="margin-right: 10px">
48
 
          <a href="../genindex.html" title="General Index"
49
 
             accesskey="I">index</a></li>
50
 
        <li class="right" >
51
 
          <a href="../py-modindex.html" title="Python Module Index"
52
 
             >modules</a> |</li>
53
 
        <li class="right" >
54
 
          <a href="mailbox.html" title="19.4. mailbox — Manipulate mailboxes in various formats"
55
 
             accesskey="N">next</a> |</li>
56
 
        <li class="right" >
57
 
          <a href="json.html" title="19.2. json — JSON encoder and decoder"
58
 
             accesskey="P">previous</a> |</li>
59
 
        <li><img src="../_static/py.png" alt=""
60
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
61
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
62
 
        <li>
63
 
          <span class="version_switcher_placeholder">3.5.1</span>
64
 
          <a href="../index.html">Documentation </a> &raquo;
65
 
        </li>
66
 
 
67
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
68
 
          <li class="nav-item nav-item-2"><a href="netdata.html" accesskey="U">19. Internet Data Handling</a> &raquo;</li> 
69
 
      </ul>
70
 
    </div>    
71
 
 
72
 
    <div class="document">
73
 
      <div class="documentwrapper">
74
 
        <div class="bodywrapper">
75
 
          <div class="body" role="main">
76
 
            
77
 
  <div class="section" id="module-mailcap">
78
 
<span id="mailcap-mailcap-file-handling"></span><h1>19.3. <a class="reference internal" href="#module-mailcap" title="mailcap: Mailcap file handling."><code class="xref py py-mod docutils literal"><span class="pre">mailcap</span></code></a> &#8212; Mailcap file handling<a class="headerlink" href="#module-mailcap" title="Permalink to this headline">¶</a></h1>
79
 
<p><strong>Source code:</strong> <a class="reference external" href="https://hg.python.org/cpython/file/3.5/Lib/mailcap.py">Lib/mailcap.py</a></p>
80
 
<hr class="docutils" />
81
 
<p>Mailcap files are used to configure how MIME-aware applications such as mail
82
 
readers and Web browsers react to files with different MIME types. (The name
83
 
&#8220;mailcap&#8221; is derived from the phrase &#8220;mail capability&#8221;.)  For example, a mailcap
84
 
file might contain a line like <code class="docutils literal"><span class="pre">video/mpeg;</span> <span class="pre">xmpeg</span> <span class="pre">%s</span></code>.  Then, if the user
85
 
encounters an email message or Web document with the MIME type
86
 
<em class="mimetype">video/mpeg</em>, <code class="docutils literal"><span class="pre">%s</span></code> will be replaced by a filename (usually one
87
 
belonging to a temporary file) and the <strong class="program">xmpeg</strong> program can be
88
 
automatically started to view the file.</p>
89
 
<p>The mailcap format is documented in <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc1524.html"><strong>RFC 1524</strong></a>, &#8220;A User Agent Configuration
90
 
Mechanism For Multimedia Mail Format Information,&#8221; but is not an Internet
91
 
standard.  However, mailcap files are supported on most Unix systems.</p>
92
 
<dl class="function">
93
 
<dt id="mailcap.findmatch">
94
 
<code class="descclassname">mailcap.</code><code class="descname">findmatch</code><span class="sig-paren">(</span><em>caps</em>, <em>MIMEtype</em>, <em>key='view'</em>, <em>filename='/dev/null'</em>, <em>plist=[]</em><span class="sig-paren">)</span><a class="headerlink" href="#mailcap.findmatch" title="Permalink to this definition">¶</a></dt>
95
 
<dd><p>Return a 2-tuple; the first element is a string containing the command line to
96
 
be executed (which can be passed to <a class="reference internal" href="os.html#os.system" title="os.system"><code class="xref py py-func docutils literal"><span class="pre">os.system()</span></code></a>), and the second element
97
 
is the mailcap entry for a given MIME type.  If no matching MIME type can be
98
 
found, <code class="docutils literal"><span class="pre">(None,</span> <span class="pre">None)</span></code> is returned.</p>
99
 
<p><em>key</em> is the name of the field desired, which represents the type of activity to
100
 
be performed; the default value is &#8216;view&#8217;, since in the  most common case you
101
 
simply want to view the body of the MIME-typed data.  Other possible values
102
 
might be &#8216;compose&#8217; and &#8216;edit&#8217;, if you wanted to create a new body of the given
103
 
MIME type or alter the existing body data.  See <span class="target" id="index-1"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc1524.html"><strong>RFC 1524</strong></a> for a complete list
104
 
of these fields.</p>
105
 
<p><em>filename</em> is the filename to be substituted for <code class="docutils literal"><span class="pre">%s</span></code> in the command line; the
106
 
default value is <code class="docutils literal"><span class="pre">'/dev/null'</span></code> which is almost certainly not what you want, so
107
 
usually you&#8217;ll override it by specifying a filename.</p>
108
 
<p><em>plist</em> can be a list containing named parameters; the default value is simply
109
 
an empty list.  Each entry in the list must be a string containing the parameter
110
 
name, an equals sign (<code class="docutils literal"><span class="pre">'='</span></code>), and the parameter&#8217;s value.  Mailcap entries can
111
 
contain  named parameters like <code class="docutils literal"><span class="pre">%{foo}</span></code>, which will be replaced by the value
112
 
of the parameter named &#8216;foo&#8217;.  For example, if the command line <code class="docutils literal"><span class="pre">showpartial</span>
113
 
<span class="pre">%{id}</span> <span class="pre">%{number}</span> <span class="pre">%{total}</span></code> was in a mailcap file, and <em>plist</em> was set to
114
 
<code class="docutils literal"><span class="pre">['id=1',</span> <span class="pre">'number=2',</span> <span class="pre">'total=3']</span></code>, the resulting command line would be
115
 
<code class="docutils literal"><span class="pre">'showpartial</span> <span class="pre">1</span> <span class="pre">2</span> <span class="pre">3'</span></code>.</p>
116
 
<p>In a mailcap file, the &#8220;test&#8221; field can optionally be specified to test some
117
 
external condition (such as the machine architecture, or the window system in
118
 
use) to determine whether or not the mailcap line applies.  <a class="reference internal" href="#mailcap.findmatch" title="mailcap.findmatch"><code class="xref py py-func docutils literal"><span class="pre">findmatch()</span></code></a>
119
 
will automatically check such conditions and skip the entry if the check fails.</p>
120
 
</dd></dl>
121
 
 
122
 
<dl class="function">
123
 
<dt id="mailcap.getcaps">
124
 
<code class="descclassname">mailcap.</code><code class="descname">getcaps</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailcap.getcaps" title="Permalink to this definition">¶</a></dt>
125
 
<dd><p>Returns a dictionary mapping MIME types to a list of mailcap file entries. This
126
 
dictionary must be passed to the <a class="reference internal" href="#mailcap.findmatch" title="mailcap.findmatch"><code class="xref py py-func docutils literal"><span class="pre">findmatch()</span></code></a> function.  An entry is stored
127
 
as a list of dictionaries, but it shouldn&#8217;t be necessary to know the details of
128
 
this representation.</p>
129
 
<p>The information is derived from all of the mailcap files found on the system.
130
 
Settings in the user&#8217;s mailcap file <code class="file docutils literal"><span class="pre">$HOME/.mailcap</span></code> will override
131
 
settings in the system mailcap files <code class="file docutils literal"><span class="pre">/etc/mailcap</span></code>,
132
 
<code class="file docutils literal"><span class="pre">/usr/etc/mailcap</span></code>, and <code class="file docutils literal"><span class="pre">/usr/local/etc/mailcap</span></code>.</p>
133
 
</dd></dl>
134
 
 
135
 
<p>An example usage:</p>
136
 
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">mailcap</span>
137
 
<span class="gp">&gt;&gt;&gt; </span><span class="n">d</span><span class="o">=</span><span class="n">mailcap</span><span class="o">.</span><span class="n">getcaps</span><span class="p">()</span>
138
 
<span class="gp">&gt;&gt;&gt; </span><span class="n">mailcap</span><span class="o">.</span><span class="n">findmatch</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="s1">&#39;video/mpeg&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="s1">&#39;tmp1223&#39;</span><span class="p">)</span>
139
 
<span class="go">(&#39;xmpeg tmp1223&#39;, {&#39;view&#39;: &#39;xmpeg %s&#39;})</span>
140
 
</pre></div>
141
 
</div>
142
 
</div>
143
 
 
144
 
 
145
 
          </div>
146
 
        </div>
147
 
      </div>
148
 
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
149
 
        <div class="sphinxsidebarwrapper">
150
 
  <h4>Previous topic</h4>
151
 
  <p class="topless"><a href="json.html"
152
 
                        title="previous chapter">19.2. <code class="docutils literal"><span class="pre">json</span></code> &#8212; JSON encoder and decoder</a></p>
153
 
  <h4>Next topic</h4>
154
 
  <p class="topless"><a href="mailbox.html"
155
 
                        title="next chapter">19.4. <code class="docutils literal"><span class="pre">mailbox</span></code> &#8212; Manipulate mailboxes in various formats</a></p>
156
 
<h3>This Page</h3>
157
 
<ul class="this-page-menu">
158
 
  <li><a href="../bugs.html">Report a Bug</a></li>
159
 
  <li><a href="../_sources/library/mailcap.txt"
160
 
         rel="nofollow">Show Source</a></li>
161
 
</ul>
162
 
 
163
 
<div id="searchbox" style="display: none" role="search">
164
 
  <h3>Quick search</h3>
165
 
    <form class="search" action="../search.html" method="get">
166
 
      <input type="text" name="q" />
167
 
      <input type="submit" value="Go" />
168
 
      <input type="hidden" name="check_keywords" value="yes" />
169
 
      <input type="hidden" name="area" value="default" />
170
 
    </form>
171
 
    <p class="searchtip" style="font-size: 90%">
172
 
    Enter search terms or a module, class or function name.
173
 
    </p>
174
 
</div>
175
 
<script type="text/javascript">$('#searchbox').show(0);</script>
176
 
        </div>
177
 
      </div>
178
 
      <div class="clearer"></div>
179
 
    </div>  
180
 
    <div class="related" role="navigation" aria-label="related navigation">
181
 
      <h3>Navigation</h3>
182
 
      <ul>
183
 
        <li class="right" style="margin-right: 10px">
184
 
          <a href="../genindex.html" title="General Index"
185
 
             >index</a></li>
186
 
        <li class="right" >
187
 
          <a href="../py-modindex.html" title="Python Module Index"
188
 
             >modules</a> |</li>
189
 
        <li class="right" >
190
 
          <a href="mailbox.html" title="19.4. mailbox — Manipulate mailboxes in various formats"
191
 
             >next</a> |</li>
192
 
        <li class="right" >
193
 
          <a href="json.html" title="19.2. json — JSON encoder and decoder"
194
 
             >previous</a> |</li>
195
 
        <li><img src="../_static/py.png" alt=""
196
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
197
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
198
 
        <li>
199
 
          <span class="version_switcher_placeholder">3.5.1</span>
200
 
          <a href="../index.html">Documentation </a> &raquo;
201
 
        </li>
202
 
 
203
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
204
 
          <li class="nav-item nav-item-2"><a href="netdata.html" >19. Internet Data Handling</a> &raquo;</li> 
205
 
      </ul>
206
 
    </div>  
207
 
    <div class="footer">
208
 
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
209
 
    <br />
210
 
    The Python Software Foundation is a non-profit corporation.
211
 
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
212
 
    <br />
213
 
    Last updated on Jan 22, 2016.
214
 
    <a href="../bugs.html">Found a bug</a>?
215
 
    <br />
216
 
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
217
 
    </div>
218
 
 
219
 
  </body>
220
 
</html>
 
 
b'\\ No newline at end of file'