Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / module-base64.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-binascii.html" />
<link rel="prev" href="module-rfc822.html" />
<link rel="parent" href="netdata.html" />
<link rel="next" href="module-binascii.html" />
<meta name='aesop' content='information' />
<title>12.12 base64 -- RFC 3548: Base16, Base32, Base64 Data Encodings</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="12.11.2 AddressList Objects"
href="addresslist-objects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="12. Internet Data Handling"
href="netdata.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="12.13 binascii "
href="module-binascii.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="addresslist-objects.html">12.11.2 AddressList Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="netdata.html">12. Internet Data Handling</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-binascii.html">12.13 binascii </A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION00141200000000000000000">
12.12 <tt class="module">base64</tt> --
RFC 3548: Base16, Base32, Base64 Data Encodings</A>
</H1>
<P>
<A NAME="module-base64"></A>
<P>
<a id='l2h-4108' xml:id='l2h-4108'></a><a id='l2h-4123' xml:id='l2h-4123'></a>
<P>
This module provides data encoding and decoding as specified in
<a class="rfc" id='rfcref-91230' xml:id='rfcref-91230'
href="http://www.faqs.org/rfcs/rfc3548.html">RFC 3548</a>. This standard defines the Base16, Base32, and Base64
algorithms for encoding and decoding arbitrary binary strings into
text strings that can be safely sent by email, used as parts of URLs,
or included as part of an HTTP POST request. The encoding algorithm is
not the same as the <b class="program">uuencode</b> program.
<P>
There are two interfaces provided by this module. The modern
interface supports encoding and decoding string objects using all
three alphabets. The legacy interface provides for encoding and
decoding to and from file-like objects as well as strings, but only
using the Base64 standard alphabet.
<P>
The modern interface provides:
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4109' xml:id='l2h-4109' class="function">b64encode</tt></b>(</nobr></td>
<td><var>s</var><big>[</big><var>, altchars</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Encode a string use Base64.
<P>
<var>s</var> is the string to encode. Optional <var>altchars</var> must be a
string of at least length 2 (additional characters are ignored) which
specifies an alternative alphabet for the <code>+</code> and <code>/</code>
characters. This allows an application to e.g. generate URL or
filesystem safe Base64 strings. The default is <code>None</code>, for which
the standard Base64 alphabet is used.
<P>
The encoded string is returned.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4110' xml:id='l2h-4110' class="function">b64decode</tt></b>(</nobr></td>
<td><var>s</var><big>[</big><var>, altchars</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Decode a Base64 encoded string.
<P>
<var>s</var> is the string to decode. Optional <var>altchars</var> must be a
string of at least length 2 (additional characters are ignored) which
specifies the alternative alphabet used instead of the <code>+</code> and
<code>/</code> characters.
<P>
The decoded string is returned. A <tt class="exception">TypeError</tt> is raised if
<var>s</var> were incorrectly padded or if there are non-alphabet
characters present in the string.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4111' xml:id='l2h-4111' class="function">standard_b64encode</tt></b>(</nobr></td>
<td><var>s</var>)</td></tr></table></dt>
<dd>
Encode string <var>s</var> using the standard Base64 alphabet.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4112' xml:id='l2h-4112' class="function">standard_b64decode</tt></b>(</nobr></td>
<td><var>s</var>)</td></tr></table></dt>
<dd>
Decode string <var>s</var> using the standard Base64 alphabet.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4113' xml:id='l2h-4113' class="function">urlsafe_b64encode</tt></b>(</nobr></td>
<td><var>s</var>)</td></tr></table></dt>
<dd>
Encode string <var>s</var> using a URL-safe alphabet, which substitutes
<code>-</code> instead of <code>+</code> and <code>_</code> instead of <code>/</code> in the
standard Base64 alphabet.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4114' xml:id='l2h-4114' class="function">urlsafe_b64decode</tt></b>(</nobr></td>
<td><var>s</var>)</td></tr></table></dt>
<dd>
Decode string <var>s</var> using a URL-safe alphabet, which substitutes
<code>-</code> instead of <code>+</code> and <code>_</code> instead of <code>/</code> in the
standard Base64 alphabet.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4115' xml:id='l2h-4115' class="function">b32encode</tt></b>(</nobr></td>
<td><var>s</var>)</td></tr></table></dt>
<dd>
Encode a string using Base32. <var>s</var> is the string to encode. The
encoded string is returned.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4116' xml:id='l2h-4116' class="function">b32decode</tt></b>(</nobr></td>
<td><var>s</var><big>[</big><var>, casefold</var><big>[</big><var>, map01</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Decode a Base32 encoded string.
<P>
<var>s</var> is the string to decode. Optional <var>casefold</var> is a flag
specifying whether a lowercase alphabet is acceptable as input. For
security purposes, the default is <code>False</code>.
<P>
<a class="rfc" id='rfcref-91232' xml:id='rfcref-91232'
href="http://www.faqs.org/rfcs/rfc3548.html">RFC 3548</a> allows for optional mapping of the digit 0 (zero) to the
letter O (oh), and for optional mapping of the digit 1 (one) to either
the letter I (eye) or letter L (el). The optional argument
<var>map01</var> when not <code>None</code>, specifies which letter the digit 1 should
be mapped to (when map01 is not <var>None</var>, the digit 0 is always
mapped to the letter O). For security purposes the default is
<code>None</code>, so that 0 and 1 are not allowed in the input.
<P>
The decoded string is returned. A <tt class="exception">TypeError</tt> is raised if
<var>s</var> were incorrectly padded or if there are non-alphabet characters
present in the string.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4117' xml:id='l2h-4117' class="function">b16encode</tt></b>(</nobr></td>
<td><var>s</var>)</td></tr></table></dt>
<dd>
Encode a string using Base16.
<P>
<var>s</var> is the string to encode. The encoded string is returned.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4118' xml:id='l2h-4118' class="function">b16decode</tt></b>(</nobr></td>
<td><var>s</var><big>[</big><var>, casefold</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Decode a Base16 encoded string.
<P>
<var>s</var> is the string to decode. Optional <var>casefold</var> is a flag
specifying whether a lowercase alphabet is acceptable as input. For
security purposes, the default is <code>False</code>.
<P>
The decoded string is returned. A <tt class="exception">TypeError</tt> is raised if
<var>s</var> were incorrectly padded or if there are non-alphabet
characters present in the string.
</dl>
<P>
The legacy interface:
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4119' xml:id='l2h-4119' class="function">decode</tt></b>(</nobr></td>
<td><var>input, output</var>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4120' xml:id='l2h-4120' class="function">decodestring</tt></b>(</nobr></td>
<td><var>s</var>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4121' xml:id='l2h-4121' class="function">encode</tt></b>(</nobr></td>
<td><var>input, output</var>)</td></tr></table></dt>
<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. <tt class="function">encode()</tt>
returns the encoded data plus a trailing newline character
(<code>'&#92;n'</code>).
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4122' xml:id='l2h-4122' class="function">encodestring</tt></b>(</nobr></td>
<td><var>s</var>)</td></tr></table></dt>
<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. <tt class="function">encodestring()</tt> returns a
string containing one or more lines of base64-encoded data
always including an extra trailing newline (<code>'&#92;n'</code>).
</dl>
<P>
<div class="seealso">
<p class="heading">See Also:</p>
<dl compact="compact" class="seemodule">
<dt>Module <b><tt class="module"><a href="module-binascii.html">binascii</a></tt>:</b>
<dd>Support module containing ASCII-to-binary
and binary-to-ASCII conversions.
</dl>
<dl compact="compact" class="seerfc">
<dt><a href="http://www.faqs.org/rfcs/rfc1521.html"
title="MIME (Multipurpose Internet Mail Extensions) Part One:
Mechanisms for Specifying and Describing the Format of
Internet Message Bodies"
>RFC 1521, <em>MIME (Multipurpose Internet Mail Extensions) Part One:
Mechanisms for Specifying and Describing the Format of
Internet Message Bodies</em></a>
<dd>Section 5.2, ``Base64
Content-Transfer-Encoding,'' provides the definition of the
base64 encoding.
</dl>
</div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="12.11.2 AddressList Objects"
href="addresslist-objects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="12. Internet Data Handling"
href="netdata.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="12.13 binascii "
href="module-binascii.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="addresslist-objects.html">12.11.2 AddressList Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="netdata.html">12. Internet Data Handling</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-binascii.html">12.13 binascii </A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>