Module cookielib :: Class CookieJar
[hide private]
[frames] | no frames]

Class CookieJar

Known Subclasses:

Collection of HTTP cookies.

You may not need to know about this class: try urllib2.build_opener(HTTPCookieProcessor).open(url).

Instance Methods [hide private]
 
__init__(self, policy=None)
 
set_policy(self, policy)
 
_cookies_for_domain(self, domain, request)
 
_cookies_for_request(self, request)
Return a list of cookies to be returned to server.
 
_cookie_attrs(self, cookies)
Return a list of cookie-attributes to be returned to server.
 
add_cookie_header(self, request)
Add correct Cookie: header to request (urllib2.Request object).
 
_normalized_cookie_tuples(self, attrs_set)
Return list of tuples containing normalised cookie information.
 
_cookie_from_cookie_tuple(self, tup, request)
 
_cookies_from_attrs_set(self, attrs_set, request)
 
_process_rfc2109_cookies(self, cookies)
 
make_cookies(self, response, request)
Return sequence of Cookie objects extracted from response object.
 
set_cookie_if_ok(self, cookie, request)
Set a cookie if policy says it's OK to do so.
 
set_cookie(self, cookie)
Set a cookie, without checking whether or not it should be set.
 
extract_cookies(self, response, request)
Extract cookies from response, where allowable given the request.
 
clear(self, domain=None, path=None, name=None)
Clear some cookies.
 
clear_session_cookies(self)
Discard all session cookies.
 
clear_expired_cookies(self)
Discard all expired cookies.
 
__iter__(self)
 
__len__(self)
Return number of contained cookies.
 
__repr__(self)
 
__str__(self)
Class Variables [hide private]
  non_word_re = re.compile(r'\W')
  quote_re = re.compile(r'(["\\])')
  strict_domain_re = re.compile(r'\.?[^\.]*')
  domain_re = re.compile(r'[^\.]*')
  dots_re = re.compile(r'^\.+')
  magic_re = '^\\#LWP-Cookies-(\\d+\\.\\d+)'
Method Details [hide private]

_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).

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.

_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.

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_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.

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).