<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>12.15 base64 --
Encode and decode MIME base64 data</TITLE>
<META NAME="description" CONTENT="12.15 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">
<LINK REL="next" HREF="module-quopri.html">
<LINK REL="previous" HREF="module-mimetypes.html">
<LINK REL="up" HREF="netdata.html">
<LINK REL="next" HREF="module-quopri.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-quopri.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="netdata.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-mimetypes.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-quopri.html">12.16 quopri  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="netdata.html">12. Internet Data Handling</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-mimetypes.html">12.14 mimetypes  </A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION00141500000000000000000">
12.15 <tt class=module>base64</tt> --
         Encode and decode MIME base64 data</A>
</H1>

<P>


<P>
<a name="l2h-2109"></a>
<a name="l2h-2110"></a>

<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 <span class=rfc><a name="rfcref-42906"
href="http://info.internet.isi.edu/in-notes/rfc/files/rfc1421.txt">RFC 1421</a></span> (``Privacy Enhancement for
Internet Electronic Mail: Part I: Message Encryption and
Authentication Procedures'', section 4.3.2.4, ``Step 4: Printable
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 <tt>'www.python.org'</tt> is encoded as the string
<tt>'d3d3LnB5dGhvbi5vcmc=&#92;n'</tt>.  

<P>
<dl><dt><b><a name="l2h-2105"><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
<tt><var>input</var>.read()</tt> returns an empty string.
</dl>

<P>
<dl><dt><b><a name="l2h-2106"><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-2107"><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
<tt><var>input</var>.read()</tt> returns an empty string.
</dl>

<P>
<dl><dt><b><a name="l2h-2108"><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>

  <div class=seemodule>
<p>Module <b><tt class=module><a href="module-binascii.html">binascii</a></tt></b>&nbsp;&nbsp;&nbsp;(support module containing ASCII-to-binary
                       and binary-to-ASCII conversions)</p>
</div>
</div><p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-quopri.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="netdata.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-mimetypes.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-quopri.html">12.16 quopri  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="netdata.html">12. Internet Data Handling</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-mimetypes.html">12.14 mimetypes  </A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
