mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-08 15:04:05 +08:00
1 line
6.5 KiB
HTML
1 line
6.5 KiB
HTML
<div class="body" role="main"><div class="section" id="module-quopri"><h1><span class="yiyi-st" id="yiyi-10">19.9. <a class="reference internal" href="#module-quopri" title="quopri: Encode and decode files using the MIME quoted-printable encoding."><code class="xref py py-mod docutils literal"><span class="pre">quopri</span></code></a> - 对MIME引用的可打印数据进行编码和解码</span></h1><p><span class="yiyi-st" id="yiyi-11"><strong>源代码:</strong> <a class="reference external" href="https://hg.python.org/cpython/file/3.5/Lib/quopri.py">Lib / quopri.py</a></span></p><p><span class="yiyi-st" id="yiyi-12">该模块执行在<span class="target" id="index-1"></span> <a class="rfc reference external" href="https://tools.ietf.org/html/rfc1521.html"><strong>RFC 1521</strong></a>中定义的引用可打印的传输编码和解码:“MIME(Multipurpose Internet Mail Extensions)Part One:Mechanisms for Specifying and Describing the Format of互联网消息机构“。</span><span class="yiyi-st" id="yiyi-13">引用可打印编码设计用于存在相对较少的不可打印字符的数据;如果有许多这样的字符,例如当发送图形文件时,通过<a class="reference internal" href="base64.html#module-base64" title="base64: RFC 3548: Base16, Base32, Base64 Data Encodings; Base85 and Ascii85"><code class="xref py py-mod docutils literal"><span class="pre">base64</span></code></a>模块可用的base64编码方案更紧凑。</span></p><dl class="function"><dt id="quopri.decode"><span class="yiyi-st" id="yiyi-14"> <code class="descclassname">quopri.</code><code class="descname">decode</code><span class="sig-paren">(</span><em>input</em>, <em>output</em>, <em>header=False</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-15">解码<em>输入</em>文件的内容,并将生成的解码二进制数据写入<em>输出</em>文件。</span><span class="yiyi-st" id="yiyi-16"><em>输入</em>和<em>输出</em>必须是<a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">binary file objects</span></a>。</span><span class="yiyi-st" id="yiyi-17">如果可选参数<em>头</em>存在且为真,则下划线将解释为空格。</span><span class="yiyi-st" id="yiyi-18">这用于解码<span class="target" id="index-2"></span> <a class="rfc reference external" href="https://tools.ietf.org/html/rfc1522.html"><strong>RFC 1522</strong></a>中描述的“Q”编码报头:“MIME(多用途Internet邮件扩展)第二部分:非ASCII文本的消息头扩展“。</span></p></dd></dl><dl class="function"><dt id="quopri.encode"><span class="yiyi-st" id="yiyi-19"> <code class="descclassname">quopri.</code><code class="descname">encode</code><span class="sig-paren">(</span><em>input</em>, <em>output</em>, <em>quotetabs</em>, <em>header=False</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-20">编码<em>输入</em>文件的内容,并将生成的可引用数据写入<em>输出</em>文件。</span><span class="yiyi-st" id="yiyi-21"><em>输入</em>和<em>输出</em>必须是<a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">binary file objects</span></a>。</span><span class="yiyi-st" id="yiyi-22"><em>quotetabs</em>,必须提供控制是否编码嵌入空格和制表符的标志,如果为true,则编码此类嵌入的空格,如果为false,则使它们未编码。</span><span class="yiyi-st" id="yiyi-23">请注意,出现在行尾的空格和制表符总是按<span class="target" id="index-3"></span> <a class="rfc reference external" href="https://tools.ietf.org/html/rfc1521.html"><strong>RFC 1521</strong></a>编码。 <em>头</em>是根据<span class="target" id="index-4"></span> <a class="rfc reference external" href="https://tools.ietf.org/html/rfc1522.html"><strong>RFC 1522</strong></a>控制是否将空格编码为下划线的标志。</span></p></dd></dl><dl class="function"><dt id="quopri.decodestring"><span class="yiyi-st" id="yiyi-24"> <code class="descclassname">quopri.</code><code class="descname">decodestring</code><span class="sig-paren">(</span><em>s</em>, <em>header=False</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-25">类似于<a class="reference internal" href="#quopri.decode" title="quopri.decode"><code class="xref py py-func docutils literal"><span class="pre">decode()</span></code></a>,除了它接受源<a class="reference internal" href="functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a>并返回对应的解码的<a class="reference internal" href="functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a>。</span></p></dd></dl><dl class="function"><dt id="quopri.encodestring"><span class="yiyi-st" id="yiyi-26"> <code class="descclassname">quopri.</code><code class="descname">encodestring</code><span class="sig-paren">(</span><em>s</em>, <em>quotetabs=False</em>, <em>header=False</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-27">像<a class="reference internal" href="#quopri.encode" title="quopri.encode"><code class="xref py py-func docutils literal"><span class="pre">encode()</span></code></a>,除了它接受源<a class="reference internal" href="functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a>并返回相应的编码的<a class="reference internal" href="functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a>。</span><span class="yiyi-st" id="yiyi-28">默认情况下,它向<a class="reference internal" href="#quopri.encode" title="quopri.encode"><code class="xref py py-func docutils literal"><span class="pre">encode()</span></code></a>函数的<em>quotetabs</em>参数发送一个False值。</span></p></dd></dl><div class="admonition seealso"><p class="first admonition-title"><span class="yiyi-st" id="yiyi-29">也可以看看</span></p><dl class="last docutils"><dt><span class="yiyi-st" id="yiyi-30">模块<a class="reference internal" href="base64.html#module-base64" title="base64: RFC 3548: Base16, Base32, Base64 Data Encodings; Base85 and Ascii85"><code class="xref py py-mod docutils literal"><span class="pre">base64</span></code></a></span></dt><dd><span class="yiyi-st" id="yiyi-31">编码和解码MIME base64数据</span></dd></dl></div></div></div> |