| | |
- Absent
- Cookie
- CookieJar
-
- FileCookieJar
- CookiePolicy
-
- DefaultCookiePolicy
- exceptions.Exception
-
- LoadError
class Absent |
| |
# Used as second parameter to dict.get() method, to distinguish absent
# dict key from one with a None value. |
| |
|
class Cookie |
| |
HTTP Cookie.
This class represents both Netscape and RFC 2965 cookies.
This is deliberately a very simple class. It just holds attributes. It's
possible to construct Cookie instances that don't comply with the cookie
standards. CookieJar.make_cookies is the factory function for Cookie
objects -- it deals with cookie parsing, supplying defaults, and
normalising to the representation used in this class. CookiePolicy is
responsible for checking them to see whether they should be accepted from
and returned to the server.
Note that the port may be present in the headers, but unspecified ("Port"
rather than"Port=80", for example); if this is the case, port is None. |
| |
Methods defined here:
- __init__(self, version, name, value, port, port_specified, domain, domain_specified, domain_initial_dot, path, path_specified, secure, expires, discard, comment, comment_url, rest)
- __repr__(self)
- __str__(self)
- get_nonstandard_attr(self, name, default=None)
- has_nonstandard_attr(self, name)
- is_expired(self, now=None)
- set_nonstandard_attr(self, name, value)
|
class CookieJar |
| |
Collection of HTTP cookies.
You may not need to know about this class: try
urllib2.build_opener(HTTPCookieProcessor).open(url). |
| |
Methods defined here:
- __init__(self, policy=None)
- __iter__(self)
- __len__(self)
- Return number of contained cookies.
- __repr__(self)
- __str__(self)
- 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.
- 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 defined here:
- domain_re = <_sre.SRE_Pattern object>
- dots_re = <_sre.SRE_Pattern object>
- magic_re = r'^\#LWP-Cookies-(\d+\.\d+)'
- non_word_re = <_sre.SRE_Pattern object>
- quote_re = <_sre.SRE_Pattern object>
- strict_domain_re = <_sre.SRE_Pattern object>
|
class CookiePolicy |
| |
Defines which cookies get accepted from and returned to server.
May also modify cookies, though this is probably a bad idea.
The subclass DefaultCookiePolicy defines the standard rules for Netscape
and RFC 2965 cookies -- override that if you want a customised policy. |
| |
Methods defined here:
- domain_return_ok(self, domain, request)
- Return false if cookies should not be returned, given cookie domain.
- path_return_ok(self, path, request)
- Return false if cookies should not be returned, given cookie path.
- return_ok(self, cookie, request)
- Return true if (and only if) cookie should be returned to server.
- set_ok(self, cookie, request)
- Return true if (and only if) cookie should be accepted from server.
Currently, pre-expired cookies never get this far -- the CookieJar
class deletes such cookies itself.
|
class DefaultCookiePolicy(CookiePolicy) |
| |
Implements the standard rules for accepting and returning cookies. |
| |
Methods defined here:
- __init__(self, blocked_domains=None, allowed_domains=None, netscape=True, rfc2965=False, hide_cookie2=False, strict_domain=False, strict_rfc2965_unverifiable=True, strict_ns_unverifiable=False, strict_ns_domain=0, strict_ns_set_initial_dollar=False, strict_ns_set_path=False)
- Constructor arguments should be passed as keyword arguments only.
- allowed_domains(self)
- Return None, or the sequence of allowed domains (as a tuple).
- blocked_domains(self)
- Return the sequence of blocked domains (as a tuple).
- domain_return_ok(self, domain, request)
- is_blocked(self, domain)
- is_not_allowed(self, domain)
- path_return_ok(self, path, request)
- return_ok(self, cookie, request)
- If you override .return_ok(), be sure to call this method. If it
returns false, so should your subclass (assuming your subclass wants to
be more strict about which cookies to return).
- return_ok_domain(self, cookie, request)
- return_ok_expires(self, cookie, request)
- return_ok_port(self, cookie, request)
- return_ok_secure(self, cookie, request)
- return_ok_verifiability(self, cookie, request)
- return_ok_version(self, cookie, request)
- set_allowed_domains(self, allowed_domains)
- Set the sequence of allowed domains, or None.
- set_blocked_domains(self, blocked_domains)
- Set the sequence of blocked domains.
- set_ok(self, cookie, request)
- If you override .set_ok(), be sure to call this method. If it returns
false, so should your subclass (assuming your subclass wants to be more
strict about which cookies to accept).
- set_ok_domain(self, cookie, request)
- set_ok_name(self, cookie, request)
- set_ok_path(self, cookie, request)
- set_ok_port(self, cookie, request)
- set_ok_verifiability(self, cookie, request)
- set_ok_version(self, cookie, request)
Data and other attributes defined here:
- DomainLiberal = 0
- DomainRFC2965Match = 4
- DomainStrict = 3
- DomainStrictNoDots = 1
- DomainStrictNonDomain = 2
|
class FileCookieJar(CookieJar) |
| |
CookieJar that can be loaded from and saved to a file. |
| |
Methods defined here:
- __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.
- save(self, filename=None, ignore_discard=False, ignore_expires=False)
- Save cookies to a file.
Methods inherited from CookieJar:
- __iter__(self)
- __len__(self)
- Return number of contained cookies.
- __repr__(self)
- __str__(self)
- 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.
- 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 CookieJar:
- domain_re = <_sre.SRE_Pattern object>
- dots_re = <_sre.SRE_Pattern object>
- magic_re = r'^\#LWP-Cookies-(\d+\.\d+)'
- non_word_re = <_sre.SRE_Pattern object>
- quote_re = <_sre.SRE_Pattern object>
- strict_domain_re = <_sre.SRE_Pattern object>
|
|