1.1 --- a/WebStack/ModPython.py Thu Sep 16 22:18:33 2004 +0000
1.2 +++ b/WebStack/ModPython.py Thu Sep 16 22:19:45 2004 +0000
1.3 @@ -5,7 +5,7 @@
1.4 """
1.5
1.6 import Generic
1.7 -from Helpers.Request import get_body_field, filter_fields
1.8 +from Helpers.Request import get_body_field, filter_fields, Cookie
1.9 from Helpers.Response import ConvertingStream
1.10 from mod_python.util import parse_qs, FieldStorage
1.11 from mod_python import apache
1.12 @@ -14,10 +14,11 @@
1.13 # The alternative session support requires cookie support of some kind.
1.14
1.15 try:
1.16 - from mod_python import Cookie
1.17 + from mod_python.Cookie import get_cookies, add_cookie, Cookie as SimpleCookie
1.18 + have_cookies = 1
1.19 except ImportError:
1.20 from Cookie import SimpleCookie
1.21 - Cookie = None
1.22 + have_cookies = 0
1.23 try:
1.24 from mod_python import Session
1.25 except ImportError:
1.26 @@ -42,7 +43,7 @@
1.27
1.28 # Support non-framework cookies.
1.29
1.30 - if Cookie is None:
1.31 + if not have_cookies:
1.32
1.33 # Define the incoming cookies.
1.34
1.35 @@ -273,10 +274,11 @@
1.36 NOTE: support for enhanced cookies in mod_python.
1.37 """
1.38
1.39 - if Cookie:
1.40 - return Cookie.get_cookies(self.trans)
1.41 + if have_cookies:
1.42 + found_cookies = get_cookies(self.trans)
1.43 else:
1.44 - return self.cookies_in
1.45 + found_cookies = self.cookies_in
1.46 + return self.process_cookies(found_cookies)
1.47
1.48 def get_cookie(self, cookie_name):
1.49
1.50 @@ -287,7 +289,11 @@
1.51 cookie exists.
1.52 """
1.53
1.54 - return self.get_cookies().get(cookie_name)
1.55 + cookie = self.get_cookies().get(self.encode_cookie_value(cookie_name))
1.56 + if cookie is not None:
1.57 + return Cookie(cookie_name, self.decode_cookie_value(cookie.value))
1.58 + else:
1.59 + return None
1.60
1.61 # Response-related methods.
1.62
1.63 @@ -360,15 +366,10 @@
1.64 Stores the given 'cookie' object in the response.
1.65 """
1.66
1.67 - if Cookie:
1.68 - Cookie.add_cookie(self.trans, cookie)
1.69 - else:
1.70 - # NOTE: If multiple cookies of the same name could be specified, this
1.71 - # NOTE: could need changing.
1.72 + # NOTE: If multiple cookies of the same name could be specified, this
1.73 + # NOTE: could need changing.
1.74
1.75 - cookie_out = SimpleCookie()
1.76 - cookie_out[cookie.name] = cookie.value
1.77 - self._write_cookie(cookie_out)
1.78 + self.set_cookie_value(cookie.name, cookie.value)
1.79
1.80 def set_cookie_value(self, name, value, path=None, expires=None):
1.81
1.82 @@ -380,18 +381,18 @@
1.83 time.time function, and indicates the expiry date/time of the cookie.
1.84 """
1.85
1.86 - # NOTE: We just hope that Cookie converts Unicode arguments to US-ASCII.
1.87 + name = self.encode_cookie_value(name)
1.88
1.89 - if Cookie:
1.90 - cookie = Cookie.Cookie(name, value)
1.91 + if have_cookies:
1.92 + cookie = SimpleCookie(name, self.encode_cookie_value(value))
1.93 if expires is not None:
1.94 cookie.expires = expires
1.95 if path is not None:
1.96 cookie.path = path
1.97 - Cookie.add_cookie(self.trans, cookie)
1.98 + add_cookie(self.trans, cookie)
1.99 else:
1.100 cookie_out = SimpleCookie()
1.101 - cookie_out[name] = value
1.102 + cookie_out[name] = self.encode_cookie_value(value)
1.103 if path is not None:
1.104 cookie_out[name]["path"] = path
1.105 if expires is not None:
1.106 @@ -409,18 +410,20 @@
1.107 # has been sent the cookie or not.
1.108 # NOTE: Magic discovered in Webware.
1.109
1.110 - if Cookie:
1.111 - cookie = Cookie.Cookie(cookie_name, "")
1.112 + name = self.encode_cookie_value(cookie_name)
1.113 +
1.114 + if have_cookies:
1.115 + cookie = SimpleCookie(name, "")
1.116 cookie.path = "/"
1.117 cookie.expires = 0
1.118 cookie.max_age = 0
1.119 - Cookie.add_cookie(self.trans, cookie)
1.120 + add_cookie(self.trans, cookie)
1.121 else:
1.122 cookie_out = SimpleCookie()
1.123 - cookie_out[cookie_name] = ""
1.124 - cookie_out[cookie_name]["path"] = "/"
1.125 - cookie_out[cookie_name]["expires"] = 0
1.126 - cookie_out[cookie_name]["max-age"] = 0
1.127 + cookie_out[name] = ""
1.128 + cookie_out[name]["path"] = "/"
1.129 + cookie_out[name]["expires"] = 0
1.130 + cookie_out[name]["max-age"] = 0
1.131 self._write_cookie(cookie_out)
1.132
1.133 def _write_cookie(self, cookie):