Defines which cookies get accepted from and returned to server.
May also modify cookies.
The subclass DefaultCookiePolicy defines the standard rules for Netscape and RFC 2965 cookies -- override that if you want a customised policy.
As well as implementing set_ok and return_ok, implementations of this interface must also supply the following attributes, indicating which protocols should be used, and how. These can be read and set at any time, though whether that makes complete sense from the protocol point of view is doubtful.
Public attributes:
netscape: implement netscape protocol rfc2965: implement RFC 2965 protocol rfc2109_as_netscape: WARNING: This argument will change or go away if is not accepted into the Python standard library in this form! If true, treat RFC 2109 cookies as though they were Netscape cookies. The default is for this attribute to be None, which means treat 2109 cookies as RFC 2965 cookies unless RFC 2965 handling is switched off (which it is, by default), and as Netscape cookies otherwise. hide_cookie2: don't add Cookie2 header to requests (the presence of this header indicates to the server that we understand RFC 2965 cookies)
There are no base classes.
There are no implemented interfaces.
There are no attributes in this class.
domain_return_ok(domain, request)
Return false if cookies should not be returned, given cookie domain.
This is here as an optimization, to remove the need for checking every cookie with a particular domain (which may involve reading many files). The default implementations of domain_return_ok and path_return_ok (return True) leave all the work to return_ok.
If domain_return_ok returns true for the cookie domain, path_return_ok is called for the cookie path. Otherwise, path_return_ok and return_ok are never called for that cookie domain. If path_return_ok returns true, return_ok is called with the Cookie object itself for a full check. Otherwise, return_ok is never called for that cookie path.
Note that domain_return_ok is called for every cookie domain, not just for the request domain. For example, the function might be called with both ".acme.com" and "www.acme.com" if the request domain is "www.acme.com". The same goes for path_return_ok.
For argument documentation, see the docstring for return_ok.
path_return_ok(path, request)
Return false if cookies should not be returned, given cookie path.
See the docstring for domain_return_ok.
return_ok(cookie, request)
Return true if (and only if) cookie should be returned to server.
cookie: mechanize.Cookie object request: object implementing the interface defined by CookieJar.add_cookie_header.__doc__
set_ok(cookie, request)
Return true if (and only if) cookie should be accepted from server.
cookie: mechanize.Cookie object request: object implementing the interface defined by CookieJar.extract_cookies.__doc__