1.1 --- a/WebStack/Webware.py Mon Aug 16 18:13:45 2004 +0000
1.2 +++ b/WebStack/Webware.py Thu Aug 26 20:37:21 2004 +0000
1.3 @@ -342,6 +342,37 @@
1.4
1.5 self.trans.response().delCookie(cookie_name)
1.6
1.7 + # Session-related methods.
1.8 +
1.9 + def get_session(self, create=1):
1.10 +
1.11 + """
1.12 + A framework-specific method which returns a session corresponding to
1.13 + an identifier supplied in the transaction.
1.14 +
1.15 + If no session has yet been established according to information
1.16 + provided in the transaction then the optional 'create' parameter
1.17 + determines whether a new session will be established.
1.18 +
1.19 + Where no session has been established and where 'create' is set to 0
1.20 + then None is returned. In all other cases, a session object is created
1.21 + (where appropriate) and returned.
1.22 + """
1.23 +
1.24 + # NOTE: Should really use Webware's hasSession method.
1.25 +
1.26 + session = self.trans.session()
1.27 + return Session(session)
1.28 +
1.29 + def expire_session(self):
1.30 +
1.31 + """
1.32 + A framework-specific method which expires any session established
1.33 + according to information provided in the transaction.
1.34 + """
1.35 +
1.36 + self.trans.request().setSessionExpired(1)
1.37 +
1.38 # Application-specific methods.
1.39
1.40 def set_user(self, username):
1.41 @@ -354,4 +385,17 @@
1.42
1.43 self.user = username
1.44
1.45 +class Session:
1.46 +
1.47 + "A more dictionary-like session object than the one Webware provides."
1.48 +
1.49 + def __init__(self, session):
1.50 + self.session = session
1.51 +
1.52 + def items(self):
1.53 + return self.session.values().items()
1.54 +
1.55 + def __getattr__(self, name):
1.56 + return getattr(self.__dict__["session"], name)
1.57 +
1.58 # vim: tabstop=4 expandtab shiftwidth=4