[schema categorization] new NO_I18NCONTEXT set usable to somewhat control c-c i18n
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""web session component: by dfault the session is actually the db connectionobject :/"""__docformat__="restructuredtext en"fromcubicweb.webimportInvalidSessionfromcubicweb.web.applicationimportAbstractSessionManagerfromcubicweb.dbapiimportDBAPISessionclassInMemoryRepositorySessionManager(AbstractSessionManager):"""manage session data associated to a session identifier"""def__init__(self,*args,**kwargs):AbstractSessionManager.__init__(self,*args,**kwargs)# XXX require a RepositoryAuthenticationManager which violates# authenticate interface by returning a session instead of a user#assert isinstance(self.authmanager, RepositoryAuthenticationManager)self._sessions={}# dump_data / restore_data to avoid loosing open sessions on registry# reloadingdefdump_data(self):returnself._sessionsdefrestore_data(self,data):self._sessions=datadefcurrent_sessions(self):returnself._sessions.values()defget_session(self,req,sessionid):"""return existing session for the given session identifier"""ifnotsessionidinself._sessions:raiseInvalidSession()session=self._sessions[sessionid]try:user=self.authmanager.validate_session(req,session)exceptInvalidSession:# invalid sessionself.close_session(session)raise# associate the connection to the current requestreq.set_session(session,user)returnsessiondefopen_session(self,req):"""open and return a new session for the given request. The session is also bound to the request. raise :exc:`cubicweb.AuthenticationError` if authentication failed (no authentication info found or wrong user/password) """cnx,login,authinfo=self.authmanager.authenticate(req)session=DBAPISession(cnx,login,authinfo)self._sessions[session.sessionid]=session# associate the connection to the current requestreq.set_session(session)returnsessiondefclose_session(self,session):"""close session on logout or on invalid session detected (expired out, corrupted...) """self.info('closing http session %s'%session.sessionid)delself._sessions[session.sessionid]try:session.cnx.close()except:# already closed, may occurs if the repository session expired but# not the web sessionpasssession.cnx=None