1.1 --- a/WebStack/BaseHTTPRequestHandler.py Sun Sep 05 11:12:32 2004 +0000
1.2 +++ b/WebStack/BaseHTTPRequestHandler.py Sun Sep 05 15:51:44 2004 +0000
1.3 @@ -8,6 +8,7 @@
1.4 from Helpers.Request import MessageBodyStream, get_body_fields, get_storage_items
1.5 from Helpers.Response import ConvertingStream
1.6 from Helpers.Auth import UserInfo
1.7 +from Helpers.Session import SessionStore
1.8 from cgi import parse_qs, FieldStorage
1.9 import Cookie
1.10 from StringIO import StringIO
1.11 @@ -44,6 +45,10 @@
1.12
1.13 self.storage_body = None
1.14
1.15 + # Special objects retained throughout the transaction.
1.16 +
1.17 + self.session_store = None
1.18 +
1.19 def commit(self):
1.20
1.21 """
1.22 @@ -51,6 +56,13 @@
1.23 objects.
1.24 """
1.25
1.26 + # Close the session store.
1.27 +
1.28 + if self.session_store is not None:
1.29 + self.session_store.close()
1.30 +
1.31 + # Prepare the response.
1.32 +
1.33 self.trans.send_response(self.response_code)
1.34 if self.content_type is not None:
1.35 self.trans.send_header("Content-Type", str(self.content_type))
1.36 @@ -370,6 +382,42 @@
1.37 self.cookies_out[cookie_name]["expires"] = 0
1.38 self.cookies_out[cookie_name]["max-age"] = 0
1.39
1.40 + # Session-related methods.
1.41 +
1.42 + def get_session(self, create=1):
1.43 +
1.44 + """
1.45 + Gets a session corresponding to an identifier supplied in the
1.46 + transaction.
1.47 +
1.48 + If no session has yet been established according to information
1.49 + provided in the transaction then the optional 'create' parameter
1.50 + determines whether a new session will be established.
1.51 +
1.52 + Where no session has been established and where 'create' is set to 0
1.53 + then None is returned. In all other cases, a session object is created
1.54 + (where appropriate) and returned.
1.55 + """
1.56 +
1.57 + # NOTE: Requires configuration.
1.58 +
1.59 + if self.session_store is None:
1.60 + self.session_store = SessionStore(self, "WebStack-sessions")
1.61 + return self.session_store.get_session(create)
1.62 +
1.63 + def expire_session(self):
1.64 +
1.65 + """
1.66 + Expires any session established according to information provided in the
1.67 + transaction.
1.68 + """
1.69 +
1.70 + # NOTE: Requires configuration.
1.71 +
1.72 + if self.session_store is None:
1.73 + self.session_store = SessionStore(self, "WebStack-sessions")
1.74 + self.session_store.expire_session()
1.75 +
1.76 # Application-specific methods.
1.77
1.78 def set_user(self, username):