equal
deleted
inserted
replaced
31 from logilab.common.textutils import unormalize |
31 from logilab.common.textutils import unormalize |
32 from logilab.common.registry import objectify_predicate |
32 from logilab.common.registry import objectify_predicate |
33 |
33 |
34 from cubicweb import UnknownEid, QueryError, schema, server |
34 from cubicweb import UnknownEid, QueryError, schema, server |
35 from cubicweb.req import RequestSessionBase |
35 from cubicweb.req import RequestSessionBase |
36 from cubicweb.dbapi import ConnectionProperties |
|
37 from cubicweb.utils import make_uid |
36 from cubicweb.utils import make_uid |
38 from cubicweb.rqlrewrite import RQLRewriter |
37 from cubicweb.rqlrewrite import RQLRewriter |
39 from cubicweb.server import ShuttingDown |
38 from cubicweb.server import ShuttingDown |
40 from cubicweb.server.edition import EditedEntity |
39 from cubicweb.server.edition import EditedEntity |
41 |
40 |
230 is_internal_session = False |
229 is_internal_session = False |
231 |
230 |
232 def __init__(self, user, repo, cnxprops=None, _id=None): |
231 def __init__(self, user, repo, cnxprops=None, _id=None): |
233 super(Session, self).__init__(repo.vreg) |
232 super(Session, self).__init__(repo.vreg) |
234 self.id = _id or make_uid(unormalize(user.login).encode('UTF8')) |
233 self.id = _id or make_uid(unormalize(user.login).encode('UTF8')) |
235 cnxprops = cnxprops or ConnectionProperties('inmemory') |
|
236 self.user = user |
234 self.user = user |
237 self.repo = repo |
235 self.repo = repo |
238 self.cnxtype = cnxprops.cnxtype |
|
239 self.timestamp = time() |
236 self.timestamp = time() |
240 self.default_mode = 'read' |
237 self.default_mode = 'read' |
241 # undo support |
238 # undo support |
242 if repo.config.creating or repo.config.repairing or self.is_internal_session: |
239 if repo.config.creating or repo.config.repairing or self.is_internal_session: |
243 self.undo_actions = False |
240 self.undo_actions = False |
256 self._threads_in_transaction = set() |
253 self._threads_in_transaction = set() |
257 self._closed = False |
254 self._closed = False |
258 self._closed_lock = threading.Lock() |
255 self._closed_lock = threading.Lock() |
259 |
256 |
260 def __unicode__(self): |
257 def __unicode__(self): |
261 return '<%ssession %s (%s 0x%x)>' % ( |
258 return '<session %s (%s 0x%x)>' % ( |
262 self.cnxtype, unicode(self.user.login), self.id, id(self)) |
259 unicode(self.user.login), self.id, id(self)) |
263 |
260 |
264 def transaction(self, free_cnxset=True): |
261 def transaction(self, free_cnxset=True): |
265 """return context manager to enter a transaction for the session: when |
262 """return context manager to enter a transaction for the session: when |
266 exiting the `with` block on exception, call `session.rollback()`, else |
263 exiting the `with` block on exception, call `session.rollback()`, else |
267 call `session.commit()` on normal exit. |
264 call `session.commit()` on normal exit. |
1183 |
1180 |
1184 def __init__(self, repo, cnxprops=None, safe=False): |
1181 def __init__(self, repo, cnxprops=None, safe=False): |
1185 super(InternalSession, self).__init__(InternalManager(), repo, cnxprops, |
1182 super(InternalSession, self).__init__(InternalManager(), repo, cnxprops, |
1186 _id='internal') |
1183 _id='internal') |
1187 self.user._cw = self # XXX remove when "vreg = user._cw.vreg" hack in entity.py is gone |
1184 self.user._cw = self # XXX remove when "vreg = user._cw.vreg" hack in entity.py is gone |
1188 self.cnxtype = 'inmemory' |
|
1189 if not safe: |
1185 if not safe: |
1190 self.disable_hook_categories('integrity') |
1186 self.disable_hook_categories('integrity') |
1191 |
1187 |
1192 def __enter__(self): |
1188 def __enter__(self): |
1193 return self |
1189 return self |