cookielib

HTTP cookie handling for web clients.

This module has (now fairly distant) origins in Gisle Aas’ Perl module HTTP::Cookies, from the libwww-perl library.

Docstrings, comments and debug strings in this code refer to the attributes of the HTTP cookie system as cookie-attributes, to distinguish them clearly from Python attributes.

Class diagram (note that BSDDBCookieJar and the MSIE* classes are not distributed with the Python standard library, but are available from http://wwwsearch.sf.net/):

CookieJar____ /
FileCookieJar
/ |
MozillaCookieJar | LWPCookieJar
|
—MSIEBase |
/ | |
/ MSIEDBCookieJar BSDDBCookieJar

|/

MSIECookieJar

Functions

deepvalues(mapping) Iterates over nested mapping, depth-first, in sorted order by key.
domain_match(A, B) Return True if domain A domain-matches domain B, according to RFC 2965.
eff_request_host(request) Return a tuple (request-host, effective request-host name).
escape_path(path) Escape any invalid characters in HTTP URL, and uppercase all escapes.
http2time(text) Returns time in seconds since epoch of time represented by a string.
is_HDN(text) Return True if text is a host domain name.
is_third_party(request) RFC 2965, section 3.3.6:
iso2time(text) As for http2time, but parses the ISO 8601 formats:
join_header_words(lists) Do the inverse (almost) of the conversion done by split_header_words.
liberal_is_HDN(text) Return True if text is a sort-of-like a host domain name.
lwp_cookie_str(cookie) Return string representation of Cookie in the LWP cookie file format.
offset_from_tz_string(tz)
parse_ns_headers(ns_headers) Ad-hoc parser for Netscape protocol cookie-attributes.
reach(h) Return reach of host h, as defined by RFC 2965, section 1.
request_host(request) Return request-host, as defined by RFC 2965.
request_path(request) Path component of request-URI, as defined by RFC 2965.
request_port(request)
split_header_words(header_values) Parse header values into a list of lists containing key,value pairs.
time2isoz([t]) Return a string representing time in seconds since epoch, t.
time2netscape([t]) Return a string representing time in seconds since epoch, t.
timegm(tuple) Unrelated but handy function to calculate Unix timestamp from GMT.
unmatched(match) Return unmatched part of re.Match object.
uppercase_escaped_char(match)
user_domain_match(A, B) For blocking/accepting domains.
vals_sorted_by_key(adict)

Classes

Absent
Cookie(version, name, value, port, ...[, ...]) HTTP Cookie.
CookieJar([policy]) Collection of HTTP cookies.
CookiePolicy Defines which cookies get accepted from and returned to server.
DefaultCookiePolicy([blocked_domains, ...]) Implements the standard rules for accepting and returning cookies.
FileCookieJar([filename, delayload, policy]) CookieJar that can be loaded from and saved to a file.
LWPCookieJar([filename, delayload, policy]) The LWPCookieJar saves a sequence of “Set-Cookie3” lines.
MozillaCookieJar([filename, delayload, policy]) WARNING: you may want to backup your browser’s cookies file if you use this class to save cookies.

Exceptions

LoadError