aboutsummaryrefslogtreecommitdiff
path: root/bindings/python/notmuch/filename.py
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2011-10-10 00:12:54 +0200
committerSebastian Spaeth <Sebastian@SSpaeth.de>2011-12-01 22:24:19 +0100
commit3434d194026ff65217d9342ffe511f67fd71e79f (patch)
treeadcd4621f97ac5143efd378530d62a78f3b937f5 /bindings/python/notmuch/filename.py
parente92b438f46a3ad7103299b1c62747f36d9de06bf (diff)
python: annotate all calls into libnotmuch with types
Add type information to the ctypes._FuncPtr wrappers and use the wrapper classes instead of c_void_p for pointers to notmuch_*_t. This enables the ctypes library to type check parameters being handed to functions from the notmuch library. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
Diffstat (limited to 'bindings/python/notmuch/filename.py')
-rw-r--r--bindings/python/notmuch/filename.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py
index de4d785..077754e 100644
--- a/bindings/python/notmuch/filename.py
+++ b/bindings/python/notmuch/filename.py
@@ -17,7 +17,8 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>.
Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
"""
from ctypes import c_char_p
-from notmuch.globals import nmlib, STATUS, NotmuchError
+from notmuch.globals import (nmlib, STATUS, NotmuchError,
+ NotmuchFilenamesP, NotmuchMessagesP, NotmuchMessageP)
class Filenames(object):
@@ -50,6 +51,7 @@ class Filenames(object):
#notmuch_filenames_get
_get = nmlib.notmuch_filenames_get
+ _get.argtypes = [NotmuchFilenamesP]
_get.restype = c_char_p
def __init__(self, files_p, parent):
@@ -74,6 +76,14 @@ class Filenames(object):
#save reference to parent object so we keep it alive
self._parent = parent
+ _valid = nmlib.notmuch_filenames_valid
+ _valid.argtypes = [NotmuchFilenamesP]
+ _valid.restype = bool
+
+ _move_to_next = nmlib.notmuch_filenames_move_to_next
+ _move_to_next.argtypes = [NotmuchFilenamesP]
+ _move_to_next.restype = None
+
def as_generator(self):
"""Return generator of Filenames
@@ -82,9 +92,9 @@ class Filenames(object):
if self._files is None:
raise NotmuchError(STATUS.NOT_INITIALIZED)
- while nmlib.notmuch_filenames_valid(self._files):
+ while self._valid(self._files):
yield Filenames._get(self._files)
- nmlib.notmuch_filenames_move_to_next(self._files)
+ self._move_to_next(self._files)
self._files = None
@@ -101,7 +111,11 @@ class Filenames(object):
"""
return "\n".join(self)
+ _destroy = nmlib.notmuch_filenames_destroy
+ _destroy.argtypes = [NotmuchMessageP]
+ _destroy.restype = None
+
def __del__(self):
"""Close and free the notmuch filenames"""
if self._files is not None:
- nmlib.notmuch_filenames_destroy(self._files)
+ self._destroy(self._files)