server/session.py
changeset 8777 4e72b78ea5aa
parent 8776 cdb261bd36ac
child 8778 9d6a34b9838d
equal deleted inserted replaced
8776:cdb261bd36ac 8777:4e72b78ea5aa
   392 
   392 
   393     def __unicode__(self):
   393     def __unicode__(self):
   394         return '<session %s (%s 0x%x)>' % (
   394         return '<session %s (%s 0x%x)>' % (
   395             unicode(self.user.login), self.id, id(self))
   395             unicode(self.user.login), self.id, id(self))
   396 
   396 
       
   397     def get_tx(self, txid):
       
   398         """return the <txid> transaction attached to this session
       
   399 
       
   400         Transaction is created if necessary"""
       
   401         with self._lock: # no transaction exist with the same id
       
   402             try:
       
   403                 tx = self._txs[txid]
       
   404             except KeyError:
       
   405                 rewriter = RQLRewriter(self)
       
   406                 tx = Transaction(txid, self.default_mode, rewriter)
       
   407                 self._txs[txid] = tx
       
   408         return tx
       
   409 
   397     def set_tx(self, txid=None):
   410     def set_tx(self, txid=None):
   398         """set the default transaction of the current thread to <txid>
   411         """set the default transaction of the current thread to <txid>
   399 
   412 
   400         Transaction is created if necessary"""
   413         Transaction is created if necessary"""
   401         if txid is None:
   414         if txid is None:
   402             txid = threading.currentThread().getName()
   415             txid = threading.currentThread().getName()
   403         try:
   416         self.__threaddata.tx = self.get_tx(txid)
   404             self.__threaddata.tx = self._txs[txid]
       
   405         except KeyError:
       
   406             rewriter = RQLRewriter(self)
       
   407             tx = Transaction(txid, self.default_mode, rewriter)
       
   408             self.__threaddata.tx = self._txs[txid] = tx
       
   409 
   417 
   410     @property
   418     @property
   411     def _tx(self):
   419     def _tx(self):
   412         try:
   420         try:
   413             return self.__threaddata.tx
   421             return self.__threaddata.tx