diff options
Diffstat (limited to 'cgi')
-rw-r--r-- | cgi/framework.py | 35 | ||||
-rwxr-xr-x | cgi/weabot.py | 7 |
2 files changed, 23 insertions, 19 deletions
diff --git a/cgi/framework.py b/cgi/framework.py index 053bef0..2cfabe3 100644 --- a/cgi/framework.py +++ b/cgi/framework.py @@ -314,7 +314,10 @@ def getRandomIco(): def N_(message): return message def getCookie(self, value=""): - return urllib.unquote_plus(self._cookies[value].value) + try: + return urllib.unquote_plus(self._cookies[value].value) + except KeyError: + return None def reCookie(self, key, value=""): board = Settings._.BOARD @@ -324,14 +327,14 @@ def setCookie(self, key, value="", max_age=None, expires=None, path="/", domain= """ Copied from Colubrid """ - if self._cookies is None: - self._cookies = SimpleCookie() - self._cookies[key] = urllib.quote_plus(value) + if self._newcookies is None: + self._newcookies = SimpleCookie() + self._newcookies[key] = urllib.quote_plus(value) if not max_age is None: - self._cookies[key]["max-age"] = max_age + self._newcookies[key]["max-age"] = max_age if not expires is None: if isinstance(expires, basestring): - self._cookies[key]["expires"] = expires + self._newcookies[key]["expires"] = expires expires = None elif isinstance(expires, datetime): expires = expires.utctimetuple() @@ -350,26 +353,26 @@ def setCookie(self, key, value="", max_age=None, expires=None, path="/", domain= ) d = "%s, %s %02d:%02d:%02d GMT" % (day, date, now.tm_hour, now.tm_min, now.tm_sec) - self._cookies[key]["expires"] = d + self._newcookies[key]["expires"] = d if not path is None: - self._cookies[key]["path"] = path + self._newcookies[key]["path"] = path if not domain is None: if domain != "THIS": - self._cookies[key]["domain"] = domain + self._newcookies[key]["domain"] = domain else: - self._cookies[key]["domain"] = Settings.DOMAIN + self._newcookies[key]["domain"] = Settings.DOMAIN if not secure is None: - self._cookies[key]["secure"] = secure + self._newcookies[key]["secure"] = secure def deleteCookie(self, key): """ Copied from Colubrid """ - if self._cookies is None: - self._cookies = SimpleCookie() - if not key in self._cookies: - self._cookies[key] = "" - self._cookies[key]["max-age"] = 0 + if self._newcookies is None: + self._newcookies = SimpleCookie() + if not key in self._newcookies: + self._newcookies[key] = "" + self._newcookies[key]["max-age"] = 0 def elapsed_time(seconds, suffixes=['y','w','d','h','m','s'], add_s=False, separator=' '): """ diff --git a/cgi/weabot.py b/cgi/weabot.py index f5451d9..f576f91 100755 --- a/cgi/weabot.py +++ b/cgi/weabot.py @@ -110,13 +110,14 @@ class weabot(object): self.handleCookies() def handleResponse(self): - if self._cookies is not None: - for cookie in self._cookies.values(): - self.headers.append(("Set-Cookie", cookie.output(header=""))) + if self._newcookies: + for newcookie in self._newcookies.values(): + self.headers.append(("Set-Cookie", newcookie.output(header=""))) def handleCookies(self): self._cookies = SimpleCookie() self._cookies.load(self.environ.get("HTTP_COOKIE", "")) + self._newcookies = None def run(self): path_split = self.environ["PATH_INFO"].split("/") |