[Twisted-web] Re: Newbie help on session data
Craig H. Anderson
craig at coot.net
Thu Jun 10 21:40:11 MDT 2004
Some more attempts and reading of code and
here are code fragments with working session data.
Where is a good place to call components.registerAdapter()
for a server?
#---------------------------------------
from twisted.python import components
from twisted.web.resource import Resource
from twisted.web import server
class IGcsSession(components.Interface):
def getData(self):
"""Return the session data
"""
class GcsSession(components.Adapter):
__implements__ = (IGcsSession, )
def __init__(self,original):
components.Adapter.__init__(self,original)
self.counter = 0
self.dict = {}
def getData(self):
return self
components.registerAdapter(GcsSession, server.Session, IGcsSession)
class CalForm(Resource):
template render(self,request):
sessData = request.getSession(IGcsSession)
sessData.counter += 1
'counter %d<br>' % sessData.counter
resource = CalForm()
More information about the Twisted-web
mailing list