aboutsummaryrefslogtreecommitdiff
path: root/bindings/python/notmuch/thread.py
diff options
context:
space:
mode:
authorSebastian Spaeth <Sebastian@SSpaeth.de>2011-06-02 16:28:00 +0200
committerSebastian Spaeth <Sebastian@SSpaeth.de>2011-06-02 16:28:00 +0200
commit01cc4a31155dc71643fce1b619778493c1ff0dd7 (patch)
treeb8847a55041cb6939dde49ac5b7738b7e98e0b09 /bindings/python/notmuch/thread.py
parent4d406d9c252e707477a1cc744c4ee74bde4d1c3c (diff)
bindings/python: implement Threads().__nonzero__
__nonzero__ checks if Threads() contains at least one more valid thread The existence of this function makes 'if Threads(): foo' work, as that previously implicitely called len() exhausting the iterator. This function makes `bool(Threads())` work repeatedly. For further info, see http://docs.python.org/reference/datamodel.html. Credits for the hint go to Brian May. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'bindings/python/notmuch/thread.py')
-rw-r--r--bindings/python/notmuch/thread.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index eebd6cb..2bb30b7 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -141,7 +141,19 @@ class Threads(object):
self._threads = None
return i
-
+ def __nonzero__(self):
+ """Check if :class:`Threads` contains at least one more valid thread
+
+ The existence of this function makes 'if Threads: foo' work, as
+ that will implicitely call len() exhausting the iterator if
+ __nonzero__ does not exist. This function makes `bool(Threads())`
+ work repeatedly.
+
+ :return: True if there is at least one more thread in the
+ Iterator, False if not. None on a "Out-of-memory" error.
+ """
+ return self._threads is not None and \
+ nmlib.notmuch_threads_valid(self._threads) > 0
def __del__(self):
"""Close and free the notmuch Threads"""