GNU Info

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

(python2.1-lib.info)URLopener Objects


Next: Urllib Examples Prev: urllib Up: urllib
Enter node , (file) or (file)node

URLopener Objects
-----------------

This manual section was written by Skip Montanaro <skip@mojam.com>.
`URLopener' and `FancyURLopener' objects have the following attributes.

`open(fullurl[, data])'
     Open FULLURL using the appropriate protocol.  This method sets up
     cache and proxy information, then calls the appropriate open
     method with its input arguments.  If the scheme is not recognized,
     `open_unknown()' is called.  The DATA argument has the same
     meaning as the DATA argument of `urlopen()'.

`open_unknown(fullurl[, data])'
     Overridable interface to open unknown URL types.

`retrieve(url[, filename[, reporthook[, data]]])'
     Retrieves the contents of URL and places it in FILENAME.  The
     return value is a tuple consisting of a local filename and either a
     `mimetools.Message' object containing the response headers (for
     remote URLs) or None (for local URLs).  The caller must then open
     and read the contents of FILENAME.  If FILENAME is not given and
     the URL refers to a local file, the input filename is returned.
     If the URL is non-local and FILENAME is not given, the filename is
     the output of `tempfile.mktemp()' with a suffix that matches the
     suffix of the last path component of the input URL.  If REPORTHOOK
     is given, it must be a function accepting three numeric
     parameters.  It will be called after each chunk of data is read
     from the network.  REPORTHOOK is ignored for local URLs.

     If the URL uses the `http:' scheme identifier, the optional DATA
     argument may be given to specify a `POST' request (normally the
     request type is `GET').  The DATA argument must in standard
     `application/x-www-form-urlencoded' format; see the `urlencode()'
     function below.

`version'
     Variable that specifies the user agent of the opener object.  To
     get `urllib' to tell servers that it is a particular user agent,
     set this in a subclass as a class variable or in the constructor
     before calling the base constructor.

The `FancyURLopener' class offers one additional method that should be
overloaded to provide the appropriate behavior:

`prompt_user_passwd(host, realm)'
     Return information needed to authenticate the user at the given
     host in the specified security realm.  The return value should be
     a tuple, `(USER, PASSWORD)', which can be used for basic
     authentication.

     The implementation prompts for this information on the terminal; an
     application should override this method to use an appropriate
     interaction model in the local environment.


automatically generated by info2www version 1.2.2.9