equal
deleted
inserted
replaced
11 __docformat__ = "restructuredtext en" |
11 __docformat__ = "restructuredtext en" |
12 |
12 |
13 from logging import getLogger |
13 from logging import getLogger |
14 from time import time, clock |
14 from time import time, clock |
15 |
15 |
16 from cubicweb import ConnectionError, RequestSessionMixIn, set_log_methods |
16 from logilab.common.logging_ext import set_log_methods |
|
17 from cubicweb import ETYPE_NAME_MAP, ConnectionError, RequestSessionMixIn |
17 from cubicweb.cwvreg import CubicWebRegistry, MulCnxCubicWebRegistry |
18 from cubicweb.cwvreg import CubicWebRegistry, MulCnxCubicWebRegistry |
18 from cubicweb.cwconfig import CubicWebNoAppConfiguration |
19 from cubicweb.cwconfig import CubicWebNoAppConfiguration |
19 |
20 |
20 _MARKER = object() |
21 _MARKER = object() |
21 |
22 |
99 elif setvreg: |
100 elif setvreg: |
100 if mulcnx: |
101 if mulcnx: |
101 vreg = MulCnxCubicWebRegistry(config, initlog=initlog) |
102 vreg = MulCnxCubicWebRegistry(config, initlog=initlog) |
102 else: |
103 else: |
103 vreg = CubicWebRegistry(config, initlog=initlog) |
104 vreg = CubicWebRegistry(config, initlog=initlog) |
104 vreg.set_schema(repo.get_schema()) |
105 schema = repo.get_schema() |
|
106 for oldetype, newetype in ETYPE_NAME_MAP.items(): |
|
107 if oldetype in schema: |
|
108 print 'aliasing', newetype, 'to', oldetype |
|
109 schema._entities[newetype] = schema._entities[oldetype] |
|
110 vreg.set_schema(schema) |
105 else: |
111 else: |
106 vreg = None |
112 vreg = None |
107 cnx = repo_connect(repo, user, password, cnxprops) |
113 cnx = repo_connect(repo, user, password, cnxprops) |
108 cnx.vreg = vreg |
114 cnx.vreg = vreg |
109 return cnx |
115 return cnx |
323 self.cursor_class = Cursor |
329 self.cursor_class = Cursor |
324 self.anonymous_connection = False |
330 self.anonymous_connection = False |
325 self.vreg = None |
331 self.vreg = None |
326 # session's data |
332 # session's data |
327 self.data = {} |
333 self.data = {} |
328 # XXX < 3.2 bw compat |
|
329 if 'EUser' in self._repo.get_schema(): |
|
330 self._user_etype = 'EUser' |
|
331 else: |
|
332 self._user_etype = 'CWUser' |
|
333 |
334 |
334 def __repr__(self): |
335 def __repr__(self): |
335 if self.anonymous_connection: |
336 if self.anonymous_connection: |
336 return '<Connection %s (anonymous)>' % self.sessionid |
337 return '<Connection %s (anonymous)>' % self.sessionid |
337 return '<Connection %s>' % self.sessionid |
338 return '<Connection %s>' % self.sessionid |
433 """return the User object associated to this connection""" |
434 """return the User object associated to this connection""" |
434 # cnx validity is checked by the call to .user_info |
435 # cnx validity is checked by the call to .user_info |
435 eid, login, groups, properties = self._repo.user_info(self.sessionid, props) |
436 eid, login, groups, properties = self._repo.user_info(self.sessionid, props) |
436 if req is None: |
437 if req is None: |
437 req = self.request() |
438 req = self.request() |
438 rset = req.eid_rset(eid, self._user_etype) |
439 rset = req.eid_rset(eid, 'CWUser') |
439 user = self.vreg.etype_class(self._user_etype)(req, rset, row=0, groups=groups, |
440 user = self.vreg.etype_class('CWUser')(req, rset, row=0, groups=groups, |
440 properties=properties) |
441 properties=properties) |
441 user['login'] = login # cache login |
442 user['login'] = login # cache login |
442 return user |
443 return user |
443 |
444 |
444 def __del__(self): |
445 def __del__(self): |
445 """close the remote connection if necessary""" |
446 """close the remote connection if necessary""" |