Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / node130.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="standard-encodings.html" />
13<link rel="prev" href="module-codecs.html" />
14<link rel="parent" href="module-codecs.html" />
15<link rel="next" href="codec-objects.html" />
16<meta name='aesop' content='information' />
17<title>4.9.1 Codec Base Classes</title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="4.9 codecs "
25 href="module-codecs.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="4.9 codecs "
28 href="module-codecs.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="4.9.1.1 Codec Objects"
31 href="codec-objects.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="module-codecs.html">4.9 codecs </A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="module-codecs.html">4.9 codecs </A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="codec-objects.html">4.9.1.1 Codec Objects</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H2><A NAME="SECTION006910000000000000000">
564.9.1 Codec Base Classes</A>
57</H2>
58
59<P>
60The <tt class="module">codecs</tt> defines a set of base classes which define the
61interface and can also be used to easily write you own codecs for use
62in Python.
63
64<P>
65Each codec has to define four interfaces to make it usable as codec in
66Python: stateless encoder, stateless decoder, stream reader and stream
67writer. The stream reader and writers typically reuse the stateless
68encoder/decoder to implement the file protocols.
69
70<P>
71The <tt class="class">Codec</tt> class defines the interface for stateless
72encoders/decoders.
73
74<P>
75To simplify and standardize error handling, the <tt class="method">encode()</tt> and
76<tt class="method">decode()</tt> methods may implement different error handling
77schemes by providing the <var>errors</var> string argument. The following
78string values are defined and implemented by all standard Python
79codecs:
80
81<P>
82<div class="center"><table class="realtable">
83 <thead>
84 <tr>
85 <th class="left" >Value</th>
86 <th class="left" >Meaning</th>
87 </tr>
88 </thead>
89 <tbody>
90 <tr><td class="left" valign="baseline"><code>'strict'</code></td>
91 <td class="left" >Raise <tt class="exception">UnicodeError</tt> (or a subclass);
92 this is the default.</td></tr>
93 <tr><td class="left" valign="baseline"><code>'ignore'</code></td>
94 <td class="left" >Ignore the character and continue with the next.</td></tr>
95 <tr><td class="left" valign="baseline"><code>'replace'</code></td>
96 <td class="left" >Replace with a suitable replacement character;
97 Python will use the official U+FFFD REPLACEMENT
98 CHARACTER for the built-in Unicode codecs on
99 decoding and '?' on encoding.</td></tr>
100 <tr><td class="left" valign="baseline"><code>'xmlcharrefreplace'</code></td>
101 <td class="left" >Replace with the appropriate XML
102 character reference (only for encoding).</td></tr>
103 <tr><td class="left" valign="baseline"><code>'backslashreplace'</code></td>
104 <td class="left" >Replace with backslashed escape sequences
105 (only for encoding).</td></tr></tbody>
106</table></div>
107
108<P>
109The set of allowed values can be extended via <tt class="method">register_error</tt>.
110
111<P>
112
113<p><br /></p><hr class='online-navigation' />
114<div class='online-navigation'>
115<!--Table of Child-Links-->
116<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
117
118<UL CLASS="ChildLinks">
119<LI><A href="codec-objects.html">4.9.1.1 Codec Objects</a>
120<LI><A href="stream-writer-objects.html">4.9.1.2 StreamWriter Objects</a>
121<LI><A href="stream-reader-objects.html">4.9.1.3 StreamReader Objects</a>
122<LI><A href="stream-reader-writer.html">4.9.1.4 StreamReaderWriter Objects</a>
123<LI><A href="stream-recoder-objects.html">4.9.1.5 StreamRecoder Objects</a>
124</ul>
125<!--End of Table of Child-Links-->
126</div>
127
128<DIV CLASS="navigation">
129<div class='online-navigation'>
130<p></p><hr />
131<table align="center" width="100%" cellpadding="0" cellspacing="2">
132<tr>
133<td class='online-navigation'><a rel="prev" title="4.9 codecs "
134 href="module-codecs.html"><img src='../icons/previous.png'
135 border='0' height='32' alt='Previous Page' width='32' /></A></td>
136<td class='online-navigation'><a rel="parent" title="4.9 codecs "
137 href="module-codecs.html"><img src='../icons/up.png'
138 border='0' height='32' alt='Up One Level' width='32' /></A></td>
139<td class='online-navigation'><a rel="next" title="4.9.1.1 Codec Objects"
140 href="codec-objects.html"><img src='../icons/next.png'
141 border='0' height='32' alt='Next Page' width='32' /></A></td>
142<td align="center" width="100%">Python Library Reference</td>
143<td class='online-navigation'><a rel="contents" title="Table of Contents"
144 href="contents.html"><img src='../icons/contents.png'
145 border='0' height='32' alt='Contents' width='32' /></A></td>
146<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
147 border='0' height='32' alt='Module Index' width='32' /></a></td>
148<td class='online-navigation'><a rel="index" title="Index"
149 href="genindex.html"><img src='../icons/index.png'
150 border='0' height='32' alt='Index' width='32' /></A></td>
151</tr></table>
152<div class='online-navigation'>
153<b class="navlabel">Previous:</b>
154<a class="sectref" rel="prev" href="module-codecs.html">4.9 codecs </A>
155<b class="navlabel">Up:</b>
156<a class="sectref" rel="parent" href="module-codecs.html">4.9 codecs </A>
157<b class="navlabel">Next:</b>
158<a class="sectref" rel="next" href="codec-objects.html">4.9.1.1 Codec Objects</A>
159</div>
160</div>
161<hr />
162<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
163</DIV>
164<!--End of Navigation Panel-->
165<ADDRESS>
166See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
167</ADDRESS>
168</BODY>
169</HTML>