1.1 --- a/WebStack/ModPython.py Fri Mar 26 18:59:55 2004 +0000
1.2 +++ b/WebStack/ModPython.py Sun Apr 18 23:39:08 2004 +0000
1.3 @@ -7,6 +7,11 @@
1.4 import Generic
1.5 from mod_python.util import parse_qs, FieldStorage
1.6 from mod_python import apache
1.7 +try:
1.8 + from mod_python import Cookie
1.9 +except ImportError:
1.10 + # NOTE: Should provide an alternative implementation.
1.11 + Cookie = None
1.12
1.13 class Transaction(Generic.Transaction):
1.14
1.15 @@ -161,6 +166,20 @@
1.16
1.17 return self.trans.user
1.18
1.19 + def get_cookies(self):
1.20 +
1.21 + """
1.22 + A framework-specific method which obtains cookie information from the
1.23 + request.
1.24 +
1.25 + Returns a dictionary mapping cookie names to cookie objects.
1.26 +
1.27 + NOTE: No additional information is passed to the underlying API despite
1.28 + NOTE: support for enhanced cookies in mod_python.
1.29 + """
1.30 +
1.31 + return Cookie.get_cookies(self.trans)
1.32 +
1.33 # Response-related methods.
1.34
1.35 def get_response_stream(self):
1.36 @@ -207,4 +226,61 @@
1.37
1.38 self.trans.content_type = self.format_content_type(content_type)
1.39
1.40 + def set_cookie(self, cookie):
1.41 +
1.42 + """
1.43 + A framework-specific method which stores the given 'cookie' object in
1.44 + the response.
1.45 + """
1.46 +
1.47 + if Cookie:
1.48 + Cookie.add_cookie(self.trans, cookie)
1.49 + else:
1.50 + # NOTE: Should raise an exception or provide an implementation.
1.51 + pass
1.52 +
1.53 + def set_cookie_value(self, name, value, path=None, expires=None):
1.54 +
1.55 + """
1.56 + A framework-specific method which stores a cookie with the given 'name'
1.57 + and 'value' in the response.
1.58 +
1.59 + The optional 'path' is a string which specifies the scope of the cookie,
1.60 + and the optional 'expires' parameter is a value compatible with the
1.61 + time.time function, and indicates the expiry date/time of the cookie.
1.62 + """
1.63 +
1.64 + if Cookie:
1.65 + cookie = Cookie.Cookie(name, value)
1.66 + if expires is not None:
1.67 + cookie.expires = expires
1.68 + if path is not None:
1.69 + cookie.path = path
1.70 + Cookie.add_cookie(self.trans, cookie)
1.71 + else:
1.72 + # NOTE: Should raise an exception or provide an implementation.
1.73 + pass
1.74 +
1.75 + def delete_cookie(self, cookie_name):
1.76 +
1.77 + """
1.78 + A framework-specific method which adds to the response a request that
1.79 + the cookie with the given 'cookie_name' be deleted/discarded by the
1.80 + client.
1.81 + """
1.82 +
1.83 + # Create a special cookie, given that we do not know whether the browser
1.84 + # has been sent the cookie or not.
1.85 + # NOTE: Magic discovered in Webware.
1.86 +
1.87 + if Cookie:
1.88 + cookie = Cookie.Cookie(cookie_name, "")
1.89 + cookie.path = "/"
1.90 + cookie.expires = 0
1.91 + cookie.max_age = 0
1.92 + Cookie.add_cookie(self.trans, cookie)
1.93 + else:
1.94 + # NOTE: Should raise an exception or provide an implementation.
1.95 + pass
1.96 +
1.97 # vim: tabstop=4 expandtab shiftwidth=4