1.1 --- a/WebStack/Twisted.py Sun Sep 05 11:12:32 2004 +0000
1.2 +++ b/WebStack/Twisted.py Sun Sep 05 15:51:44 2004 +0000
1.3 @@ -8,6 +8,7 @@
1.4 from Helpers.Auth import UserInfo
1.5 from Helpers.Request import Cookie, get_body_field
1.6 from Helpers.Response import ConvertingStream
1.7 +from Helpers.Session import SessionStore
1.8 from cgi import parse_qs
1.9
1.10 class Transaction(Generic.Transaction):
1.11 @@ -24,6 +25,22 @@
1.12 self.user = None
1.13 self.content_type = 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 + A special method, synchronising the transaction with framework-specific
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 # Request-related methods.
1.32
1.33 def get_request_stream(self):
1.34 @@ -341,6 +358,42 @@
1.35
1.36 self.trans.addCookie(cookie_name, "", expires=0, path="/", max_age=0)
1.37
1.38 + # Session-related methods.
1.39 +
1.40 + def get_session(self, create=1):
1.41 +
1.42 + """
1.43 + Gets a session corresponding to an identifier supplied in the
1.44 + transaction.
1.45 +
1.46 + If no session has yet been established according to information
1.47 + provided in the transaction then the optional 'create' parameter
1.48 + determines whether a new session will be established.
1.49 +
1.50 + Where no session has been established and where 'create' is set to 0
1.51 + then None is returned. In all other cases, a session object is created
1.52 + (where appropriate) and returned.
1.53 + """
1.54 +
1.55 + # NOTE: Requires configuration.
1.56 +
1.57 + if self.session_store is None:
1.58 + self.session_store = SessionStore(self, "WebStack-sessions")
1.59 + return self.session_store.get_session(create)
1.60 +
1.61 + def expire_session(self):
1.62 +
1.63 + """
1.64 + Expires any session established according to information provided in the
1.65 + transaction.
1.66 + """
1.67 +
1.68 + # NOTE: Requires configuration.
1.69 +
1.70 + if self.session_store is None:
1.71 + self.session_store = SessionStore(self, "WebStack-sessions")
1.72 + self.session_store.expire_session()
1.73 +
1.74 # Application-specific methods.
1.75
1.76 def set_user(self, username):