module-base64.html
来自「一本很好的python的说明书,适合对python感兴趣的人」· HTML 代码 · 共 146 行
HTML
146 行
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>12.12 base64 -- Encode and decode MIME base64 data</title>
<META NAME="description" CONTENT="12.12 base64 -- Encode and decode MIME base64 data">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-quopri.html" tppabs="http://www.python.org/doc/current/lib/module-quopri.html">
<LINK REL="previous" href="module-mimetypes.html" tppabs="http://www.python.org/doc/current/lib/module-mimetypes.html">
<LINK REL="up" href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html">
<LINK REL="next" href="module-quopri.html" tppabs="http://www.python.org/doc/current/lib/module-quopri.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-mimetypes.html" tppabs="http://www.python.org/doc/current/lib/module-mimetypes.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-quopri.html" tppabs="http://www.python.org/doc/current/lib/module-quopri.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-mimetypes.html" tppabs="http://www.python.org/doc/current/lib/module-mimetypes.html">12.11 mimetypes </A>
<b class="navlabel">Up:</b> <a class="sectref" href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html">12. Internet Data Handling</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-quopri.html" tppabs="http://www.python.org/doc/current/lib/module-quopri.html">12.13 quopri </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION00141200000000000000000">
12.12 <tt class="module">base64</tt> --
Encode and decode MIME base64 data</A>
</H1>
<P>
<P>
<P>
This module performs base64 encoding and decoding of arbitrary binary
strings into text strings that can be safely emailed or posted. The
encoding scheme is defined in <a class="rfc" name="rfcref-47587"
href="javascript:if(confirm('http://www.ietf.org/rfc/rfc1521.txt \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc1521.txt'" tppabs="http://www.ietf.org/rfc/rfc1521.txt">RFC 1521 <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a> (<i>MIME
(Multipurpose Internet Mail Extensions) Part One: Mechanisms for
Specifying and Describing the Format of Internet Message Bodies</i>,
section 5.2, ``Base64 Content-Transfer-Encoding'') and is used for
MIME email and various other Internet-related applications; it is not
the same as the output produced by the <b class="program">uuencode</b> program.
For example, the string <code>'www.python.org'</code> is encoded as the
string <code>'d3d3LnB5dGhvbi5vcmc=\n'</code>.
<P>
<dl><dt><b><a name='l2h-2485'><tt class='function'>decode</tt></a></b> (<var>input, output</var>)
<dd>
Decode the contents of the <var>input</var> file and write the resulting
binary data to the <var>output</var> file.
<var>input</var> and <var>output</var> must either be file objects or objects that
mimic the file object interface. <var>input</var> will be read until
<code><var>input</var>.read()</code> returns an empty string.
</dl>
<P>
<dl><dt><b><a name='l2h-2486'><tt class='function'>decodestring</tt></a></b> (<var>s</var>)
<dd>
Decode the string <var>s</var>, which must contain one or more lines of
base64 encoded data, and return a string containing the resulting
binary data.
</dl>
<P>
<dl><dt><b><a name='l2h-2487'><tt class='function'>encode</tt></a></b> (<var>input, output</var>)
<dd>
Encode the contents of the <var>input</var> file and write the resulting
base64 encoded data to the <var>output</var> file.
<var>input</var> and <var>output</var> must either be file objects or objects that
mimic the file object interface. <var>input</var> will be read until
<code><var>input</var>.read()</code> returns an empty string.
</dl>
<P>
<dl><dt><b><a name='l2h-2488'><tt class='function'>encodestring</tt></a></b> (<var>s</var>)
<dd>
Encode the string <var>s</var>, which can contain arbitrary binary data,
and return a string containing one or more lines of
base64 encoded data.
</dl>
<P>
<div class='seealso'>
<p class='heading'><b>See Also:</b></p>
<dl compact class="seemodule">
<dt>Module <b><tt class='module'><a href="module-binascii.html" tppabs="http://www.python.org/doc/current/lib/module-binascii.html">binascii</a></tt>:</b>
<dd>support module containing ASCII-to-binary
and binary-to-ASCII conversions.
</dl>
<div class="seetext"><p>Internet <a class="rfc" name="rfcref-47582"
href="javascript:if(confirm('http://www.ietf.org/rfc/rfc1521.txt \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc1521.txt'" tppabs="http://www.ietf.org/rfc/rfc1521.txt">RFC 1521 <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a>, <i>MIME (Multipurpose Internet
Mail Extensions) Part One: Mechanisms for Specifying and
Describing the Format of Internet Message Bodies</i>, section
5.2, ``Base64 Content-Transfer-Encoding,'' provides the
definition of the base64 encoding.</div>
</div>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-mimetypes.html" tppabs="http://www.python.org/doc/current/lib/module-mimetypes.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-quopri.html" tppabs="http://www.python.org/doc/current/lib/module-quopri.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-mimetypes.html" tppabs="http://www.python.org/doc/current/lib/module-mimetypes.html">12.11 mimetypes </A>
<b class="navlabel">Up:</b> <a class="sectref" href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html">12. Internet Data Handling</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-quopri.html" tppabs="http://www.python.org/doc/current/lib/module-quopri.html">12.13 quopri </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?