Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > by-pkgid > 0b7eb7009605a11593fbe388d7fbee61 > files > 608

python-docs-2.2-9.1mdk.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>4.8.1 Codec Base Classes</title>
<META NAME="description" CONTENT="4.8.1 Codec Base Classes">
<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=">
<link rel="STYLESHEET" href="lib.css">
<link rel="first" href="lib.html">
<link rel="contents" href="contents.html" title="Contents">
<link rel="index" href="genindex.html" title="Index">
<LINK REL="previous" href="module-codecs.html">
<LINK REL="up" href="module-codecs.html">
<LINK REL="next" href="codec-objects.html">
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-codecs.html"><img src="../icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-codecs.html"><img src="../icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="codec-objects.html"><img src="../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"><img src="../icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" title="Module Index"><img src="../icons/modules.gif"
  border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html"><img src="../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-codecs.html">4.8 codecs  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-codecs.html">4.8 codecs  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="codec-objects.html">4.8.1.1 Codec Objects</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION006810000000000000000">
4.8.1 Codec Base Classes</A>
</H2>

<P>
The <tt class="module">codecs</tt> defines a set of base classes which define the
interface and can also be used to easily write you own codecs for use
in Python.

<P>
Each codec has to define four interfaces to make it usable as codec in
Python: stateless encoder, stateless decoder, stream reader and stream
writer. The stream reader and writers typically reuse the stateless
encoder/decoder to implement the file protocols.

<P>
The <tt class="class">Codec</tt> class defines the interface for stateless
encoders/decoders.

<P>
To simplify and standardize error handling, the <tt class="method">encode()</tt> and
<tt class="method">decode()</tt> methods may implement different error handling
schemes by providing the <var>errors</var> string argument.  The following
string values are defined and implemented by all standard Python
codecs:

<P>
<table border align="center" style="border-collapse: collapse">
  <thead>
    <tr class="tableheader">
      <th align="left"><b>Value</b>&nbsp;</th>
      <th align="left"><b>Meaning</b>&nbsp;</th>
      </tr>
    </thead>
  <tbody valign="baseline">
    <tr><td align="left" valign="baseline"><code>'strict'</code></td>
        <td align="left">Raise <tt class="exception">ValueError</tt> (or a subclass);
                    this is the default.</td>
    <tr><td align="left" valign="baseline"><code>'ignore'</code></td>
        <td align="left">Ignore the character and continue with the next.</td>
    <tr><td align="left" valign="baseline"><code>'replace'</code></td>
        <td align="left">Replace with a suitable replacement character;
                     Python will use the official U+FFFD REPLACEMENT
                     CHARACTER for the built-in Unicode codecs.</td></tbody>
</table>

<P>

<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>

<UL CLASS="ChildLinks">
<LI><A href="codec-objects.html">4.8.1.1 Codec Objects</a>
<LI><A href="stream-writer-objects.html">4.8.1.2 StreamWriter Objects</a>
<LI><A href="stream-reader-objects.html">4.8.1.3 StreamReader Objects</a>
<LI><A href="stream-reader-writer.html">4.8.1.4 StreamReaderWriter Objects</a>
<LI><A href="stream-recoder-objects.html">4.8.1.5 StreamRecoder Objects</a>
</ul>
<!--End of Table of Child-Links-->

<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-codecs.html"><img src="../icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-codecs.html"><img src="../icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="codec-objects.html"><img src="../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"><img src="../icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" title="Module Index"><img src="../icons/modules.gif"
  border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html"><img src="../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-codecs.html">4.8 codecs  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-codecs.html">4.8 codecs  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="codec-objects.html">4.8.1.1 Codec Objects</A>
<hr>
<span class="release-info">Release 2.2, documentation updated on December 21, 2001.</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>