# HG changeset patch # User Goffi # Date 1490809587 -7200 # Node ID 8cea8bf41b03e67f80be7ef8cfc9dc2369f9c4ee # Parent 7b267496da1da34841155c206f6c2ef354d5533d server: new purgeSession and getSessionData helper methods diff -r 7b267496da1d -r 8cea8bf41b03 src/server/server.py --- a/src/server/server.py Wed Mar 29 19:46:04 2017 +0200 +++ b/src/server/server.py Wed Mar 29 19:46:27 2017 +0200 @@ -1777,6 +1777,28 @@ # FIXME: check that no information is leaked (c.f. https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#request-encoders) self.root.putChild(path, web_resource.EncodingResourceWrapper(resource, [server.GzipEncoderFactory()])) + ## Sessions ## + + def purgeSession(self, request): + """helper method to purge a session during request handling""" + session = request.session + if session is not None: + log.debug(_(u"session purge")) + session.expire() + # FIXME: not clean but it seems that it's the best way to reset + # session during request handling + request._secureSession = request._insecureSession = None + + def getSessionData(self, request, *args): + """helper method to retrieve session data + + @param request(server.Request): request linked to the session + @param *args(zope.interface.Interface): interface of the session to get + @return (iterator(data)): requested session data + """ + session = request.getSession() + return (iface(session) for iface in args) + ## TLS related methods ## def _TLSOptionsCheck(self):