92 """A Connection object to be used Client side. |
92 """A Connection object to be used Client side. |
93 |
93 |
94 This object is aimed to be used client side (so potential communication |
94 This object is aimed to be used client side (so potential communication |
95 with the repo through RTC) and aims to offer some compatibility with the |
95 with the repo through RTC) and aims to offer some compatibility with the |
96 cubicweb.dbapi.Connection interface. |
96 cubicweb.dbapi.Connection interface. |
|
97 |
|
98 The autoclose_session paramenter informs the connection that this session |
|
99 have been open explictly and only for this client connection. The |
|
100 connection will close the session of exit. |
97 """ |
101 """ |
98 # make exceptions available through the connection object |
102 # make exceptions available through the connection object |
99 ProgrammingError = ProgrammingError |
103 ProgrammingError = ProgrammingError |
100 # attributes that may be overriden per connection instance |
104 # attributes that may be overriden per connection instance |
101 anonymous_connection = False # XXX really needed ? |
105 anonymous_connection = False # XXX really needed ? |
102 is_repo_in_memory = True # BC, always true |
106 is_repo_in_memory = True # BC, always true |
103 |
107 |
104 def __init__(self, session): |
108 def __init__(self, session, autoclose_session=False): |
105 self._session = session |
109 self._session = session |
106 self._cnxid = None |
110 self._cnxid = None |
107 self._open = None |
111 self._open = None |
108 self._web_request = False |
112 self._web_request = False |
109 self.vreg = session.vreg |
113 self.vreg = session.vreg |
110 self._set_user(session.user) |
114 self._set_user(session.user) |
|
115 self._autoclose_session = autoclose_session |
111 |
116 |
112 def __enter__(self): |
117 def __enter__(self): |
113 assert self._open is None |
118 assert self._open is None |
114 self._open = True |
119 self._open = True |
115 self._cnxid = '%s-%s' % (self._session.id, uuid4().hex) |
120 self._cnxid = '%s-%s' % (self._session.id, uuid4().hex) |