晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /usr/share/doc/python2-docs/html/library/ |
Upload File : |
<!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="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>18.7. mimetypes — Map filenames to MIME types — Python 2.7.16 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></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.16 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="18.8. MimeWriter — Generic MIME file writer" href="mimewriter.html" />
<link rel="prev" title="18.6. mimetools — Tools for parsing MIME messages" href="mimetools.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="https://docs.python.org/2/library/mimetypes.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<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="mimewriter.html" title="18.8. MimeWriter — Generic MIME file writer"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="mimetools.html" title="18.6. mimetools — Tools for parsing MIME messages"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<a href="../index.html">Python 2.7.16 documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
<li class="nav-item nav-item-2"><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" role="main">
<div class="section" id="module-mimetypes">
<span id="mimetypes-map-filenames-to-mime-types"></span><h1>18.7. <a class="reference internal" href="#module-mimetypes" title="mimetypes: Mapping of filename extensions to MIME types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">mimetypes</span></code></a> — Map filenames to MIME types<a class="headerlink" href="#module-mimetypes" title="Permalink to this headline">¶</a></h1>
<p id="index-0"><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/2.7/Lib/mimetypes.py">Lib/mimetypes.py</a></p>
<hr class="docutils" />
<p>The <a class="reference internal" href="#module-mimetypes" title="mimetypes: Mapping of filename extensions to MIME types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">mimetypes</span></code></a> module converts between a filename or URL and the MIME type
associated with the filename extension. Conversions are provided from filename
to MIME type and from MIME type to filename extension; encodings are not
supported for the latter conversion.</p>
<p>The module provides one class and a number of convenience functions. The
functions are the normal interface to this module, but some applications may be
interested in the class as well.</p>
<p>The functions described below provide the primary interface for this module. If
the module has not been initialized, they will call <a class="reference internal" href="#mimetypes.init" title="mimetypes.init"><code class="xref py py-func docutils literal notranslate"><span class="pre">init()</span></code></a> if they rely on
the information <a class="reference internal" href="#mimetypes.init" title="mimetypes.init"><code class="xref py py-func docutils literal notranslate"><span class="pre">init()</span></code></a> sets up.</p>
<dl class="function">
<dt id="mimetypes.guess_type">
<code class="descclassname">mimetypes.</code><code class="descname">guess_type</code><span class="sig-paren">(</span><em>url</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.guess_type" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-1">Guess the type of a file based on its filename or URL, given by <em>url</em>. The
return value is a tuple <code class="docutils literal notranslate"><span class="pre">(type,</span> <span class="pre">encoding)</span></code> where <em>type</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code> if the
type can’t be guessed (missing or unknown suffix) or a string of the form
<code class="docutils literal notranslate"><span class="pre">'type/subtype'</span></code>, usable for a MIME <em class="mailheader">content-type</em> header.</p>
<p><em>encoding</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code> for no encoding or the name of the program used to encode
(e.g. <strong class="program">compress</strong> or <strong class="program">gzip</strong>). The encoding is suitable for use
as a <em class="mailheader">Content-Encoding</em> header, <strong>not</strong> as a
<em class="mailheader">Content-Transfer-Encoding</em> header. The mappings are table driven.
Encoding suffixes are case sensitive; type suffixes are first tried case
sensitively, then case insensitively.</p>
<p>The optional <em>strict</em> argument is a flag specifying whether the list of known MIME types
is limited to only the official types <a class="reference external" href="https://www.iana.org/assignments/media-types/media-types.xhtml">registered with IANA</a>.
When <em>strict</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code> (the default), only the IANA types are supported; when
<em>strict</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, some additional non-standard but commonly used MIME types
are also recognized.</p>
</dd></dl>
<dl class="function">
<dt id="mimetypes.guess_all_extensions">
<code class="descclassname">mimetypes.</code><code class="descname">guess_all_extensions</code><span class="sig-paren">(</span><em>type</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.guess_all_extensions" title="Permalink to this definition">¶</a></dt>
<dd><p>Guess the extensions for a file based on its MIME type, given by <em>type</em>. The
return value is a list of strings giving all possible filename extensions,
including the leading dot (<code class="docutils literal notranslate"><span class="pre">'.'</span></code>). The extensions are not guaranteed to have
been associated with any particular data stream, but would be mapped to the MIME
type <em>type</em> by <a class="reference internal" href="#mimetypes.guess_type" title="mimetypes.guess_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_type()</span></code></a>.</p>
<p>The optional <em>strict</em> argument has the same meaning as with the <a class="reference internal" href="#mimetypes.guess_type" title="mimetypes.guess_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_type()</span></code></a> function.</p>
</dd></dl>
<dl class="function">
<dt id="mimetypes.guess_extension">
<code class="descclassname">mimetypes.</code><code class="descname">guess_extension</code><span class="sig-paren">(</span><em>type</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.guess_extension" title="Permalink to this definition">¶</a></dt>
<dd><p>Guess the extension for a file based on its MIME type, given by <em>type</em>. The
return value is a string giving a filename extension, including the leading dot
(<code class="docutils literal notranslate"><span class="pre">'.'</span></code>). The extension is not guaranteed to have been associated with any
particular data stream, but would be mapped to the MIME type <em>type</em> by
<a class="reference internal" href="#mimetypes.guess_type" title="mimetypes.guess_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_type()</span></code></a>. If no extension can be guessed for <em>type</em>, <code class="docutils literal notranslate"><span class="pre">None</span></code> is
returned.</p>
<p>The optional <em>strict</em> argument has the same meaning as with the <a class="reference internal" href="#mimetypes.guess_type" title="mimetypes.guess_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_type()</span></code></a> function.</p>
</dd></dl>
<p>Some additional functions and data items are available for controlling the
behavior of the module.</p>
<dl class="function">
<dt id="mimetypes.init">
<code class="descclassname">mimetypes.</code><code class="descname">init</code><span class="sig-paren">(</span><em>files=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.init" title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize the internal data structures. If given, <em>files</em> must be a sequence
of file names which should be used to augment the default type map. If omitted,
the file names to use are taken from <a class="reference internal" href="#mimetypes.knownfiles" title="mimetypes.knownfiles"><code class="xref py py-const docutils literal notranslate"><span class="pre">knownfiles</span></code></a>; on Windows, the
current registry settings are loaded. Each file named in <em>files</em> or
<a class="reference internal" href="#mimetypes.knownfiles" title="mimetypes.knownfiles"><code class="xref py py-const docutils literal notranslate"><span class="pre">knownfiles</span></code></a> takes precedence over those named before it. Calling
<a class="reference internal" href="#mimetypes.init" title="mimetypes.init"><code class="xref py py-func docutils literal notranslate"><span class="pre">init()</span></code></a> repeatedly is allowed.</p>
<p>Specifying an empty list for <em>files</em> will prevent the system defaults from
being applied: only the well-known values will be present from a built-in list.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.7: </span>Previously, Windows registry settings were ignored.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="mimetypes.read_mime_types">
<code class="descclassname">mimetypes.</code><code class="descname">read_mime_types</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.read_mime_types" title="Permalink to this definition">¶</a></dt>
<dd><p>Load the type map given in the file <em>filename</em>, if it exists. The type map is
returned as a dictionary mapping filename extensions, including the leading dot
(<code class="docutils literal notranslate"><span class="pre">'.'</span></code>), to strings of the form <code class="docutils literal notranslate"><span class="pre">'type/subtype'</span></code>. If the file <em>filename</em>
does not exist or cannot be read, <code class="docutils literal notranslate"><span class="pre">None</span></code> is returned.</p>
</dd></dl>
<dl class="function">
<dt id="mimetypes.add_type">
<code class="descclassname">mimetypes.</code><code class="descname">add_type</code><span class="sig-paren">(</span><em>type</em>, <em>ext</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.add_type" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a mapping from the MIME type <em>type</em> to the extension <em>ext</em>. When the
extension is already known, the new type will replace the old one. When the type
is already known the extension will be added to the list of known extensions.</p>
<p>When <em>strict</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code> (the default), the mapping will be added to the
official MIME types, otherwise to the non-standard ones.</p>
</dd></dl>
<dl class="data">
<dt id="mimetypes.inited">
<code class="descclassname">mimetypes.</code><code class="descname">inited</code><a class="headerlink" href="#mimetypes.inited" title="Permalink to this definition">¶</a></dt>
<dd><p>Flag indicating whether or not the global data structures have been initialized.
This is set to <code class="docutils literal notranslate"><span class="pre">True</span></code> by <a class="reference internal" href="#mimetypes.init" title="mimetypes.init"><code class="xref py py-func docutils literal notranslate"><span class="pre">init()</span></code></a>.</p>
</dd></dl>
<dl class="data">
<dt id="mimetypes.knownfiles">
<code class="descclassname">mimetypes.</code><code class="descname">knownfiles</code><a class="headerlink" href="#mimetypes.knownfiles" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-2">List of type map file names commonly installed. These files are typically named
<code class="file docutils literal notranslate"><span class="pre">mime.types</span></code> and are installed in different locations by different
packages.</p>
</dd></dl>
<dl class="data">
<dt id="mimetypes.suffix_map">
<code class="descclassname">mimetypes.</code><code class="descname">suffix_map</code><a class="headerlink" href="#mimetypes.suffix_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping suffixes to suffixes. This is used to allow recognition of
encoded files for which the encoding and the type are indicated by the same
extension. For example, the <code class="file docutils literal notranslate"><span class="pre">.tgz</span></code> extension is mapped to <code class="file docutils literal notranslate"><span class="pre">.tar.gz</span></code>
to allow the encoding and type to be recognized separately.</p>
</dd></dl>
<dl class="data">
<dt id="mimetypes.encodings_map">
<code class="descclassname">mimetypes.</code><code class="descname">encodings_map</code><a class="headerlink" href="#mimetypes.encodings_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping filename extensions to encoding types.</p>
</dd></dl>
<dl class="data">
<dt id="mimetypes.types_map">
<code class="descclassname">mimetypes.</code><code class="descname">types_map</code><a class="headerlink" href="#mimetypes.types_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping filename extensions to MIME types.</p>
</dd></dl>
<dl class="data">
<dt id="mimetypes.common_types">
<code class="descclassname">mimetypes.</code><code class="descname">common_types</code><a class="headerlink" href="#mimetypes.common_types" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping filename extensions to non-standard, but commonly found MIME
types.</p>
</dd></dl>
<p>An example usage of the module:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">mimetypes</span>
<span class="gp">>>> </span><span class="n">mimetypes</span><span class="o">.</span><span class="n">init</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">mimetypes</span><span class="o">.</span><span class="n">knownfiles</span>
<span class="go">['/etc/mime.types', '/etc/httpd/mime.types', ... ]</span>
<span class="gp">>>> </span><span class="n">mimetypes</span><span class="o">.</span><span class="n">suffix_map</span><span class="p">[</span><span class="s1">'.tgz'</span><span class="p">]</span>
<span class="go">'.tar.gz'</span>
<span class="gp">>>> </span><span class="n">mimetypes</span><span class="o">.</span><span class="n">encodings_map</span><span class="p">[</span><span class="s1">'.gz'</span><span class="p">]</span>
<span class="go">'gzip'</span>
<span class="gp">>>> </span><span class="n">mimetypes</span><span class="o">.</span><span class="n">types_map</span><span class="p">[</span><span class="s1">'.tgz'</span><span class="p">]</span>
<span class="go">'application/x-tar-gz'</span>
</pre></div>
</div>
<div class="section" id="mimetypes-objects">
<span id="id1"></span><h2>18.7.1. MimeTypes Objects<a class="headerlink" href="#mimetypes-objects" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#mimetypes.MimeTypes" title="mimetypes.MimeTypes"><code class="xref py py-class docutils literal notranslate"><span class="pre">MimeTypes</span></code></a> class may be useful for applications which may want more
than one MIME-type database; it provides an interface similar to the one of the
<a class="reference internal" href="#module-mimetypes" title="mimetypes: Mapping of filename extensions to MIME types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">mimetypes</span></code></a> module.</p>
<dl class="class">
<dt id="mimetypes.MimeTypes">
<em class="property">class </em><code class="descclassname">mimetypes.</code><code class="descname">MimeTypes</code><span class="sig-paren">(</span><em>filenames=()</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.MimeTypes" title="Permalink to this definition">¶</a></dt>
<dd><p>This class represents a MIME-types database. By default, it provides access to
the same database as the rest of this module. The initial database is a copy of
that provided by the module, and may be extended by loading additional
<code class="file docutils literal notranslate"><span class="pre">mime.types</span></code>-style files into the database using the <a class="reference internal" href="#mimetypes.MimeTypes.read" title="mimetypes.MimeTypes.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code></a> or
<a class="reference internal" href="#mimetypes.MimeTypes.readfp" title="mimetypes.MimeTypes.readfp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">readfp()</span></code></a> methods. The mapping dictionaries may also be cleared before
loading additional data if the default data is not desired.</p>
<p>The optional <em>filenames</em> parameter can be used to cause additional files to be
loaded “on top” of the default database.</p>
<dl class="attribute">
<dt id="mimetypes.MimeTypes.suffix_map">
<code class="descname">suffix_map</code><a class="headerlink" href="#mimetypes.MimeTypes.suffix_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping suffixes to suffixes. This is used to allow recognition of
encoded files for which the encoding and the type are indicated by the same
extension. For example, the <code class="file docutils literal notranslate"><span class="pre">.tgz</span></code> extension is mapped to <code class="file docutils literal notranslate"><span class="pre">.tar.gz</span></code>
to allow the encoding and type to be recognized separately. This is initially a
copy of the global <a class="reference internal" href="#mimetypes.suffix_map" title="mimetypes.suffix_map"><code class="xref py py-data docutils literal notranslate"><span class="pre">suffix_map</span></code></a> defined in the module.</p>
</dd></dl>
<dl class="attribute">
<dt id="mimetypes.MimeTypes.encodings_map">
<code class="descname">encodings_map</code><a class="headerlink" href="#mimetypes.MimeTypes.encodings_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping filename extensions to encoding types. This is initially a
copy of the global <a class="reference internal" href="#mimetypes.encodings_map" title="mimetypes.encodings_map"><code class="xref py py-data docutils literal notranslate"><span class="pre">encodings_map</span></code></a> defined in the module.</p>
</dd></dl>
<dl class="attribute">
<dt id="mimetypes.MimeTypes.types_map">
<code class="descname">types_map</code><a class="headerlink" href="#mimetypes.MimeTypes.types_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Tuple containing two dictionaries, mapping filename extensions to MIME types:
the first dictionary is for the non-standards types and the second one is for
the standard types. They are initialized by <a class="reference internal" href="#mimetypes.common_types" title="mimetypes.common_types"><code class="xref py py-data docutils literal notranslate"><span class="pre">common_types</span></code></a> and
<a class="reference internal" href="#mimetypes.types_map" title="mimetypes.types_map"><code class="xref py py-data docutils literal notranslate"><span class="pre">types_map</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="mimetypes.MimeTypes.types_map_inv">
<code class="descname">types_map_inv</code><a class="headerlink" href="#mimetypes.MimeTypes.types_map_inv" title="Permalink to this definition">¶</a></dt>
<dd><p>Tuple containing two dictionaries, mapping MIME types to a list of filename
extensions: the first dictionary is for the non-standards types and the
second one is for the standard types. They are initialized by
<a class="reference internal" href="#mimetypes.common_types" title="mimetypes.common_types"><code class="xref py py-data docutils literal notranslate"><span class="pre">common_types</span></code></a> and <a class="reference internal" href="#mimetypes.types_map" title="mimetypes.types_map"><code class="xref py py-data docutils literal notranslate"><span class="pre">types_map</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="mimetypes.MimeTypes.guess_extension">
<code class="descname">guess_extension</code><span class="sig-paren">(</span><em>type</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.MimeTypes.guess_extension" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to the <a class="reference internal" href="#mimetypes.guess_extension" title="mimetypes.guess_extension"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_extension()</span></code></a> function, using the tables stored as part
of the object.</p>
</dd></dl>
<dl class="method">
<dt id="mimetypes.MimeTypes.guess_type">
<code class="descname">guess_type</code><span class="sig-paren">(</span><em>url</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.MimeTypes.guess_type" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to the <a class="reference internal" href="#mimetypes.guess_type" title="mimetypes.guess_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_type()</span></code></a> function, using the tables stored as part of
the object.</p>
</dd></dl>
<dl class="method">
<dt id="mimetypes.MimeTypes.guess_all_extensions">
<code class="descname">guess_all_extensions</code><span class="sig-paren">(</span><em>type</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.MimeTypes.guess_all_extensions" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to the <a class="reference internal" href="#mimetypes.guess_all_extensions" title="mimetypes.guess_all_extensions"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_all_extensions()</span></code></a> function, using the tables stored
as part of the object.</p>
</dd></dl>
<dl class="method">
<dt id="mimetypes.MimeTypes.read">
<code class="descname">read</code><span class="sig-paren">(</span><em>filename</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.MimeTypes.read" title="Permalink to this definition">¶</a></dt>
<dd><p>Load MIME information from a file named <em>filename</em>. This uses <a class="reference internal" href="#mimetypes.MimeTypes.readfp" title="mimetypes.MimeTypes.readfp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">readfp()</span></code></a> to
parse the file.</p>
<p>If <em>strict</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, information will be added to list of standard types,
else to the list of non-standard types.</p>
</dd></dl>
<dl class="method">
<dt id="mimetypes.MimeTypes.readfp">
<code class="descname">readfp</code><span class="sig-paren">(</span><em>fp</em>, <em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.MimeTypes.readfp" title="Permalink to this definition">¶</a></dt>
<dd><p>Load MIME type information from an open file <em>fp</em>. The file must have the format of
the standard <code class="file docutils literal notranslate"><span class="pre">mime.types</span></code> files.</p>
<p>If <em>strict</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, information will be added to the list of standard
types, else to the list of non-standard types.</p>
</dd></dl>
<dl class="method">
<dt id="mimetypes.MimeTypes.read_windows_registry">
<code class="descname">read_windows_registry</code><span class="sig-paren">(</span><em>strict=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mimetypes.MimeTypes.read_windows_registry" title="Permalink to this definition">¶</a></dt>
<dd><p>Load MIME type information from the Windows registry. Availability: Windows.</p>
<p>If <em>strict</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, information will be added to the list of standard
types, else to the list of non-standard types.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.7.</span></p>
</div>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">18.7. <code class="docutils literal notranslate"><span class="pre">mimetypes</span></code> — Map filenames to MIME types</a><ul>
<li><a class="reference internal" href="#mimetypes-objects">18.7.1. MimeTypes Objects</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="mimetools.html"
title="previous chapter">18.6. <code class="docutils literal notranslate"><span class="pre">mimetools</span></code> — Tools for parsing MIME messages</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="mimewriter.html"
title="next chapter">18.8. <code class="docutils literal notranslate"><span class="pre">MimeWriter</span></code> — Generic MIME file writer</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/library/mimetypes.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<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>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<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="mimewriter.html" title="18.8. MimeWriter — Generic MIME file writer"
>next</a> |</li>
<li class="right" >
<a href="mimetools.html" title="18.6. mimetools — Tools for parsing MIME messages"
>previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<a href="../index.html">Python 2.7.16 documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
<li class="nav-item nav-item-2"><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="https://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on Mar 27, 2019.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6.
</div>
</body>
</html>