GNU Info

Info Node: (python2.1-lib.info)BaseHandler Objects

(python2.1-lib.info)BaseHandler Objects


Next: HTTPRedirectHandler Objects Prev: OpenerDirector Objects Up: urllib2
Enter node , (file) or (file)node

BaseHandler Objects
-------------------

`BaseHandler' objects provide a couple of methods that are directly
useful, and others that are meant to be used by derived classes.  These
are intended for direct use:

`add_parent(director)'
     Add a director as parent.

`close()'
     Remove any parents.

The following members and methods should be used only be classes
derived from `BaseHandler':

`parent'
     A valid `OpenerDirector', which can be used to open using a
     different protocol, or handle errors.

`default_open(req)'
     This method is _not_ defined in `BaseHandler', but subclasses
     should define it if they want to catch all URLs.

     This method, if exists, will be called by the `parent'
     `OpenerDirector'.  It should return a file-like object as
     described in the return value of the `open()' of `OpenerDirector'
     or `None'.  It should raise `URLError', unless a truly exceptional
     thing happens (for example, `MemoryError' should not be mapped to
     `URLError'.

     This method will be called before any protocol-specific open
     method.

`PROTOCOL_open(req)'
     This method is _not_ defined in `BaseHandler', but subclasses
     should define it if they want to handle URLs with the given
     protocol.

     This method, if defined, will be called by the `parent'
     `OpenerDirector'.  Return values should be the same as for
     `default_open()'.

`unknown_open(req)'
     This method is NOT defined in `BaseHandler', but subclasses should
     define it if they want to catch all URLs with no specific
     registerd handler to open it.

     This method, if exists, will be called by the `parent'
     `OpenerDirector'.  Return values should be the same as for
     `default_open()'.

`http_error_default(req, fp, code, msg, hdrs)'
     This method is _not_ defined in `BaseHandler', but subclasses
     should override it if they intend to provide a catch-all for
     otherwise unhandled HTTP errors.  It will be called automatically
     by the  `OpenerDirector' getting the error, and should not
     normally be called in other circumstances.

     REQ will be a `Request' object, FP will be a file-like object with
     the HTTP error body, CODE will be the three-digit code of the
     error, MSG will be the user-visible explanation of the code and
     HDRS will be a mapping object with the headers of the error.

     Return values and exceptions raised should be the same as those of
     `urlopen()'.

`http_error_NNN(req, fp, code, msg, hdrs)'
     NNN should be a three-digit HTTP error code.  This method is also
     not defined in `BaseHandler', but will be called, if it exists, on
     an instance of a subclass, when an HTTP error with code NNN occurs.

     Subclasses should override this method to handle specific HTTP
     errors.

     Arguments, return values and exceptions raised should be the same
     as for `http_error_default()'.


automatically generated by info2www version 1.2.2.9