1.1 --- a/WebStack/Webware.py Sat Apr 24 20:34:47 2004 +0000
1.2 +++ b/WebStack/Webware.py Sat Apr 24 23:08:38 2004 +0000
1.3 @@ -8,6 +8,7 @@
1.4 from cgi import parse_qs
1.5 import StringIO
1.6 from Helpers import Environment
1.7 +from Helpers.Request import Cookie
1.8
1.9 class Transaction(Generic.Transaction):
1.10
1.11 @@ -192,6 +193,35 @@
1.12 except KeyError, exc:
1.13 return None
1.14
1.15 + def get_cookies(self):
1.16 +
1.17 + """
1.18 + A framework-specific method which obtains cookie information from the
1.19 + request.
1.20 +
1.21 + Returns a dictionary mapping cookie names to cookie objects.
1.22 + """
1.23 +
1.24 + cookies = {}
1.25 + for name, value in self.trans.request().cookies().items():
1.26 + cookies[name] = Cookie(name, value)
1.27 + return cookies
1.28 +
1.29 + def get_cookie(self, cookie_name):
1.30 +
1.31 + """
1.32 + A framework-specific method which obtains cookie information from the
1.33 + request.
1.34 +
1.35 + Returns a cookie object for the given 'cookie_name' or None if no such
1.36 + cookie exists.
1.37 + """
1.38 +
1.39 + try:
1.40 + return Cookie(cookie_name, self.trans.request().cookie(cookie_name))
1.41 + except KeyError:
1.42 + return None
1.43 +
1.44 # Response-related methods.
1.45
1.46 def get_response_stream(self):
1.47 @@ -247,4 +277,38 @@
1.48
1.49 return self.trans.response().setHeader("Content-Type", self.format_content_type(content_type))
1.50
1.51 + # Higher level response-related methods.
1.52 +
1.53 + def set_cookie(self, cookie):
1.54 +
1.55 + """
1.56 + A framework-specific method which stores the given 'cookie' object in
1.57 + the response.
1.58 + """
1.59 +
1.60 + self.trans.response().addCookie(cookie)
1.61 +
1.62 + def set_cookie_value(self, name, value, path=None, expires=None):
1.63 +
1.64 + """
1.65 + A framework-specific method which stores a cookie with the given 'name'
1.66 + and 'value' in the response.
1.67 +
1.68 + The optional 'path' is a string which specifies the scope of the cookie,
1.69 + and the optional 'expires' parameter is a value compatible with the
1.70 + time.time function, and indicates the expiry date/time of the cookie.
1.71 + """
1.72 +
1.73 + self.trans.response().setCookie(name, value, path, expires)
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 + self.trans.response().delCookie(cookie_name)
1.84 +
1.85 # vim: tabstop=4 expandtab shiftwidth=4