# HG changeset patch # User Pierre-Yves David # Date 1363977753 -3600 # Node ID 51962942239140e6eaaab97ac7a7ddad0b8615ad # Parent 2005dcc6150e71b5830d70f1e8ab0f8ba43eac36 [session] rename _tx_data into _txs The object inside are now Transaction object. Not TransactionData object. diff -r 2005dcc6150e -r 519629422391 server/repository.py --- a/server/repository.py Fri Mar 22 19:32:25 2013 +0100 +++ b/server/repository.py Fri Mar 22 19:42:33 2013 +0100 @@ -844,7 +844,7 @@ self.debug('begin commit for session %s', sessionid) try: session = self._get_session(sessionid) - session.set_tx_data(txid) + session.set_tx(txid) return session.commit() except (ValidationError, Unauthorized): raise @@ -857,7 +857,7 @@ self.debug('begin rollback for session %s', sessionid) try: session = self._get_session(sessionid) - session.set_tx_data(txid) + session.set_tx(txid) session.rollback() except Exception: self.exception('unexpected error') @@ -1005,7 +1005,7 @@ except KeyError: raise BadConnectionId('No such session %s' % sessionid) if setcnxset: - session.set_tx_data(txid) # must be done before set_cnxset + session.set_tx(txid) # must be done before set_cnxset session.set_cnxset() return session diff -r 2005dcc6150e -r 519629422391 server/session.py --- a/server/session.py Fri Mar 22 19:32:25 2013 +0100 +++ b/server/session.py Fri Mar 22 19:42:33 2013 +0100 @@ -258,7 +258,7 @@ :attr:`data` is a dictionary containing shared data, used to communicate extra information between the client and the repository - :attr:`_tx_data` is a dictionary of :class:`TransactionData` instance, one + :attr:`_txs` is a dictionary of :class:`TransactionData` instance, one for each running transaction. The key is the transaction id. By default the transaction id is the thread name but it can be otherwise (per dbapi cursor for instance, or per thread name *from another process*). @@ -381,8 +381,9 @@ self.data = {} # i18n initialization self.set_language(user.prefered_language()) - # internals - self._tx_data = {} + ### internals + # Transaction of this section + self._txs = {} # Data local to the thread self.__threaddata = threading.local() self._threads_in_transaction = set() @@ -393,22 +394,22 @@ return '' % ( unicode(self.user.login), self.id, id(self)) - def set_tx_data(self, txid=None): + def set_tx(self, txid=None): if txid is None: txid = threading.currentThread().getName() try: - self.__threaddata.txdata = self._tx_data[txid] + self.__threaddata.txdata = self._txs[txid] except KeyError: rewriter = RQLRewriter(self) tx = Transaction(txid, self.default_mode, rewriter) - self.__threaddata.txdata = self._tx_data[txid] = tx + self.__threaddata.txdata = self._txs[txid] = tx @property def _threaddata(self): try: return self.__threaddata.txdata except AttributeError: - self.set_tx_data() + self.set_tx() return self.__threaddata.txdata def get_option_value(self, option, foreid=None): @@ -1018,7 +1019,7 @@ self._clear_tx_storage(txstore) def _clear_thread_storage(self, txstore): - self._tx_data.pop(txstore.transactionid, None) + self._txs.pop(txstore.transactionid, None) try: del self.__threaddata.txdata except AttributeError: @@ -1170,11 +1171,11 @@ self._free_thread_cnxset(thread, cnxset, force_close=True) self.rollback() del self.__threaddata - del self._tx_data + del self._txs @property def closed(self): - return not hasattr(self, '_tx_data') + return not hasattr(self, '_txs') # transaction data/operations management ################################## diff -r 2005dcc6150e -r 519629422391 server/test/unittest_session.py --- a/server/test/unittest_session.py Fri Mar 22 19:32:25 2013 +0100 +++ b/server/test/unittest_session.py Fri Mar 22 19:42:33 2013 +0100 @@ -32,7 +32,7 @@ self.assertEqual(session.hooks_mode, session.HOOKS_ALLOW_ALL) self.assertEqual(session.disabled_hook_categories, set()) self.assertEqual(session.enabled_hook_categories, set()) - self.assertEqual(len(session._tx_data), 1) + self.assertEqual(len(session._txs), 1) with session.deny_all_hooks_but('metadata'): self.assertEqual(session.hooks_mode, session.HOOKS_DENY_ALL) self.assertEqual(session.disabled_hook_categories, set()) @@ -54,7 +54,7 @@ self.assertEqual(session.enabled_hook_categories, set(('metadata',))) # leaving context manager with no transaction running should reset the # transaction local storage (and associated cnxset) - self.assertEqual(session._tx_data, {}) + self.assertEqual(session._txs, {}) self.assertEqual(session.cnxset, None) self.assertEqual(session.hooks_mode, session.HOOKS_ALLOW_ALL) self.assertEqual(session.disabled_hook_categories, set())