dbapi.py
changeset 9042 6cc13a0a9145
parent 9040 3c85e734ce00
child 9045 5378a738f333
--- a/dbapi.py	Mon Jun 24 11:31:47 2013 +0200
+++ b/dbapi.py	Mon Jun 24 14:53:19 2013 +0200
@@ -34,7 +34,7 @@
 from urlparse import  urlparse
 
 from logilab.common.logging_ext import set_log_methods
-from logilab.common.decorators import monkeypatch
+from logilab.common.decorators import monkeypatch, cachedproperty
 from logilab.common.deprecation import deprecated
 
 from cubicweb import ETYPE_NAME_MAP, ConnectionError, AuthenticationError,\
@@ -541,7 +541,6 @@
     # make exceptions available through the connection object
     ProgrammingError = ProgrammingError
     # attributes that may be overriden per connection instance
-    anonymous_connection = False
     cursor_class = Cursor
     vreg = None
     _closed = None
@@ -567,6 +566,13 @@
             return False
         return isinstance(self._repo, Repository)
 
+    @property # could be a cached property but we want to prevent assigment to
+              # catch potential programming error.
+    def anonymous_connection(self):
+        login = self._repo.user_info(self.sessionid)[1]
+        anon_login = self.vreg.config.get('anonymous-user')
+        return login == anon_login
+
     def __repr__(self):
         if self.anonymous_connection:
             return '<Connection %s (anonymous)>' % self.sessionid