web/application.py
changeset 7876 df15d194a134
parent 7855 54283a5b7afc
child 7990 a673d1d9a738
--- a/web/application.py	Tue Sep 27 18:46:36 2011 +0200
+++ b/web/application.py	Tue Sep 27 18:47:11 2011 +0200
@@ -23,6 +23,7 @@
 
 import sys
 from time import clock, time
+from contextlib import contextmanager
 
 from logilab.common.deprecation import deprecated
 
@@ -32,7 +33,7 @@
 from cubicweb import (
     ValidationError, Unauthorized, AuthenticationError, NoSelectableObject,
     BadConnectionId, CW_EVENT_MANAGER)
-from cubicweb.dbapi import DBAPISession
+from cubicweb.dbapi import DBAPISession, anonymous_session
 from cubicweb.web import LOGGER, component
 from cubicweb.web import (
     StatusResponse, DirectResponse, Redirect, NotFound, LogOut,
@@ -42,6 +43,16 @@
 # print information about web session
 SESSION_MANAGER = None
 
+
+@contextmanager
+def anonymized_request(req):
+    orig_session = req.session
+    req.set_session(anonymous_session(req.vreg))
+    try:
+        yield req
+    finally:
+        req.set_session(orig_session)
+
 class AbstractSessionManager(component.Component):
     """manage session data associated to a session identifier"""
     __regid__ = 'sessionmanager'