blob: d754a72f02711847279cb3ba2d9460bb81df2bc7 [file] [log] [blame]
Moshe Zadka8a18e992001-03-01 08:40:42 +00001\section{\module{urllib2} ---
2 extensible library for opening URLs}
3
4\declaremodule{standard}{urllib2}
Moshe Zadka8a18e992001-03-01 08:40:42 +00005\moduleauthor{Jeremy Hylton}{jhylton@users.sourceforge.net}
6\sectionauthor{Moshe Zadka}{moshez@users.sourceforge.net}
7
8\modulesynopsis{An extensible library for opening URLs using a variety of
9 protocols}
10
11The \module{urllib2} module defines functions and classes which help
Fred Drake93c86712001-03-02 20:39:34 +000012in opening URLs (mostly HTTP) in a complex world --- basic and digest
Moshe Zadka8a18e992001-03-01 08:40:42 +000013authentication, redirections and more.
14
15The \module{urllib2} module defines the following functions:
16
17\begin{funcdesc}{urlopen}{url\optional{, data}}
18Open the url \var{url}, which can either a string or a \class{Request}
19object (currently the code checks that it really is a \class{Request}
Fred Drake93c86712001-03-02 20:39:34 +000020instance, or an instance of a subclass of \class{Request}).
Moshe Zadka8a18e992001-03-01 08:40:42 +000021
22\var{data} should be a string, which specifies additional data to
23send to the server. In HTTP requests, which are the only ones that
24support \var{data}, it should be a buffer in the format of
Fred Drake93c86712001-03-02 20:39:34 +000025\mimetype{application/x-www-form-urlencoded}, for example one returned
26from \function{urllib.urlencode()}.
Moshe Zadka8a18e992001-03-01 08:40:42 +000027
28This function returns a file-like object with two additional methods:
29
30\begin{itemize}
Fred Drake93c86712001-03-02 20:39:34 +000031 \item \method{geturl()} --- return the URL of the resource retrieved
32 \item \method{info()} --- return the meta-information of the page, as
33 a dictionary-like object
Moshe Zadka8a18e992001-03-01 08:40:42 +000034\end{itemize}
35
36Raises \exception{URLError} on errors.
37\end{funcdesc}
38
39\begin{funcdesc}{install_opener}{opener}
40Install a \class{OpenerDirector} instance as the default opener.
41The code does not check for a real \class{OpenerDirector}, and any
42class with the appropriate interface will work.
43\end{funcdesc}
44
Fred Drake93c86712001-03-02 20:39:34 +000045\begin{funcdesc}{build_opener}{\optional{handler, \moreargs}}
Moshe Zadka8a18e992001-03-01 08:40:42 +000046Return an \class{OpenerDirector} instance, which chains the
47handlers in the order given. \var{handler}s can be either instances
48of \class{BaseHandler}, or subclasses of \class{BaseHandler} (in
49which case it must be possible to call the constructor without
50any parameters. Instances of the following classes will be in
51the front of the \var{handler}s, unless the \var{handler}s contain
52them, instances of them or subclasses of them:
53
54\code{ProxyHandler, UnknownHandler, HTTPHandler, HTTPDefaultErrorHandler,
55 HTTPRedirectHandler, FTPHandler, FileHandler}
56
Fred Drake93c86712001-03-02 20:39:34 +000057If the Python installation has SSL support (\function{socket.ssl()}
58exists), \class{HTTPSHandler} will also be added.
Moshe Zadka8a18e992001-03-01 08:40:42 +000059\end{funcdesc}
60
Fred Drake93c86712001-03-02 20:39:34 +000061
62The following exceptions are raised as appropriate:
63
Moshe Zadka8a18e992001-03-01 08:40:42 +000064\begin{excdesc}{URLError}
Fred Drake93c86712001-03-02 20:39:34 +000065The error handlers raise when they run into a problem. It is a
66subclass of \exception{IOError}.
Moshe Zadka8a18e992001-03-01 08:40:42 +000067\end{excdesc}
68
69\begin{excdesc}{HTTPError}
70A subclass of \exception{URLError}, it can also function as a
Fred Drake93c86712001-03-02 20:39:34 +000071non-exceptional file-like return value (the same thing that
72\function{urlopen()} returns). This is useful when handling exotic
73HTTP errors, such as requests for authentication.
Moshe Zadka8a18e992001-03-01 08:40:42 +000074\end{excdesc}
75
76\begin{excdesc}{GopherError}
77A subclass of \exception{URLError}, this is the error raised by the
78Gopher handler.
79\end{excdesc}
80
Fred Drake93c86712001-03-02 20:39:34 +000081
82The following classes are provided:
83
84\begin{classdesc}{Request}{url\optional{, data\optional{, headers}}}
Moshe Zadka8a18e992001-03-01 08:40:42 +000085This class is an abstraction of a URL request.
86
87\var{url} should be a string which is a valid URL. For descrtion
Fred Drake93c86712001-03-02 20:39:34 +000088of \var{data} see the \method{add_data()} description.
Moshe Zadka8a18e992001-03-01 08:40:42 +000089\var{headers} should be a dictionary, and will be treated as if
Fred Drake93c86712001-03-02 20:39:34 +000090\method{add_header()} was called with each key and value as arguments.
Moshe Zadka8a18e992001-03-01 08:40:42 +000091\end{classdesc}
92
Fred Drake93c86712001-03-02 20:39:34 +000093\begin{classdesc}{OpenerDirector}{}
94The \class{OpenerDirector} class opens URLs via \class{BaseHandler}s
95chained together. It manages the chaining of handlers, and recovery
96from errors.
97\end{classdesc}
98
99\begin{classdesc}{BaseHandler}{}
100This is the base class for all registered handlers --- and handles only
101the simple mechanics of registration.
102\end{classdesc}
103
104\begin{classdesc}{HTTPDefaultErrorHandler}{}
105A class which defines a default handler for HTTP error responses; all
106responses are turned into \exception{HTTPError} exceptions.
107\end{classdesc}
108
109\begin{classdesc}{HTTPRedirectHandler}{}
110A class to handle redirections.
111\end{classdesc}
112
113\begin{classdesc}{ProxyHandler}{\optional{proxies}}
114Cause requests to go through a proxy.
115If \var{proxies} is given, it must be a dictionary mapping
116protocol names to URLs of proxies.
117The default is to read the list of proxies from the environment
118variables \envvar{\var{protocol}_proxy}.
119\end{classdesc}
120
121\begin{classdesc}{HTTPPasswordMgr}{}
122Keep a database of
123\code{(\var{realm}, \var{uri}) -> (\var{user}, \var{password})}
124mappings.
125\end{classdesc}
126
127\begin{classdesc}{HTTPPasswordMgrWithDefaultRealm}{}
128Keep a database of
129\code{(\var{realm}, \var{uri}) -> (\var{user}, \var{password})} mappings.
130A realm of \code{None} is considered a catch-all realm, which is searched
131if no other realm fits.
132\end{classdesc}
133
134\begin{classdesc}{AbstractBasicAuthHandler}{\optional{password_mgr}}
135This is a mixin class that helps with HTTP authentication, both
136to the remote host and to a proxy.
137
138\var{password_mgr} should be something that is compatible with
139\class{HTTPPasswordMgr} --- supplies the documented interface above.
140\end{classdesc}
141
142\begin{classdesc}{HTTPBasicAuthHandler}{\optional{password_mgr}}
143Handle authentication with the remote host.
144Valid \var{password_mgr}, if given, are the same as for
145\class{AbstractBasicAuthHandler}.
146\end{classdesc}
147
148\begin{classdesc}{ProxyBasicAuthHandler}{\optional{password_mgr}}
149Handle authentication with the proxy.
150Valid \var{password_mgr}, if given, are the same as for
151\class{AbstractBasicAuthHandler}.
152\end{classdesc}
153
154\begin{classdesc}{AbstractDigestAuthHandler}{\optional{password_mgr}}
155This is a mixin class, that helps with HTTP authentication, both
156to the remote host and to a proxy.
157
158\var{password_mgr} should be something that is compatible with
159\class{HTTPPasswordMgr} --- supplies the documented interface above.
160\end{classdesc}
161
162\begin{classdesc}{HTTPDigestAuthHandler}{\optional{password_mgr}}
163Handle authentication with the remote host.
164Valid \var{password_mgr}, if given, are the same as for
165\class{AbstractBasicAuthHandler}.
166\end{classdesc}
167
168\begin{classdesc}{ProxyDigestAuthHandler}{\optional{password_mgr}}
169Handle authentication with the proxy.
170\var{password_mgr}, if given, shoudl be the same as for
171the constructor of \class{AbstractDigestAuthHandler}.
172\end{classdesc}
173
174\begin{classdesc}{HTTPHandler}{}
175A class to handle opening of HTTP URLs.
176\end{classdesc}
177
178\begin{classdesc}{HTTPSHandler}{}
179A class to handle opening of HTTPS URLs.
180\end{classdesc}
181
182\begin{classdesc}{FileHandler}{}
183Open local files.
184\end{classdesc}
185
186\begin{classdesc}{FTPHandler}{}
187Open FTP URLs.
188\end{classdesc}
189
190\begin{classdesc}{CacheFTPHandler}{}
191Open FTP URLs, keeping a cache of open FTP connections to minimize
192delays.
193\end{classdesc}
194
195\begin{classdesc}{GopherHandler}{}
196Open gopher URLs.
197\end{classdesc}
198
199\begin{classdesc}{UnknownHandler}{}
200A catch-all class to handle unknown URLs.
201\end{classdesc}
202
203
204\subsection{Request Objects \label{request-objects}}
205
Moshe Zadka8a18e992001-03-01 08:40:42 +0000206The following methods describe all of \class{Request}'s public interface,
207and so all must be overridden in subclasses.
208
209\begin{methoddesc}[Request]{add_data}{data}
210Set the \class{Request} data to \var{data} is ignored
211by all handlers except HTTP handlers --- and there it should be an
Fred Drake93c86712001-03-02 20:39:34 +0000212\mimetype{application/x-www-form-encoded} buffer, and will change the
Moshe Zadka8a18e992001-03-01 08:40:42 +0000213request to be \code{POST} rather then \code{GET}.
214\end{methoddesc}
215
216\begin{methoddesc}[Request]{has_data}{data}
217Return whether the instance has a non-\code{None} data.
218\end{methoddesc}
219
220\begin{methoddesc}[Request]{get_data}{data}
221Return the instance's data.
222\end{methoddesc}
223
224\begin{methoddesc}[Request]{add_header}{key, val}
Fred Drake93c86712001-03-02 20:39:34 +0000225Add another header to the request. Headers are currently ignored by
226all handlers except HTTP handlers, where they are added to the list
227of headers sent to the server. Note that there cannot be more then
228one header with the same name, and later calls will overwrite
229previous calls in case the \var{key} collides. Currently, this is
230no loss of HTTP functionality, since all headers which have meaning
Moshe Zadka8a18e992001-03-01 08:40:42 +0000231when used more then once have a (header-specific) way of gaining the
232same functionality using only one header.
233\end{methoddesc}
234
235\begin{methoddesc}[Request]{get_full_url}{}
236Return the URL given in the constructor.
237\end{methoddesc}
238
239\begin{methoddesc}[Request]{get_type}{}
Fred Drake93c86712001-03-02 20:39:34 +0000240Return the type of the URL --- also known as the scheme.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000241\end{methoddesc}
242
243\begin{methoddesc}[Request]{get_host}{}
244Return the host to which connection will be made.
245\end{methoddesc}
246
247\begin{methoddesc}[Request]{get_selector}{}
248Return the selector --- the part of the URL that is sent to
249the server.
250\end{methoddesc}
251
252\begin{methoddesc}[Request]{set_proxy}{host, type}
Fred Drake93c86712001-03-02 20:39:34 +0000253Make the request by connecting to a proxy server. The \var{host} and
254\var{type} will replace those of the instance, and the instance's
255selector will be the original URL given in the constructor.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000256\end{methoddesc}
257
Fred Drake93c86712001-03-02 20:39:34 +0000258
259\subsection{OpenerDirector Objects \label{opener-director-objects}}
260
261\class{OpenerDirector} instances have the following methods:
Moshe Zadka8a18e992001-03-01 08:40:42 +0000262
263\begin{methoddesc}[OpenerDirector]{add_handler}{handler}
Fred Drake93c86712001-03-02 20:39:34 +0000264\var{handler} should be an instance of \class{BaseHandler}. The
265following methods are searched, and added to the possible chains.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000266
267\begin{itemize}
Fred Drake93c86712001-03-02 20:39:34 +0000268 \item \method{\var{protocol}_open()} ---
269 signal that the handler knows how to open \var{protocol} URLs.
270 \item \method{\var{protocol}_error_\var{type}()} ---
271 signal that the handler knows how to handle \var{type} errors from
272 \var{protocol}.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000273\end{itemize}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000274\end{methoddesc}
275
276\begin{methoddesc}[OpenerDirector]{close}{}
277Explicitly break cycles, and delete all the handlers.
278Because the \class{OpenerDirector} needs to know the registered handlers,
279and a handler needs to know who the \class{OpenerDirector} who called
280it is, there is a reference cycles. Even though recent versions of Python
281have cycle-collection, it is sometimes preferable to explicitly break
282the cycles.
283\end{methoddesc}
284
285\begin{methoddesc}[OpenerDirector]{open}{url\optional{, data}}
286Open the given \var{url}. (which can be a request object or a string),
287optionally passing the given \var{data}.
288Arguments, return values and exceptions raised are the same as those
Fred Drake93c86712001-03-02 20:39:34 +0000289of \function{urlopen()} (which simply calls the \method{open()} method
Moshe Zadka8a18e992001-03-01 08:40:42 +0000290on the default installed \class{OpenerDirector}.
291\end{methoddesc}
292
Fred Drake93c86712001-03-02 20:39:34 +0000293\begin{methoddesc}[OpenerDirector]{error}{proto\optional{,
294 arg\optional{, \moreargs}}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000295Handle an error in a given protocol. The HTTP protocol is special cased to
296use the code as the error. This will call the registered error handlers
297for the given protocol with the given arguments (which are protocol specific).
298
299Return values and exceptions raised are the same as those
Fred Drake93c86712001-03-02 20:39:34 +0000300of \function{urlopen()}.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000301\end{methoddesc}
302
Fred Drake93c86712001-03-02 20:39:34 +0000303
304\subsection{BaseHandler Objects \label{base-handler-objects}}
305
306\class{BaseHandler} objects provide a couple of methods that are
307directly useful, and others that are meant to be used by derived
308classes. These are intended for direct use:
Moshe Zadka8a18e992001-03-01 08:40:42 +0000309
310\begin{methoddesc}[BaseHandler]{add_parent}{director}
311Add a director as parent.
312\end{methoddesc}
313
314\begin{methoddesc}[BaseHandler]{close}{}
315Remove any parents.
316\end{methoddesc}
317
Fred Drake93c86712001-03-02 20:39:34 +0000318The following members and methods should be used only be classes
319derived from \class{BaseHandler}:
Moshe Zadka8a18e992001-03-01 08:40:42 +0000320
321\begin{memberdesc}[BaseHandler]{parent}
Fred Drake93c86712001-03-02 20:39:34 +0000322A valid \class{OpenerDirector}, which can be used to open using a
323different protocol, or handle errors.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000324\end{memberdesc}
325
326\begin{methoddesc}[BaseHandler]{default_open}{req}
Fred Drake93c86712001-03-02 20:39:34 +0000327This method is \emph{not} defined in \class{BaseHandler}, but
328subclasses should define it if they want to catch all URLs.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000329
Fred Drake93c86712001-03-02 20:39:34 +0000330This method, if exists, will be called by the \member{parent}
331\class{OpenerDirector}. It should return a file-like object as
332described in the return value of the \method{open()} of
333\class{OpenerDirector} or \code{None}. It should raise
334\exception{URLError}, unless a truly exceptional thing happens (for
335example, \exception{MemoryError} should not be mapped to
336\exception{URLError}.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000337
338This method will be called before any protocol-specific open method.
339\end{methoddesc}
340
Fred Drake93c86712001-03-02 20:39:34 +0000341\begin{methoddesc}[BaseHandler]{\var{protocol}_open}{req}
342This method is \emph{not} defined in \class{BaseHandler}, but
343subclasses should define it if they want to handle URLs with the given
344protocol.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000345
Fred Drake93c86712001-03-02 20:39:34 +0000346This method, if defined, will be called by the \member{parent}
347\class{OpenerDirector}. Return values should be the same as for
348\method{default_open()}.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000349\end{methoddesc}
350
351\begin{methoddesc}[BaseHandler]{unknown_open}{req}
Fred Drake93c86712001-03-02 20:39:34 +0000352This method is \var{not} defined in \class{BaseHandler}, but
353subclasses should define it if they want to catch all URLs with no
354specific registerd handler to open it.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000355
356This method, if exists, will be called by the \member{parent}
Fred Drake93c86712001-03-02 20:39:34 +0000357\class{OpenerDirector}. Return values should be the same as for
358\method{default_open()}.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000359\end{methoddesc}
360
361\begin{methoddesc}[BaseHandler]{http_error_default}{req, fp, code, msg, hdrs}
Fred Drake93c86712001-03-02 20:39:34 +0000362This method is \emph{not} defined in \class{BaseHandler}, but
363subclasses should override it if they intend to provide a catch-all
364for otherwise unhandled HTTP errors. It will be called automatically
365by the \class{OpenerDirector} getting the error, and should not
366normally be called in other circumstances.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000367
Fred Drake93c86712001-03-02 20:39:34 +0000368\var{req} will be a \class{Request} object, \var{fp} will be a
369file-like object with the HTTP error body, \var{code} will be the
370three-digit code of the error, \var{msg} will be the user-visible
371explanation of the code and \var{hdrs} will be a mapping object with
372the headers of the error.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000373
374Return values and exceptions raised should be the same as those
Fred Drake93c86712001-03-02 20:39:34 +0000375of \function{urlopen()}.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000376\end{methoddesc}
377
Fred Drake93c86712001-03-02 20:39:34 +0000378\begin{methoddesc}[BaseHandler]{http_error_\var{nnn}}{req, fp, code, msg, hdrs}
379\var{nnn} should be a three-digit HTTP error code. This method is
380also not defined in \class{BaseHandler}, but will be called, if it
381exists, on an instance of a subclass, when an HTTP error with code
382\var{nnn} occurs.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000383
Fred Drake93c86712001-03-02 20:39:34 +0000384Subclasses should override this method to handle specific HTTP
385errors.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000386
Fred Drake93c86712001-03-02 20:39:34 +0000387Arguments, return values and exceptions raised should be the same as
388for \method{http_error_default()}.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000389\end{methoddesc}
390
391
Fred Drake93c86712001-03-02 20:39:34 +0000392\subsection{HTTPRedirectHandler Objects \label{http-redirect-handler}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000393
394\strong{Note:} 303 redirection is not supported by this version of
395\module{urllib2}.
396
Fred Drake93c86712001-03-02 20:39:34 +0000397\begin{methoddesc}[HTTPRedirectHandler]{http_error_301}{req,
398 fp, code, msg, hdrs}
399Redirect to the \code{Location:} URL. This method is called by
400the parent \class{OpenerDirector} when getting an HTTP
401permanent-redirect response.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000402\end{methoddesc}
403
Fred Drake93c86712001-03-02 20:39:34 +0000404\begin{methoddesc}[HTTPRedirectHandler]{http_error_302}{req,
405 fp, code, msg, hdrs}
406The same as \method{http_error_301()}, but called for the
407temporary-redirect response.
408\end{methoddesc}
409
410
411\subsection{ProxyHandler Objects \label{proxy-handler}}
412
413\begin{methoddesc}[ProxyHandler]{\var{protocol}_open}{request}
414The \class{ProxyHandler} will have a method
415\method{\var{protocol}_open()} for every \var{protocol} which has a
416proxy in the \var{proxies} dictionary given in the constructor. The
417method will modify requests to go through the proxy, by calling
418\code{request.set_proxy()}, and call the next handler in the chain to
419actually execute the protocol.
420\end{methoddesc}
421
422
423\subsection{HTTPPasswordMgr Objects \label{http-password-mgr}}
424
425These methods are available on \class{HTTPPasswordMgr} and
426\class{HTTPPasswordMgrWithDefaultRealm} objects.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000427
428\begin{methoddesc}[HTTPPasswordMgr]{add_password}{realm, uri, user, passwd}
429\var{uri} can be either a single URI, or a sequene of URIs. \var{realm},
430\var{user} and \var{passwd} must be strings. This causes
Fred Drake93c86712001-03-02 20:39:34 +0000431\code{(\var{user}, \var{passwd})} to be used as authentication tokens
Moshe Zadka8a18e992001-03-01 08:40:42 +0000432when authentication for \var{realm} and a super-URI of any of the
433given URIs is given.
434\end{methoddesc}
435
436\begin{methoddesc}[HTTPPasswordMgr]{find_user_password}{realm, authuri}
Fred Drake93c86712001-03-02 20:39:34 +0000437Get user/password for given realm and URI, if any. This method will
438return \code{(None, None)} if there is no matching user/password.
439
440For \class{HTTPPasswordMgrWithDefaultRealm} objects, the realm
441\code{None} will be searched if the given \var{realm} has no matching
442user/password.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000443\end{methoddesc}
444
Moshe Zadka8a18e992001-03-01 08:40:42 +0000445
Fred Drake93c86712001-03-02 20:39:34 +0000446\subsection{AbstractBasicAuthHandler Objects
447 \label{abstract-basic-auth-handler}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000448
449\begin{methoddesc}[AbstractBasicAuthHandler]{handle_authentication_request}
450 {authreq, host, req, headers}
451Handle an authentication request by getting user/password pair, and retrying.
452\var{authreq} should be the name of the header where the information about
453the realm, \var{host} is the host to authenticate too, \var{req} should be the
454(failed) \class{Request} object, and \var{headers} should be the error headers.
455\end{methoddesc}
456
Fred Drake93c86712001-03-02 20:39:34 +0000457
458\subsection{HTTPBasicAuthHandler Objects
459 \label{http-basic-auth-handler}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000460
461\begin{methoddesc}[HTTPBasicAuthHandler]{http_error_401}{req, fp, code,
462 msg, hdrs}
463Retry the request with authentication info, if available.
464\end{methoddesc}
465
Fred Drake93c86712001-03-02 20:39:34 +0000466
467\subsection{ProxyBasicAuthHandler Objects
468 \label{proxy-basic-auth-handler}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000469
470\begin{methoddesc}[ProxyBasicAuthHandler]{http_error_407}{req, fp, code,
471 msg, hdrs}
472Retry the request with authentication info, if available.
473\end{methoddesc}
474
Moshe Zadka8a18e992001-03-01 08:40:42 +0000475
Fred Drake93c86712001-03-02 20:39:34 +0000476\subsection{AbstractDigestAuthHandler Objects
477 \label{abstract-digest-auth-handler}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000478
Fred Drake93c86712001-03-02 20:39:34 +0000479\begin{methoddesc}[AbstractDigestAuthHandler]{handle_authentication_request}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000480 {authreq, host, req, headers}
481\var{authreq} should be the name of the header where the information about
482the realm, \var{host} should be the host to authenticate too, \var{req}
483should be the (failed) \class{Request} object, and \var{headers} should be the
484error headers.
485\end{methoddesc}
486
Fred Drake93c86712001-03-02 20:39:34 +0000487
488\subsection{HTTPDigestAuthHandler Objects
489 \label{http-digest-auth-handler}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000490
491\begin{methoddesc}[HTTPDigestAuthHandler]{http_error_401}{req, fp, code,
492 msg, hdrs}
493Retry the request with authentication info, if available.
494\end{methoddesc}
495
Fred Drake93c86712001-03-02 20:39:34 +0000496
497\subsection{ProxyDigestAuthHandler Objects
498 \label{proxy-digest-auth-handler}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000499
500\begin{methoddesc}[ProxyDigestAuthHandler]{http_error_407}{req, fp, code,
501 msg, hdrs}
Fred Drake93c86712001-03-02 20:39:34 +0000502Retry the request with authentication information, if available.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000503\end{methoddesc}
504
Fred Drake93c86712001-03-02 20:39:34 +0000505
506\subsection{HTTPHandler Objects \label{http-handler-objects}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000507
508\begin{methoddesc}[HTTPHandler]{http_open}{req}
Fred Drake93c86712001-03-02 20:39:34 +0000509Send an HTTP request, whcih can be either GET or POST, depending on
510\code{\var{req}.has_data()}.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000511\end{methoddesc}
512
Fred Drake93c86712001-03-02 20:39:34 +0000513
514\subsection{HTTPSHandler Objects \label{https-handler-objects}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000515
516\begin{methoddesc}[HTTPSHandler]{https_open}{req}
Fred Drake93c86712001-03-02 20:39:34 +0000517Send an HTTPS request, which can be either GET or POST, depending on
518\code{\var{req}.has_data()}.
Moshe Zadka8a18e992001-03-01 08:40:42 +0000519\end{methoddesc}
520
Moshe Zadka8a18e992001-03-01 08:40:42 +0000521
Fred Drake93c86712001-03-02 20:39:34 +0000522\subsection{FileHandler Objects \label{file-handler-objects}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000523
524\begin{methoddesc}[FileHandler]{file_open}{req}
525Open the file locally, if there is no host name, or
Fred Drake93c86712001-03-02 20:39:34 +0000526the host name is \code{'localhost'}. Change the
Moshe Zadka8a18e992001-03-01 08:40:42 +0000527protocol to \code{ftp} otherwise, and retry opening
528it using \member{parent}.
529\end{methoddesc}
530
Fred Drake93c86712001-03-02 20:39:34 +0000531
532\subsection{FTPHandler Objects \label{ftp-handler-objects}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000533
534\begin{methoddesc}[FTPHandler]{ftp_open}{req}
535Open the FTP file indicated by \var{req}.
536The login is always done with empty username and password.
537\end{methoddesc}
538
Moshe Zadka8a18e992001-03-01 08:40:42 +0000539
Fred Drake93c86712001-03-02 20:39:34 +0000540\subsection{CacheFTPHandler Objects \label{cacheftp-handler-objects}}
541
542\class{CacheFTPHandler} objects are \class{FTPHandler} objects with
543the following additional methods:
Moshe Zadka8a18e992001-03-01 08:40:42 +0000544
545\begin{methoddesc}[CacheFTPHandler]{setTimeout}{t}
546Set timeout of connections to \var{t} seconds.
547\end{methoddesc}
548
549\begin{methoddesc}[CacheFTPHandler]{setMaxConns}{m}
550Set maximum number of cached connections to \var{m}.
551\end{methoddesc}
552
Fred Drake93c86712001-03-02 20:39:34 +0000553
554\subsection{GopherHandler Objects \label{gopher-handler}}
Moshe Zadka8a18e992001-03-01 08:40:42 +0000555
556\begin{methoddesc}[GopherHandler]{gopher_open}{req}
557Open the gopher resource indicated by \var{req}.
558\end{methoddesc}
Fred Drake93c86712001-03-02 20:39:34 +0000559
560
561\subsection{UnknownHandler Objects \label{unknown-handler-objects}}
562
563\begin{methoddesc}[UnknownHandler]{unknown_open}
564Raise a \exception{URLError} exception.
565\end{methoddesc}