CookieJar objects support the iterator protocol for iterating over contained Cookie objects.
CookieJar has the following methods:
request) |
If policy allows (ie. the rfc2965 and hide_cookie2 attributes of the CookieJar's CookiePolicy instance are true and false respectively), the Cookie2: header is also added when appropriate.
The request object (usually a urllib2.Request instance) must support the methods get_full_url(), get_host(), get_type(), unverifiable(), get_origin_req_host(), has_header(), get_header(), header_items(), and add_unredirected_header(),as documented by urllib2.
response, request) |
The CookieJar will look for allowable Set-Cookie: and Set-Cookie2: headers in the response argument, and store cookies as appropriate (subject to the CookiePolicy.set_ok() method's approval).
The response object (usually the result of a call to urllib2.urlopen(), or similar) should support an info() method, which returns an object with a getallmatchingheaders() method (usually a mimetools.Message instance).
The request object (usually a urllib2.Request instance) must support the methods get_full_url(), get_host(), unverifiable(), and get_origin_req_host(), as documented by urllib2. The request is used to set default values for cookie-attributes as well as for checking that the cookie is allowed to be set.
policy) |
response, request) |
See the documentation for extract_cookies for the interfaces required of the response and request arguments.
cookie, request) |
cookie) |
[domain[, path[, name]]]) |
If invoked without arguments, clear all cookies. If given a single argument, only cookies belonging to that domain will be removed. If given two arguments, cookies belonging to the specified domain and URL path are removed. If given three arguments, then the cookie with the specified domain, path and name is removed.
Raises KeyError if no matching cookie exists.
) |
Discards all contained cookies that have a true discard
attribute (usually because they had either no max-age
or
expires
cookie-attribute, or an explicit discard
cookie-attribute). For interactive browsers, the end of a session
usually corresponds to closing the browser window.
Note that the save() method won't save session cookies anyway, unless you ask otherwise by passing a true ignore_discard argument.
FileCookieJar implements the following additional methods:
filename=None, ignore_discard=False, ignore_expires=False) |
This base class raises NotImplementedError. Subclasses may leave this method unimplemented.
filename is the name of file in which to save cookies. If filename is not specified, self.filename is used (whose default is the value passed to the constructor, if any); if self.filename is None, ValueError is raised.
ignore_discard: save even cookies set to be discarded. ignore_expires: save even cookies that have expired
The file is overwritten if it already exists, thus wiping all the cookies it contains. Saved cookies can be restored later using the load() or revert() methods.
filename=None, ignore_discard=False, ignore_expires=False) |
Old cookies are kept unless overwritten by newly loaded ones.
Arguments are as for save().
The named file must be in the format understood by the class, or LoadError will be raised. Also, IOError may be raised, for example if the file does not exist. Note: For backwards-compatibility with Python 2.4 (which raised an IOError), LoadError is a subclass of IOError.
filename=None, ignore_discard=False, ignore_expires=False) |
revert() can raise the same exceptions as load(). If there is a failure, the object's state will not be altered.
FileCookieJar instances have the following public attributes:
See About this document... for information on suggesting changes.