summaryrefslogtreecommitdiffstats
path: root/module/network/CookieJar.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/network/CookieJar.py')
-rw-r--r--module/network/CookieJar.py66
1 files changed, 29 insertions, 37 deletions
diff --git a/module/network/CookieJar.py b/module/network/CookieJar.py
index c05812334..a2b302776 100644
--- a/module/network/CookieJar.py
+++ b/module/network/CookieJar.py
@@ -1,50 +1,42 @@
# -*- coding: utf-8 -*-
+# @author: RaNaN
-"""
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
+import Cookie
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
+from datetime import datetime, timedelta
+from time import time
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
- @author: mkaay, RaNaN
-"""
+# monkey patch for 32 bit systems
+def _getdate(future=0, weekdayname=Cookie._weekdayname, monthname=Cookie._monthname):
+ dt = datetime.now() + timedelta(seconds=int(future))
+ return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % \
+ (weekdayname[dt.weekday()], dt.day, monthname[dt.month], dt.year, dt.hour, dt.minute, dt.second)
+
+Cookie._getdate = _getdate
-from time import time
-class CookieJar():
- def __init__(self, pluginname, account=None):
- self.cookies = {}
- self.plugin = pluginname
- self.account = account
+class CookieJar(Cookie.SimpleCookie):
- def addCookies(self, clist):
- for c in clist:
- name = c.split("\t")[5]
- self.cookies[name] = c
+ def getCookie(self, name):
+ return self[name].value
- def getCookies(self):
- return self.cookies.values()
+ def setCookie(self, domain, name, value, path="/", exp=None, secure="FALSE"):
+ self[name] = value
+ self[name]["domain"] = domain
+ self[name]["path"] = path
- def parseCookie(self, name):
- if name in self.cookies:
- return self.cookies[name].split("\t")[6]
+ # Value of expires should be integer if possible
+ # otherwise the cookie won't be used
+ if not exp:
+ expires = time() + 3600 * 24 * 180
else:
- return None
-
- def getCookie(self, name):
- return self.parseCookie(name)
+ try:
+ expires = int(exp)
+ except ValueError:
+ expires = exp
- 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[name]["expires"] = expires
- def clear(self):
- self.cookies = {}
+ if secure == "TRUE":
+ self[name]["secure"] = secure