21 |
21 |
22 __docformat__ = "restructuredtext en" |
22 __docformat__ = "restructuredtext en" |
23 |
23 |
24 import sys |
24 import sys |
25 from time import clock, time |
25 from time import clock, time |
|
26 from contextlib import contextmanager |
26 |
27 |
27 from logilab.common.deprecation import deprecated |
28 from logilab.common.deprecation import deprecated |
28 |
29 |
29 from rql import BadRQLQuery |
30 from rql import BadRQLQuery |
30 |
31 |
31 from cubicweb import set_log_methods, cwvreg |
32 from cubicweb import set_log_methods, cwvreg |
32 from cubicweb import ( |
33 from cubicweb import ( |
33 ValidationError, Unauthorized, AuthenticationError, NoSelectableObject, |
34 ValidationError, Unauthorized, AuthenticationError, NoSelectableObject, |
34 BadConnectionId, CW_EVENT_MANAGER) |
35 BadConnectionId, CW_EVENT_MANAGER) |
35 from cubicweb.dbapi import DBAPISession |
36 from cubicweb.dbapi import DBAPISession, anonymous_session |
36 from cubicweb.web import LOGGER, component |
37 from cubicweb.web import LOGGER, component |
37 from cubicweb.web import ( |
38 from cubicweb.web import ( |
38 StatusResponse, DirectResponse, Redirect, NotFound, LogOut, |
39 StatusResponse, DirectResponse, Redirect, NotFound, LogOut, |
39 RemoteCallFailed, InvalidSession, RequestError) |
40 RemoteCallFailed, InvalidSession, RequestError) |
40 |
41 |
41 # make session manager available through a global variable so the debug view can |
42 # make session manager available through a global variable so the debug view can |
42 # print information about web session |
43 # print information about web session |
43 SESSION_MANAGER = None |
44 SESSION_MANAGER = None |
|
45 |
|
46 |
|
47 @contextmanager |
|
48 def anonymized_request(req): |
|
49 orig_session = req.session |
|
50 req.set_session(anonymous_session(req.vreg)) |
|
51 try: |
|
52 yield req |
|
53 finally: |
|
54 req.set_session(orig_session) |
44 |
55 |
45 class AbstractSessionManager(component.Component): |
56 class AbstractSessionManager(component.Component): |
46 """manage session data associated to a session identifier""" |
57 """manage session data associated to a session identifier""" |
47 __regid__ = 'sessionmanager' |
58 __regid__ = 'sessionmanager' |
48 |
59 |