Re: session, quick one

...I should have said that in the first place: I am trying to set the lifetime of my session but I am not using nevow. Here is the code I use to retrieve the session. It works fine but the session times out every 20min or so: if not request.session: cookiename = string.join(['TWISTED_SESSION'] \ + request.sitepath, "_") sessionCookie = request.getCookie(cookiename) if sessionCookie: print 'SESSION RETRIVING' try: request.session = \ request.site.getSession(sessionCookie) except KeyError: pass # if it still hasn't been set, fix it up. if not request.session: print 'SESSION NEW' request.session = request.site.makeSession() request.addCookie(cookiename, request.session.uid, path='/') request.session.state = m_web.State(self.glo) This code seems to be too complicated (too low level) anyways. I was hoping for something simple like: request.getCurrentOrNewsSession(lifetime=7200) #noema

On Apr 23, 2004, at 3:31 PM, noema wrote:
...I should have said that in the first place: I am trying to set the lifetime of my session but I am not using nevow. Here is the code I use to retrieve the session. It works fine but the session times out every 20min or so:
First of all, for old twisted.web code, just use request.getSession(). This does what you appear to have recreated yourself in the code you pasted, and what you seem to be asking for in the method name request.getCurrentOrNewSession (That's what request.getSession already does). Unfortunately, it doesn't have your proposed lifetime=7200 argument, and the lifetime is totally hardcoded into the session. I recommend reading twisted.web.server.Request.getSession and twisted.web.server.Session; it's not that much code. If you notice, Session.checkExpired checks whether to expire the session every 15 minutes. You might want to create your own code which touches the session every 10 minutes or so (by calling touch()) and expires it when you like (by calling expire()). We'll keep this in mind for the upcoming twisted.web cleanup and refactoring. dp

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Unfortunately, it doesn't have your proposed lifetime=7200 argument, and the lifetime is totally hardcoded into the session. I recommend reading twisted.web.server.Request.getSession and twisted.web.server.Session; it's not that much code. If you notice, Session.checkExpired checks whether to expire the session every 15 minutes. You might want to create your own code which touches the session every 10 minutes or so (by calling touch()) and expires it when you like (by calling expire()).
We'll keep this in mind for the upcoming twisted.web cleanup and refactoring.
Yeah, parameterized session timeouts would be really helpful. - -- Nicola Larosa - nico@tekNico.net "I know, no one's gonna show me everything We all come and go unknown Each so deep and superficial Between the forceps and the stone" -- Joni Mitchell, Hejira, 1976 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFAiglRXv0hgDImBm4RApFeAJ9UFWMAWSS98K+A0NsaJDFOBrFr6ACfe6SN mIVvNCG9ODIOEjAXIoj2L0g= =Ov1u -----END PGP SIGNATURE-----
participants (3)
-
Donovan Preston
-
Nicola Larosa
-
noema