1.1 --- a/WebStack/Generic.py Fri Mar 26 18:59:55 2004 +0000
1.2 +++ b/WebStack/Generic.py Sun Apr 18 23:39:08 2004 +0000
1.3 @@ -246,6 +246,17 @@
1.4
1.5 raise NotImplementedError, "get_user"
1.6
1.7 + def get_cookies(self):
1.8 +
1.9 + """
1.10 + A framework-specific method which obtains cookie information from the
1.11 + request.
1.12 +
1.13 + Returns a dictionary mapping cookie names to cookie objects.
1.14 + """
1.15 +
1.16 + raise NotImplementedError, "get_cookies"
1.17 +
1.18 # Response-related methods.
1.19
1.20 def get_response_stream(self):
1.21 @@ -292,6 +303,40 @@
1.22
1.23 raise NotImplementedError, "set_content_type"
1.24
1.25 + # Higher level response-related methods.
1.26 +
1.27 + def set_cookie(self, cookie):
1.28 +
1.29 + """
1.30 + A framework-specific method which stores the given 'cookie' object in
1.31 + the response.
1.32 + """
1.33 +
1.34 + raise NotImplementedError, "set_cookie"
1.35 +
1.36 + def set_cookie_value(self, name, value, path=None, expires=None):
1.37 +
1.38 + """
1.39 + A framework-specific method which stores a cookie with the given 'name'
1.40 + and 'value' in the response.
1.41 +
1.42 + The optional 'path' is a string which specifies the scope of the cookie,
1.43 + and the optional 'expires' parameter is a value compatible with the
1.44 + time.time function, and indicates the expiry date/time of the cookie.
1.45 + """
1.46 +
1.47 + raise NotImplementedError, "set_cookie_value"
1.48 +
1.49 + def delete_cookie(self, cookie_name):
1.50 +
1.51 + """
1.52 + A framework-specific method which adds to the response a request that
1.53 + the cookie with the given 'cookie_name' be deleted/discarded by the
1.54 + client.
1.55 + """
1.56 +
1.57 + raise NotImplementedError, "delete_cookie"
1.58 +
1.59 class Resource:
1.60
1.61 "A generic resource interface."
2.1 --- a/WebStack/ModPython.py Fri Mar 26 18:59:55 2004 +0000
2.2 +++ b/WebStack/ModPython.py Sun Apr 18 23:39:08 2004 +0000
2.3 @@ -7,6 +7,11 @@
2.4 import Generic
2.5 from mod_python.util import parse_qs, FieldStorage
2.6 from mod_python import apache
2.7 +try:
2.8 + from mod_python import Cookie
2.9 +except ImportError:
2.10 + # NOTE: Should provide an alternative implementation.
2.11 + Cookie = None
2.12
2.13 class Transaction(Generic.Transaction):
2.14
2.15 @@ -161,6 +166,20 @@
2.16
2.17 return self.trans.user
2.18
2.19 + def get_cookies(self):
2.20 +
2.21 + """
2.22 + A framework-specific method which obtains cookie information from the
2.23 + request.
2.24 +
2.25 + Returns a dictionary mapping cookie names to cookie objects.
2.26 +
2.27 + NOTE: No additional information is passed to the underlying API despite
2.28 + NOTE: support for enhanced cookies in mod_python.
2.29 + """
2.30 +
2.31 + return Cookie.get_cookies(self.trans)
2.32 +
2.33 # Response-related methods.
2.34
2.35 def get_response_stream(self):
2.36 @@ -207,4 +226,61 @@
2.37
2.38 self.trans.content_type = self.format_content_type(content_type)
2.39
2.40 + def set_cookie(self, cookie):
2.41 +
2.42 + """
2.43 + A framework-specific method which stores the given 'cookie' object in
2.44 + the response.
2.45 + """
2.46 +
2.47 + if Cookie:
2.48 + Cookie.add_cookie(self.trans, cookie)
2.49 + else:
2.50 + # NOTE: Should raise an exception or provide an implementation.
2.51 + pass
2.52 +
2.53 + def set_cookie_value(self, name, value, path=None, expires=None):
2.54 +
2.55 + """
2.56 + A framework-specific method which stores a cookie with the given 'name'
2.57 + and 'value' in the response.
2.58 +
2.59 + The optional 'path' is a string which specifies the scope of the cookie,
2.60 + and the optional 'expires' parameter is a value compatible with the
2.61 + time.time function, and indicates the expiry date/time of the cookie.
2.62 + """
2.63 +
2.64 + if Cookie:
2.65 + cookie = Cookie.Cookie(name, value)
2.66 + if expires is not None:
2.67 + cookie.expires = expires
2.68 + if path is not None:
2.69 + cookie.path = path
2.70 + Cookie.add_cookie(self.trans, cookie)
2.71 + else:
2.72 + # NOTE: Should raise an exception or provide an implementation.
2.73 + pass
2.74 +
2.75 + def delete_cookie(self, cookie_name):
2.76 +
2.77 + """
2.78 + A framework-specific method which adds to the response a request that
2.79 + the cookie with the given 'cookie_name' be deleted/discarded by the
2.80 + client.
2.81 + """
2.82 +
2.83 + # Create a special cookie, given that we do not know whether the browser
2.84 + # has been sent the cookie or not.
2.85 + # NOTE: Magic discovered in Webware.
2.86 +
2.87 + if Cookie:
2.88 + cookie = Cookie.Cookie(cookie_name, "")
2.89 + cookie.path = "/"
2.90 + cookie.expires = 0
2.91 + cookie.max_age = 0
2.92 + Cookie.add_cookie(self.trans, cookie)
2.93 + else:
2.94 + # NOTE: Should raise an exception or provide an implementation.
2.95 + pass
2.96 +
2.97 # vim: tabstop=4 expandtab shiftwidth=4