2019-04-08 23:22:26 +08:00

1 line
5.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="body" role="main"><div class="section" id="module-uu"><h1><span class="yiyi-st" id="yiyi-10">19.10. <a class="reference internal" href="#module-uu" title="uu: Encode and decode files in uuencode format."><code class="xref py py-mod docutils literal"><span class="pre">uu</span></code></a> - 对uuencode文件进行编码和解码</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/uu.py">Lib / uu.py</a></span></p><p><span class="yiyi-st" id="yiyi-12">此模块以uuencode格式编码和解码文件允许任意二进制数据通过仅ASCII连接传输。</span><span class="yiyi-st" id="yiyi-13">无论在何处需要文件参数,这些方法都接受类似于文件的对象。</span><span class="yiyi-st" id="yiyi-14">为了向后兼容,还接受包含路径名的字符串,并且相应的文件将被打开用于读取和写入;路径名<code class="docutils literal"><span class="pre">'-'</span></code>被理解为表示标准输入或输出。</span><span class="yiyi-st" id="yiyi-15">但是此接口已弃用调用者最好打开文件本身并确保在需要时模式是Windows上的<code class="docutils literal"><span class="pre">'rb'</span></code><code class="docutils literal"><span class="pre">'wb'</span></code></span></p><p id="index-0"><span class="yiyi-st" id="yiyi-16">此代码由Lance Ellinghouse贡献并由Jack Jansen修改。</span></p><p><span class="yiyi-st" id="yiyi-17"><a class="reference internal" href="#module-uu" title="uu: Encode and decode files in uuencode format."><code class="xref py py-mod docutils literal"><span class="pre">uu</span></code></a>模块定义了以下功能:</span></p><dl class="function"><dt id="uu.encode"><span class="yiyi-st" id="yiyi-18"> <code class="descclassname">uu.</code><code class="descname">encode</code><span class="sig-paren">(</span><em>in_file</em>, <em>out_file</em>, <em>name=None</em>, <em>mode=None</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-19">Uuencode文件<em>in_file</em>导入文件<em>out_file</em></span><span class="yiyi-st" id="yiyi-20">uuencoded文件将具有指定<em>名称</em><em>模式</em>的标题作为解码文件的结果的默认值。</span><span class="yiyi-st" id="yiyi-21">默认默认值分别取自<em>in_file</em><code class="docutils literal"><span class="pre">'-'</span></code><code class="docutils literal"><span class="pre">0o666</span></code></span></p></dd></dl><dl class="function"><dt id="uu.decode"><span class="yiyi-st" id="yiyi-22"> <code class="descclassname">uu.</code><code class="descname">decode</code><span class="sig-paren">(</span><em>in_file</em>, <em>out_file=None</em>, <em>mode=None</em>, <em>quiet=False</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-23">此调用会将uuencoded文件<em>in_file</em>解码,将结果放在文件<em>out_file</em>上。</span><span class="yiyi-st" id="yiyi-24">如果<em>out_file</em>是路径名,则如果必须创建文件,则使用<em>模式</em>设置权限位。</span><span class="yiyi-st" id="yiyi-25">默认值为<em>out_file</em><em>模式</em>取自uuencode标头。</span><span class="yiyi-st" id="yiyi-26">但是,如果头中指定的文件已经存在,则会引发<a class="reference internal" href="#uu.Error" title="uu.Error"><code class="xref py py-exc docutils literal"><span class="pre">uu.Error</span></code></a></span></p><p><span class="yiyi-st" id="yiyi-27">如果输入由不正确的uuencoder生成并且Python可以从该错误中恢复<a class="reference internal" href="#uu.decode" title="uu.decode"><code class="xref py py-func docutils literal"><span class="pre">decode()</span></code></a>可能会向标准错误打印警告。</span><span class="yiyi-st" id="yiyi-28"><em>quiet</em>设置为true值会使此警告静音。</span></p></dd></dl><dl class="exception"><dt id="uu.Error"><span class="yiyi-st" id="yiyi-29"> <em class="property">exception </em><code class="descclassname">uu.</code><code class="descname">Error</code></span></dt><dd><p><span class="yiyi-st" id="yiyi-30"><a class="reference internal" href="exceptions.html#Exception" title="Exception"><code class="xref py py-exc docutils literal"><span class="pre">Exception</span></code></a>的子类,这可以在各种情况下(如上所述)由<a class="reference internal" href="#uu.decode" title="uu.decode"><code class="xref py py-func docutils literal"><span class="pre">uu.decode()</span></code></a>提出,但也包括格式错误的标头或截断的输入文件。</span></p></dd></dl><div class="admonition seealso"><p class="first admonition-title"><span class="yiyi-st" id="yiyi-31">也可以看看</span></p><dl class="last docutils"><dt><span class="yiyi-st" id="yiyi-32">模块<a class="reference internal" href="binascii.html#module-binascii" title="binascii: Tools for converting between binary and various ASCII-encoded binary representations."><code class="xref py py-mod docutils literal"><span class="pre">binascii</span></code></a></span></dt><dd><span class="yiyi-st" id="yiyi-33">支持模块包含ASCII到二进制和二进制到ASCII转换。</span></dd></dl></div></div></div>