[Neo-report] r2477 vincent - in /trunk/neo: master/ tests/master/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Dec 7 22:25:19 CET 2010
Author: vincent
Date: Tue Dec 7 22:25:19 2010
New Revision: 2477
Log:
Use ZERO_TID instead of None.
There is no strong reason to use None, and it makes code more complex.
Modified:
trunk/neo/master/transactions.py
trunk/neo/tests/master/testTransactions.py
Modified: trunk/neo/master/transactions.py
==============================================================================
--- trunk/neo/master/transactions.py [iso-8859-1] (original)
+++ trunk/neo/master/transactions.py [iso-8859-1] Tue Dec 7 22:25:19 2010
@@ -17,6 +17,7 @@
from time import time, gmtime
from struct import pack, unpack
+from neo.protocol import ZERO_TID
from datetime import timedelta, datetime
from neo.util import dump
import neo
@@ -175,13 +176,13 @@ class TransactionManager(object):
"""
Manage current transactions
"""
+ _last_tid = ZERO_TID
def __init__(self):
# tid -> transaction
self._tid_dict = {}
# node -> transactions mapping
self._node_dict = {}
- self._last_tid = None
self._last_oid = None
def __getitem__(self, tid):
@@ -234,7 +235,7 @@ class TransactionManager(object):
gmt.tm_min),
int((gmt.tm_sec % 60 + (tm - int(tm))) / SECOND_PER_TID_LOW)
))
- if self._last_tid is not None and tid <= self._last_tid:
+ if tid <= self._last_tid:
tid = addTID(self._last_tid, 1)
self._last_tid = tid
return self._last_tid
@@ -249,10 +250,7 @@ class TransactionManager(object):
"""
Set the last TID, keep the previous if lower
"""
- if self._last_tid is None:
- self._last_tid = tid
- else:
- self._last_tid = max(self._last_tid, tid)
+ self._last_tid = max(self._last_tid, tid)
def reset(self):
"""
Modified: trunk/neo/tests/master/testTransactions.py
==============================================================================
--- trunk/neo/tests/master/testTransactions.py [iso-8859-1] (original)
+++ trunk/neo/tests/master/testTransactions.py [iso-8859-1] Tue Dec 7 22:25:19 2010
@@ -19,6 +19,7 @@ import unittest
from mock import Mock
from struct import pack, unpack
from neo.tests import NeoUnitTestBase
+from neo.protocol import ZERO_TID
from neo.master.transactions import Transaction, TransactionManager
from neo.master.transactions import packTID, unpackTID, addTID
@@ -126,7 +127,7 @@ class testTransactionManager(NeoUnitTest
def test_getNextTID(self):
txnman = TransactionManager()
# no previous TID
- self.assertEqual(txnman.getLastTID(), None)
+ self.assertEqual(txnman.getLastTID(), ZERO_TID)
# first transaction
node1 = Mock({'__hash__': 1})
tid1 = txnman.begin()
More information about the Neo-report
mailing list