Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / html / python / lib / base-handler-objects.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="http-redirect-handler.html" />
13<link rel="prev" href="opener-director-objects.html" />
14<link rel="parent" href="module-urllib2.html" />
15<link rel="next" href="http-redirect-handler.html" />
16<meta name='aesop' content='information' />
17<title>11.5.3 BaseHandler Objects </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="11.5.2 OpenerDirector Objects"
25 href="opener-director-objects.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="11.5 urllib2 "
28 href="module-urllib2.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="11.5.4 HTTPRedirectHandler Objects"
31 href="http-redirect-handler.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="opener-director-objects.html">11.5.2 OpenerDirector Objects</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="module-urllib2.html">11.5 urllib2 </A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="http-redirect-handler.html">11.5.4 HTTPRedirectHandler Objects</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H2><A NAME="SECTION0013530000000000000000"></A><A NAME="base-handler-objects"></A>
56<BR>
5711.5.3 BaseHandler Objects
58</H2>
59
60<P>
61<tt class="class">BaseHandler</tt> objects provide a couple of methods that are
62directly useful, and others that are meant to be used by derived
63classes. These are intended for direct use:
64
65<P>
66<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
67 <td><nobr><b><tt id='l2h-3264' xml:id='l2h-3264' class="method">add_parent</tt></b>(</nobr></td>
68 <td><var>director</var>)</td></tr></table></dt>
69<dd>
70Add a director as parent.
71</dl>
72
73<P>
74<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
75 <td><nobr><b><tt id='l2h-3265' xml:id='l2h-3265' class="method">close</tt></b>(</nobr></td>
76 <td><var></var>)</td></tr></table></dt>
77<dd>
78Remove any parents.
79</dl>
80
81<P>
82The following members and methods should only be used by classes
83derived from <tt class="class">BaseHandler</tt>. <span class="note"><b class="label">Note:</b>
84The convention has been
85adopted that subclasses defining <tt class="method"><var>protocol</var>_request()</tt> or
86<tt class="method"><var>protocol</var>_response()</tt> methods are named
87<tt class="class">*Processor</tt>; all others are named <tt class="class">*Handler</tt>.</span>
88
89<P>
90<dl><dt><b><tt id='l2h-3266' xml:id='l2h-3266' class="member">parent</tt></b></dt>
91<dd>
92A valid <tt class="class">OpenerDirector</tt>, which can be used to open using a
93different protocol, or handle errors.
94</dl>
95
96<P>
97<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
98 <td><nobr><b><tt id='l2h-3267' xml:id='l2h-3267' class="method">default_open</tt></b>(</nobr></td>
99 <td><var>req</var>)</td></tr></table></dt>
100<dd>
101This method is <em>not</em> defined in <tt class="class">BaseHandler</tt>, but
102subclasses should define it if they want to catch all URLs.
103
104<P>
105This method, if implemented, will be called by the parent
106<tt class="class">OpenerDirector</tt>. It should return a file-like object as
107described in the return value of the <tt class="method">open()</tt> of
108<tt class="class">OpenerDirector</tt>, or <code>None</code>. It should raise
109<tt class="exception">URLError</tt>, unless a truly exceptional thing happens (for
110example, <tt class="exception">MemoryError</tt> should not be mapped to
111<tt class="exception">URLError</tt>).
112
113<P>
114This method will be called before any protocol-specific open method.
115</dl>
116
117<P>
118<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
119 <td><nobr><b><var>protocol</var>_open</b>(</nobr></td>
120 <td><var>req</var>)</td></tr></table></dt>
121<dd>
122This method is <em>not</em> defined in <tt class="class">BaseHandler</tt>, but
123subclasses should define it if they want to handle URLs with the given
124protocol.
125
126<P>
127This method, if defined, will be called by the parent
128<tt class="class">OpenerDirector</tt>. Return values should be the same as for
129<tt class="method">default_open()</tt>.
130</dl>
131
132<P>
133<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
134 <td><nobr><b><tt id='l2h-3268' xml:id='l2h-3268' class="method">unknown_open</tt></b>(</nobr></td>
135 <td><var>req</var>)</td></tr></table></dt>
136<dd>
137This method is <var>not</var> defined in <tt class="class">BaseHandler</tt>, but
138subclasses should define it if they want to catch all URLs with no
139specific registered handler to open it.
140
141<P>
142This method, if implemented, will be called by the <tt class="member">parent</tt>
143<tt class="class">OpenerDirector</tt>. Return values should be the same as for
144<tt class="method">default_open()</tt>.
145</dl>
146
147<P>
148<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
149 <td><nobr><b><tt id='l2h-3269' xml:id='l2h-3269' class="method">http_error_default</tt></b>(</nobr></td>
150 <td><var>req, fp, code, msg, hdrs</var>)</td></tr></table></dt>
151<dd>
152This method is <em>not</em> defined in <tt class="class">BaseHandler</tt>, but
153subclasses should override it if they intend to provide a catch-all
154for otherwise unhandled HTTP errors. It will be called automatically
155by the <tt class="class">OpenerDirector</tt> getting the error, and should not
156normally be called in other circumstances.
157
158<P>
159<var>req</var> will be a <tt class="class">Request</tt> object, <var>fp</var> will be a
160file-like object with the HTTP error body, <var>code</var> will be the
161three-digit code of the error, <var>msg</var> will be the user-visible
162explanation of the code and <var>hdrs</var> will be a mapping object with
163the headers of the error.
164
165<P>
166Return values and exceptions raised should be the same as those
167of <tt class="function">urlopen()</tt>.
168</dl>
169
170<P>
171<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
172 <td><nobr><b><tt id='l2h-3270' xml:id='l2h-3270' class="method">http_error_<var>nnn</var></tt></b>(</nobr></td>
173 <td><var>req, fp, code, msg, hdrs</var>)</td></tr></table></dt>
174<dd>
175<var>nnn</var> should be a three-digit HTTP error code. This method is
176also not defined in <tt class="class">BaseHandler</tt>, but will be called, if it
177exists, on an instance of a subclass, when an HTTP error with code
178<var>nnn</var> occurs.
179
180<P>
181Subclasses should override this method to handle specific HTTP
182errors.
183
184<P>
185Arguments, return values and exceptions raised should be the same as
186for <tt class="method">http_error_default()</tt>.
187</dl>
188
189<P>
190<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
191 <td><nobr><b><var>protocol</var>_request</b>(</nobr></td>
192 <td><var>req</var>)</td></tr></table></dt>
193<dd>
194This method is <em>not</em> defined in <tt class="class">BaseHandler</tt>, but
195subclasses should define it if they want to pre-process requests of
196the given protocol.
197
198<P>
199This method, if defined, will be called by the parent
200<tt class="class">OpenerDirector</tt>. <var>req</var> will be a <tt class="class">Request</tt> object.
201The return value should be a <tt class="class">Request</tt> object.
202</dl>
203
204<P>
205<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
206 <td><nobr><b><var>protocol</var>_response</b>(</nobr></td>
207 <td><var>req, response</var>)</td></tr></table></dt>
208<dd>
209This method is <em>not</em> defined in <tt class="class">BaseHandler</tt>, but
210subclasses should define it if they want to post-process responses of
211the given protocol.
212
213<P>
214This method, if defined, will be called by the parent
215<tt class="class">OpenerDirector</tt>. <var>req</var> will be a <tt class="class">Request</tt> object.
216<var>response</var> will be an object implementing the same interface as
217the return value of <tt class="function">urlopen()</tt>. The return value should
218implement the same interface as the return value of
219<tt class="function">urlopen()</tt>.
220</dl>
221
222<P>
223
224<DIV CLASS="navigation">
225<div class='online-navigation'>
226<p></p><hr />
227<table align="center" width="100%" cellpadding="0" cellspacing="2">
228<tr>
229<td class='online-navigation'><a rel="prev" title="11.5.2 OpenerDirector Objects"
230 href="opener-director-objects.html"><img src='../icons/previous.png'
231 border='0' height='32' alt='Previous Page' width='32' /></A></td>
232<td class='online-navigation'><a rel="parent" title="11.5 urllib2 "
233 href="module-urllib2.html"><img src='../icons/up.png'
234 border='0' height='32' alt='Up One Level' width='32' /></A></td>
235<td class='online-navigation'><a rel="next" title="11.5.4 HTTPRedirectHandler Objects"
236 href="http-redirect-handler.html"><img src='../icons/next.png'
237 border='0' height='32' alt='Next Page' width='32' /></A></td>
238<td align="center" width="100%">Python Library Reference</td>
239<td class='online-navigation'><a rel="contents" title="Table of Contents"
240 href="contents.html"><img src='../icons/contents.png'
241 border='0' height='32' alt='Contents' width='32' /></A></td>
242<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
243 border='0' height='32' alt='Module Index' width='32' /></a></td>
244<td class='online-navigation'><a rel="index" title="Index"
245 href="genindex.html"><img src='../icons/index.png'
246 border='0' height='32' alt='Index' width='32' /></A></td>
247</tr></table>
248<div class='online-navigation'>
249<b class="navlabel">Previous:</b>
250<a class="sectref" rel="prev" href="opener-director-objects.html">11.5.2 OpenerDirector Objects</A>
251<b class="navlabel">Up:</b>
252<a class="sectref" rel="parent" href="module-urllib2.html">11.5 urllib2 </A>
253<b class="navlabel">Next:</b>
254<a class="sectref" rel="next" href="http-redirect-handler.html">11.5.4 HTTPRedirectHandler Objects</A>
255</div>
256</div>
257<hr />
258<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
259</DIV>
260<!--End of Navigation Panel-->
261<ADDRESS>
262See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
263</ADDRESS>
264</BODY>
265</HTML>