391 |
391 |
392 def __unicode__(self): |
392 def __unicode__(self): |
393 return '<session %s (%s 0x%x)>' % ( |
393 return '<session %s (%s 0x%x)>' % ( |
394 unicode(self.user.login), self.id, id(self)) |
394 unicode(self.user.login), self.id, id(self)) |
395 |
395 |
396 def transaction(self, free_cnxset=True): |
|
397 """return context manager to enter a transaction for the session: when |
|
398 exiting the `with` block on exception, call `session.rollback()`, else |
|
399 call `session.commit()` on normal exit. |
|
400 |
|
401 The `free_cnxset` will be given to rollback/commit methods to indicate |
|
402 wether the connections set should be freed or not. |
|
403 """ |
|
404 return transaction(self, free_cnxset) |
|
405 |
|
406 def set_tx_data(self, txid=None): |
396 def set_tx_data(self, txid=None): |
407 if txid is None: |
397 if txid is None: |
408 txid = threading.currentThread().getName() |
398 txid = threading.currentThread().getName() |
409 try: |
399 try: |
410 self.__threaddata.txdata = self._tx_data[txid] |
400 self.__threaddata.txdata = self._tx_data[txid] |
421 self.set_tx_data() |
411 self.set_tx_data() |
422 return self.__threaddata.txdata |
412 return self.__threaddata.txdata |
423 |
413 |
424 def get_option_value(self, option, foreid=None): |
414 def get_option_value(self, option, foreid=None): |
425 return self.repo.get_option_value(option, foreid) |
415 return self.repo.get_option_value(option, foreid) |
|
416 |
|
417 def transaction(self, free_cnxset=True): |
|
418 """return context manager to enter a transaction for the session: when |
|
419 exiting the `with` block on exception, call `session.rollback()`, else |
|
420 call `session.commit()` on normal exit. |
|
421 |
|
422 The `free_cnxset` will be given to rollback/commit methods to indicate |
|
423 wether the connections set should be freed or not. |
|
424 """ |
|
425 return transaction(self, free_cnxset) |
|
426 |
426 |
427 |
427 def hijack_user(self, user): |
428 def hijack_user(self, user): |
428 """return a fake request/session using specified user""" |
429 """return a fake request/session using specified user""" |
429 session = Session(user, self.repo) |
430 session = Session(user, self.repo) |
430 threaddata = session._threaddata |
431 threaddata = session._threaddata |