||WARNING: you may want to backup your browser's cookies file if you use|
this class to save cookies. I *think* it works, but there have been
bugs in the past!
This class differs from CookieJar only in the format it uses to save and
load cookies to and from a file. This class uses the Mozilla/Netscape
`cookies.txt' format. lynx uses this file format, too.
Don't expect cookies saved while the browser is running to be noticed by
the browser (in fact, Mozilla on unix will overwrite your saved cookies if
you change them on disk while it's running; on Windows, you probably can't
save at all while the browser is running).
Note that the Mozilla/Netscape format will downgrade RFC2965 cookies to
Netscape cookies on saving.
In particular, the cookie version and port number information is lost,
together with information about whether or not Path, Port and Discard were
specified by the Set-Cookie2 (or Set-Cookie) header, and whether or not the
domain as set in the HTTP header started with a dot (yes, I'm aware some
domains in Netscape files start with a dot and some don't -- trust me, you
really don't want to know any more about this).
Note that though Mozilla and Netscape use the same format, they use
slightly different headers. The class saves cookies using the Netscape
header by default (Mozilla can cope with that).
- Method resolution order:
Methods defined here:
- save(self, filename=None, ignore_discard=False, ignore_expires=False)
Data and other attributes defined here:
- header = ' # Netscape HTTP Cookie File\n # http://www...l\n # This is a generated file! Do not edit.\n\n'
- magic_re = '#( Netscape)? HTTP Cookie File'
Methods inherited from cookielib.FileCookieJar:
- __init__(self, filename=None, delayload=False, policy=None)
- Cookies are NOT loaded from the named file until either the .load() or
.revert() method is called.
- load(self, filename=None, ignore_discard=False, ignore_expires=False)
- Load cookies from a file.
- revert(self, 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.
Methods inherited from cookielib.CookieJar:
- Return number of contained cookies.
- add_cookie_header(self, request)
- Add correct Cookie: header to request (urllib2.Request object).
The Cookie2 header is also added unless policy.hide_cookie2 is true.
- clear(self, 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.
- 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).
- Discard all session cookies.
Note that the .save() method won't save session cookies anyway, unless
you ask otherwise by passing a true ignore_discard argument.
- extract_cookies(self, response, request)
- Extract cookies from response, where allowable given the request.
- make_cookies(self, response, request)
- Return sequence of Cookie objects extracted from response object.
- set_cookie(self, cookie)
- Set a cookie, without checking whether or not it should be set.
- set_cookie_if_ok(self, cookie, request)
- Set a cookie if policy says it's OK to do so.
- set_policy(self, policy)
Data and other attributes inherited from cookielib.CookieJar:
- domain_re = <_sre.SRE_Pattern object>
- dots_re = <_sre.SRE_Pattern object>
- non_word_re = <_sre.SRE_Pattern object>
- quote_re = <_sre.SRE_Pattern object>
- strict_domain_re = <_sre.SRE_Pattern object>