Commit cd8a8e07 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Implement __getitem__() on transaction iterator.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1903 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent ec1fec08
...@@ -79,12 +79,21 @@ class Iterator(object): ...@@ -79,12 +79,21 @@ class Iterator(object):
raise NotImplementedError('partial scan not implemented yet') raise NotImplementedError('partial scan not implemented yet')
self.app = app self.app = app
self.txn_list = [] self.txn_list = []
self.index = 0 # next index to load from storage nodes
self._next = 0
# index of current iteration
self._index = 0
self._closed = False self._closed = False
def __iter__(self): def __iter__(self):
return self return self
def __getitem__(self, index):
""" Simple index-based iterator """
if index != self._index:
raise IndexError, index
return self.next()
def next(self): def next(self):
""" Return an iterator for the next transaction""" """ Return an iterator for the next transaction"""
if self._closed: if self._closed:
...@@ -92,12 +101,13 @@ class Iterator(object): ...@@ -92,12 +101,13 @@ class Iterator(object):
app = self.app app = self.app
if not self.txn_list: if not self.txn_list:
# ask some transactions # ask some transactions
self.txn_list = app.transactionLog(self.index, self.index + 100) self.txn_list = app.transactionLog(self._next, self._next + 100)
if not self.txn_list: if not self.txn_list:
# scan finished # scan finished
raise StopIteration raise StopIteration
self.index += len(self.txn_list) self._next += len(self.txn_list)
txn = self.txn_list.pop() txn = self.txn_list.pop()
self._index += 1
tid = txn['id'] tid = txn['id']
user = txn['user_name'] user = txn['user_name']
desc = txn['description'] desc = txn['description']
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment