[web/sessions] the session managers are definitely not components
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 13 Feb 2014 17:00:40 +0100
changeset 10565 f5063eae939e
parent 10564 6b109900583b
child 10566 4c103a2c5e93
[web/sessions] the session managers are definitely not components Component (or AppObjects) take a _cw at __init__ time. The session managers want a repository. Related to #1381328.
web/application.py
web/views/sessions.py
--- a/web/application.py	Thu Feb 13 16:43:33 2014 +0100
+++ b/web/application.py	Thu Feb 13 17:00:40 2014 +0100
@@ -68,8 +68,8 @@
     def __init__(self, appli):
         self.repo = appli.repo
         self.vreg = appli.vreg
-        self.session_manager = self.vreg['components'].select('sessionmanager',
-                                                              repo=self.repo)
+        self.session_manager = self.vreg['sessions'].select('sessionmanager',
+                                                            repo=self.repo)
         global SESSION_MANAGER
         SESSION_MANAGER = self.session_manager
         if self.vreg.config.mode != 'test':
--- a/web/views/sessions.py	Thu Feb 13 16:43:33 2014 +0100
+++ b/web/views/sessions.py	Thu Feb 13 17:00:40 2014 +0100
@@ -19,15 +19,22 @@
 __docformat__ = "restructuredtext en"
 
 from time import time
+from logging import getLogger
 
-from cubicweb import RepositoryError, Unauthorized, BadConnectionId
-from cubicweb.web import InvalidSession, component
+from logilab.common.registry import RegistrableObject
+
+from cubicweb import RepositoryError, Unauthorized, BadConnectionId, set_log_methods
+from cubicweb.predicates import yes
+from cubicweb.web import InvalidSession
 
 from cubicweb.web.views import authentication
 
-class AbstractSessionManager(component.Component):
+
+class AbstractSessionManager(RegistrableObject):
     """manage session data associated to a session identifier"""
     __abstract__ = True
+    __select__ = yes()
+    __registry__ = 'sessions'
     __regid__ = 'sessionmanager'
 
     def __init__(self, repo):
@@ -96,11 +103,14 @@
         raise NotImplementedError()
 
 
+set_log_methods(AbstractSessionManager, getLogger('cubicweb.sessionmanager'))
+
+
 class InMemoryRepositorySessionManager(AbstractSessionManager):
     """manage session data associated to a session identifier"""
 
     def __init__(self, *args, **kwargs):
-        AbstractSessionManager.__init__(self, *args, **kwargs)
+        super(InMemoryRepositorySessionManager, self).__init__(*args, **kwargs)
         # XXX require a RepositoryAuthenticationManager which violates
         #     authenticate interface by returning a session instead of a user
         #assert isinstance(self.authmanager, RepositoryAuthenticationManager)