Added equality check for Cookies, and use that to augment the retrieved cookies.

This commit is contained in:
Bastian Kleineidam 2010-10-13 22:35:36 +02:00
parent 2a7292845c
commit 415efe262e
2 changed files with 5 additions and 4 deletions

View file

@ -36,7 +36,7 @@ class CookieJar (object):
@synchronized(_lock)
def add (self, headers, scheme, host, path):
"""Parse cookie values, add to cache."""
jar = set()
jar = self.cache.setdefault(host, set())
for h in headers.getallmatchingheaders("Set-Cookie"):
# RFC 2109 (Netscape) cookie type
try:

View file

@ -279,6 +279,10 @@ class HttpCookie (object):
for k, v in self.attributes.items() if k != "version"])
return "; ".join(parts)
def __eq__ (self, other):
return isinstance(other, HttpCookie) and \
self.server_header_value() == other.server_header_value()
class NetscapeCookie (HttpCookie):
"""Parses RFC 2109 (Netscape) cookies."""
@ -312,9 +316,6 @@ class Rfc2965Cookie (HttpCookie):
return quote(value)
# XXX more methods (equality test)
def from_file (filename):
"""Parse cookie data from a text file in HTTP header format.