aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Spaeth <sebastian@sspaeth.de>2010-03-16 15:00:42 +0100
committerSebastian Spaeth <sebastian@sspaeth.de>2010-03-16 15:00:42 +0100
commite026813bcb623bff70895a353aeef90364f66795 (patch)
treebd8eb445e7bfc5ed6906e14e75afecb4f537385a
parentbb5870b9af7d023d7d61233dc19d73772d84fdc5 (diff)
Fix iterator classes to not skip the first element when iterating
--HG-- extra : transplant_source : %19wvB%19A%0A%CD%E7%28-%F0%12j%7FG%0DD%16%F4
-rw-r--r--cnotmuch/database.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/cnotmuch/database.py b/cnotmuch/database.py
index cdcd31c0..82f1372c 100644
--- a/cnotmuch/database.py
+++ b/cnotmuch/database.py
@@ -239,16 +239,19 @@ class Tags(object):
def __iter__(self):
""" Make Tags an iterator """
- if self._tags is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
return self
def next(self):
- nmlib.notmuch_tags_move_to_next(self._tags)
+ if self._tags is None:
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
+
if not nmlib.notmuch_tags_valid(self._tags):
self._tags = None
raise StopIteration
- return Tags._get (self._tags)
+
+ tag = Tags._get (self._tags)
+ nmlib.notmuch_tags_move_to_next(self._tags)
+ return tag
def __del__(self):
"""Close and free the notmuch tags"""
@@ -296,11 +299,13 @@ class Messages(object):
if self._msgs is None:
raise NotmuchError(STATUS.NOT_INITIALIZED)
- nmlib.notmuch_messages_move_to_next(self._msgs)
if not nmlib.notmuch_messages_valid(self._msgs):
self._msgs = None
raise StopIteration
- return Message(Messages._get (self._msgs), self)
+
+ msg = Message(Messages._get (self._msgs), self)
+ nmlib.notmuch_messages_move_to_next(self._msgs)
+ return msg
def __del__(self):
"""Close and free the notmuch Messages"""