The LWPCookieJar saves a sequence of"Set-Cookie3" lines. "Set-Cookie3" is the format used by the libwww-perl libary, not known to be compatible with any browser, but which is easy to read and doesn't lose information about RFC 2965 cookies.
Additional methods
as_lwp_str(ignore_discard=True, ignore_expired=True)
There are no implemented interfaces.
domain_re
(type: SRE_Pattern
)
<_sre.SRE_Pattern object at 0x41696360>
dots_re
(type: SRE_Pattern
)
<_sre.SRE_Pattern object at 0x41695480>
magic_re
(type:
str
)
'^\\#LWP-Cookies-(\\d+\\.\\d+)'
non_word_re
(type: SRE_Pattern
)
<_sre.SRE_Pattern object at 0x41690608>
quote_re
(type: SRE_Pattern
)
<_sre.SRE_Pattern object at 0x416953e0>
strict_domain_re
(type: SRE_Pattern
)
<_sre.SRE_Pattern object at 0x41695430>
add_cookie_header(request)
Add correct Cookie: header to request (urllib2.Request object).
The Cookie2 header is also added unless policy.hide_cookie2 is true.
The request object (usually a urllib2.Request instance) must support the methods get_full_url, get_host, get_type, has_header, get_header, header_items and add_unredirected_header, as documented by urllib2, and the port attribute (the port number). Actually, RequestUpgradeProcessor will automatically upgrade your Request object to one with has_header, get_header, header_items and add_unredirected_header, if it lacks those methods, for compatibility with pre-2.4 versions of urllib2.
as_lwp_str(ignore_discard=True, ignore_expires=True)
Return cookies as a string of " "-separated "Set-Cookie3" headers.
ignore_discard and ignore_expires: see docstring for FileCookieJar.save
clear(domain=None, path=None, name=None)
Clear some cookies.
Invoking this method without arguments will 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 path within that domain are removed. If given three arguments, then the cookie with the specified name, path and domain is removed.
Raises KeyError if no matching cookie exists.
clear_expired_cookies()
Discard all expired cookies.
You probably don't need to call this method: expired cookies are never sent back to the server (provided you're using DefaultCookiePolicy), this method is called by CookieJar itself every so often, and the save method won't save expired cookies anyway (unless you ask otherwise by passing a true ignore_expires argument).
clear_session_cookies()
Discard all session cookies.
Discards all cookies held by object which had either no Max-Age or Expires cookie-attribute or an explicit Discard cookie-attribute, or which otherwise have ended up with a true discard 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.
extract_cookies(response, request)
Extract cookies from response, where allowable given the request.
Look for allowable Set-Cookie: and Set-Cookie2: headers in the response object passed as argument. Any of these headers that are found are used to update the state of the object (subject to the policy.set_ok method's approval).
The response object (usually be the result of a call to
mechanize.urlopen, or similar) should support an info method, which
returns a mimetools.Message object (in fact, the mimetools.Message
object
may be any object that provides a getallmatchingheaders
method).
The request object (usually a urllib2.Request instance) must support the methods get_full_url and get_host, as documented by urllib2, and the port attribute (the port number). The request is used to set default values for cookie-attributes as well as for checking that the cookie is OK to be set.
load(filename=None, ignore_discard=False, ignore_expires=False)
Load cookies from a file.
Old cookies are kept unless overwritten by newly loaded ones.
Arguments are as for .save().
If filename is not specified, self.filename is used; if self.filename is None, ValueError is raised. The named file must be in the format understood by the class, or LoadError will be raised. This format will be identical to that written by the save method, unless the load format is not sufficiently well understood (as is the case for MSIECookieJar).
make_cookies(response, request)
Return sequence of Cookie objects extracted from response object.
See extract_cookies.__doc__ for the interfaces required of the response and request arguments.
revert(filename=None, ignore_discard=False, ignore_expires=False)
Clear all cookies and reload cookies from a saved file.
Raises LoadError (or IOError) if reversion is not successful; the object's state will not be altered if this happens.
save(filename=None, ignore_discard=False, ignore_expires=False)
set_cookie(cookie)
Set a cookie, without checking whether or not it should be set.
cookie: mechanize.Cookie instance
set_cookie_if_ok(cookie, request)
Set a cookie if policy says it's OK to do so.
cookie: mechanize.Cookie instance request: see extract_cookies.__doc__ for the required interface
set_policy(policy)
There are no known subclasses.