| |
- cookielib.FileCookieJar(cookielib.CookieJar)
-
- MozillaCookieJar
class MozillaCookieJar(cookielib.FileCookieJar) |
|
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).
|
| |
- __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.
- __iter__(self)
- no doc string
- __len__(self)
- Return number of contained cookies.
- __repr__(self)
- no doc string
- __str__(self)
- no doc string
- _cookie_attrs(self, cookies)
- Return a list of cookie-attributes to be returned to server.
-
- like ['foo="bar"; $Path="/"', ...]
-
- The $Version attribute is also added when appropriate (currently only
- once per request).
- _cookie_from_cookie_tuple(self, tup, request)
- no doc string
- _cookies_for_domain(self, domain, request)
- no doc string
- _cookies_for_request(self, request)
- Return a list of cookies to be returned to server.
- _cookies_from_attrs_set(self, attrs_set, request)
- no doc string
- _normalized_cookie_tuples(self, attrs_set)
- Return list of tuples containing normalised cookie information.
-
- attrs_set is the list of lists of key,value pairs extracted from
- the Set-Cookie or Set-Cookie2 headers.
-
- Tuples are name, value, standard, rest, where name and value are the
- cookie name and value, standard is a dictionary containing the standard
- cookie-attributes (discard, secure, version, expires or max-age,
- domain, path and port) and rest is a dictionary containing the rest of
- the cookie-attributes.
- _really_load(self, f, filename, ignore_discard, ignore_expires)
- no doc string
- 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.
- clear_expired_cookies(self)
- 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(self)
- 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.
- load(self, filename=None, ignore_discard=False, ignore_expires=False)
- Load cookies from a file.
- make_cookies(self, response, request)
- Return sequence of Cookie objects extracted from response object.
- 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.
- save(self, filename=None, ignore_discard=False, ignore_expires=False)
- no doc string
- 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)
- no doc string
| |