equal
deleted
inserted
replaced
32 from os.path import join |
32 from os.path import join |
33 from uuid import uuid4 |
33 from uuid import uuid4 |
34 from urlparse import urlparse |
34 from urlparse import urlparse |
35 |
35 |
36 from logilab.common.logging_ext import set_log_methods |
36 from logilab.common.logging_ext import set_log_methods |
37 from logilab.common.decorators import monkeypatch |
37 from logilab.common.decorators import monkeypatch, cachedproperty |
38 from logilab.common.deprecation import deprecated |
38 from logilab.common.deprecation import deprecated |
39 |
39 |
40 from cubicweb import ETYPE_NAME_MAP, ConnectionError, AuthenticationError,\ |
40 from cubicweb import ETYPE_NAME_MAP, ConnectionError, AuthenticationError,\ |
41 cwvreg, cwconfig |
41 cwvreg, cwconfig |
42 from cubicweb.req import RequestSessionBase |
42 from cubicweb.req import RequestSessionBase |
539 """DB-API 2.0 compatible Connection object for CubicWeb |
539 """DB-API 2.0 compatible Connection object for CubicWeb |
540 """ |
540 """ |
541 # make exceptions available through the connection object |
541 # make exceptions available through the connection object |
542 ProgrammingError = ProgrammingError |
542 ProgrammingError = ProgrammingError |
543 # attributes that may be overriden per connection instance |
543 # attributes that may be overriden per connection instance |
544 anonymous_connection = False |
|
545 cursor_class = Cursor |
544 cursor_class = Cursor |
546 vreg = None |
545 vreg = None |
547 _closed = None |
546 _closed = None |
548 |
547 |
549 def __init__(self, repo, cnxid, cnxprops=None): |
548 def __init__(self, repo, cnxid, cnxprops=None): |
564 from cubicweb.server.repository import Repository |
563 from cubicweb.server.repository import Repository |
565 except ImportError: |
564 except ImportError: |
566 # code not available, no way |
565 # code not available, no way |
567 return False |
566 return False |
568 return isinstance(self._repo, Repository) |
567 return isinstance(self._repo, Repository) |
|
568 |
|
569 @property # could be a cached property but we want to prevent assigment to |
|
570 # catch potential programming error. |
|
571 def anonymous_connection(self): |
|
572 login = self._repo.user_info(self.sessionid)[1] |
|
573 anon_login = self.vreg.config.get('anonymous-user') |
|
574 return login == anon_login |
569 |
575 |
570 def __repr__(self): |
576 def __repr__(self): |
571 if self.anonymous_connection: |
577 if self.anonymous_connection: |
572 return '<Connection %s (anonymous)>' % self.sessionid |
578 return '<Connection %s (anonymous)>' % self.sessionid |
573 return '<Connection %s>' % self.sessionid |
579 return '<Connection %s>' % self.sessionid |