[Python-checkins] python/dist/src/Doc/lib liburllib2.tex,1.13,1.14

jhylton at users.sourceforge.net jhylton at users.sourceforge.net
Sun Dec 14 00:27:36 EST 2003


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1:/tmp/cvs-serv20853/Doc/lib
Modified Files:
	liburllib2.tex 
Log Message:
SF patch 852995: add processors feature to urllib2
John J. Lee writes: "the patch makes it possible to implement
functionality like HTTP cookie handling, Refresh handling,
etc. etc. using handler objects. At the moment urllib2's handler
objects aren't quite up to the job, which results in a lot of
cut-n-paste and subclassing. I believe the changes are
backwards-compatible, with the exception of people who've
reimplemented build_opener()'s functionality -- those people would
need to call opener.add_handler(HTTPErrorProcessor).
The main change is allowing handlers to implement
methods like:
http_request(request)
http_response(request, response)
In addition to the usual
http_open(request)
http_error{_*}(...) 
"
Note that the change isn't well documented at least in part because
handlers aren't well documented at all. Need to fix this.
Add a bunch of new tests. It appears that none of these tests
actually use the network, so they don't need to be guarded by a
resource flag.
Index: liburllib2.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/liburllib2.tex,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** liburllib2.tex	14 Jul 2003 21:07:05 -0000	1.13
--- liburllib2.tex	14 Dec 2003 05:27:34 -0000	1.14
***************
*** 53,57 ****
 \class{ProxyHandler}, \class{UnknownHandler}, \class{HTTPHandler},
 \class{HTTPDefaultErrorHandler}, \class{HTTPRedirectHandler},
! \class{FTPHandler}, \class{FileHandler}
 
 If the Python installation has SSL support (\function{socket.ssl()}
--- 53,57 ----
 \class{ProxyHandler}, \class{UnknownHandler}, \class{HTTPHandler},
 \class{HTTPDefaultErrorHandler}, \class{HTTPRedirectHandler},
! \class{FTPHandler}, \class{FileHandler}, \class{HTTPErrorProcessor}.
 
 If the Python installation has SSL support (\function{socket.ssl()}
***************
*** 249,252 ****
--- 249,261 ----
 \end{methoddesc}
 
+ \begin{methoddesc}[Request]{add_unredirected_header}{key, header}
+ Add a header that will not be added to a redirected request.
+ \end{methoddesc}
+ 
+ \begin{methoddesc}[Request]{has_header}{header}
+ Return whether the instance has the named header (checks both regular
+ and unredirected).
+ \end{methoddesc}
+ 
 \begin{methoddesc}[Request]{get_full_url}{}
 Return the URL given in the constructor.
***************
*** 287,290 ****
--- 296,305 ----
 signal that the handler knows how to handle \var{type} errors from
 \var{protocol}.
+ \item \method{\var{protocol}_request()} ---
+ signal that the handler knows how to pre-process \var{protocol}
+ requests.
+ \item \method{\var{protocol}_response()} ---
+ signal that the handler knows how to post-process \var{protocol}
+ responses.
 \end{itemize}
 \end{methoddesc}
***************
*** 618,621 ****
--- 633,651 ----
 \begin{methoddesc}[UnknownHandler]{unknown_open}{}
 Raise a \exception{URLError} exception.
+ \end{methoddesc}
+ 
+ 
+ \subsection{HTTPErrorProcessor Objects \label{http-error-processor-objects}}
+ 
+ \begin{methoddesc}[HTTPErrorProcessor]{unknown_open}{}
+ Process HTTP error responses.
+ 
+ For 200 error codes, the response object is returned immediately.
+ 
+ For non-200 error codes, this simply passes the job on to the
+ \method{\var{protocol}_error_\var{code}()} handler methods, via
+ \method{OpenerDirector.error()}. Eventually,
+ \class{urllib2.HTTPDefaultErrorHandler} will raise an
+ \exception{HTTPError} if no other handler handles the error.
 \end{methoddesc}
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /