[ANN] ClientCookie: HTTP cookie handling on client end

John J. Lee jjl@pobox.com
Tue, 23 Apr 2002 18:35:19 +0100

ClientCookie 0.02a

or http://wwwsearch.sourceforge.net/ClientCookie-002a.zip

WARNING: this is an alpha release: interfaces may change (probably not,
though).  Since this is a port rather than completely new code though, it
does actually seem to work quite well!  Also note that redirects are not
handled correctly yet when used with the extended urllib2 callables
(urlopen, HTTPHandler, etc): they'll probably accept and send cookies when
they shouldn't in some cases.

This is a Python port of Gisle Aas' HTTP::Cookies Perl module from the
libwww-perl web client library.  The purpose of this Python package is
to allow the easy extraction of HTTP cookies from "Set-Cookie" and
"Set-Cookie2" (RFC 2965) headers, and generation of "Cookie" and
"Cookie2" headers appropriate for a particular HTTP request.  Incoming
cookies are checked for acceptability based on the host name, etc.
Cookies are only set on outgoing requests if they match the request's
host name, path, etc.

Python 2.0 or above is required (though I may fix it to work with 1.52
eventually), and urllib2 is recommended.  Note that the version of
urllib2.py from Python 2.0 is too old: you need the version from Python
2.1 (available from the source distribution or CVS from
http://www.python.org), which itself depends on inspect.py -- just copy
them into your Python search path.

 import ClientCookie
 import urllib2
 request = urllib2.Request("http://www.acme.com/")
 # note we're using the urlopen from ClientCookie, not urllib2
 result = ClientCookie.urlopen(request)
 # let's say this next request requires a cookie that was set in result
 request2 = urllib2.Request("http://www.acme.com/flying_machines.html")
 result2 = ClientCookie.urlopen(request)

(lower-level usage is also possible)

Distrubuted under the Perl Artistic License.

John J. Lee <jjl@pobox.com>
April 2002