diff options
Diffstat (limited to 'module/network/CookieJar.py')
-rw-r--r-- | module/network/CookieJar.py | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/module/network/CookieJar.py b/module/network/CookieJar.py index b2cbba504..c9ae6cb6c 100644 --- a/module/network/CookieJar.py +++ b/module/network/CookieJar.py @@ -17,51 +17,34 @@ @author: mkaay, RaNaN """ -from cookielib import CookieJar as PyCookieJar -from cookielib import Cookie from time import time -class CookieJar(PyCookieJar): - def __init__(self, pluginName=None, account=None): - PyCookieJar.__init__(self) - self.plugin = pluginName +class CookieJar(): + def __init__(self, pluginname, account=None): + self.cookies = {} + self.plugin = pluginname self.account = account - def getCookie(self, name): - print "getCookie not implemented!" - return None - - def setCookie(self, domain, name, value, path="/"): - c = Cookie(version=0, name=name, value=value, port=None, port_specified=False, - domain=domain, domain_specified=False, - domain_initial_dot=(domain.startswith(".")), path=path, path_specified=True, - secure=False, expires=None, discard=True, comment=None, - comment_url=None, rest={'HttpOnly': None}, rfc2109=False) - self.set_cookie(c) - - def add_cookie_header(self, request): - self._cookies_lock.acquire() - try: + def addCookies(self, clist): + for c in clist: + name = c.split("\t")[5] + self.cookies[name] = c - self._policy._now = self._now = int(time()) + def getCookies(self): + return self.cookies.values() - cookies = self._cookies_for_request(request) + def parseCookie(self, name): + if self.cookies.has_key(name): + return self.cookies[name].split("\t")[6] + else: + return None - attrs = self._cookie_attrs(cookies) - if attrs: - if not request.has_header("Cookie"): - request.add_header( - "Cookie", "; ".join(attrs)) - - # if necessary, advertise that we know RFC 2965 - if (self._policy.rfc2965 and not self._policy.hide_cookie2 and - not request.has_header("Cookie2")): - for cookie in cookies: - if cookie.version != 1: - request.add_header("Cookie2", '$Version="1"') - break + def getCookie(self, name): + return self.parseCookie(name) - finally: - self._cookies_lock.release() + def setCookie(self, domain, name, value, path="/", exp=time()+3600*24*180): + s = ".%s TRUE %s FALSE %s %s %s" % (domain, path, exp, name, value) + self.cookies[name] = s - self.clear_expired_cookies() + def clear(self): + self.cookies = {}
\ No newline at end of file |