X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=bindings%2Fpython%2Fnotmuch%2Ffilename.py;h=de4d785ad6085ddfd3fbf42ebe54ae33d5ca76c7;hb=1915c14a3a0f947629687c686391d99ac9d3a988;hp=20b90e98b86f864c39a72c549330e05d26d34417;hpb=b31247c354b54a3cbeb1c7f9df830e16f7c921d9;p=notmuch diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py index 20b90e98..de4d785a 100644 --- a/bindings/python/notmuch/filename.py +++ b/bindings/python/notmuch/filename.py @@ -19,19 +19,20 @@ Copyright 2010 Sebastian Spaeth ' from ctypes import c_char_p from notmuch.globals import nmlib, STATUS, NotmuchError -#------------------------------------------------------------------------------ + class Filenames(object): """Represents a list of filenames as returned by notmuch - This object contains the Filenames iterator. The main function is as_generator() which will return a generator so we can do a Filenamesth an iterator over a list of notmuch filenames. Do - note that the underlying library only provides a one-time iterator - (it cannot reset the iterator to the start). Thus iterating over - the function will "exhaust" the list of tags, and a subsequent - iteration attempt will raise a :exc:`NotmuchError` - STATUS.NOT_INITIALIZED. Also note, that any function that uses - iteration (nearly all) will also exhaust the tags. So both:: + This object contains the Filenames iterator. The main function is + as_generator() which will return a generator so we can do a Filenamesth an + iterator over a list of notmuch filenames. Do note that the underlying + library only provides a one-time iterator (it cannot reset the iterator to + the start). Thus iterating over the function will "exhaust" the list of + tags, and a subsequent iteration attempt will raise a :exc:`NotmuchError` + STATUS.NOT_INITIALIZED. Also note, that any function that uses iteration + (nearly all) will also exhaust the tags. So both:: - for name in filenames: print name + for name in filenames: print name as well as:: @@ -67,7 +68,7 @@ class Filenames(object): once all derived objects are dead. """ if files_p is None: - NotmuchError(STATUS.NULL_POINTER) + raise NotmuchError(STATUS.NULL_POINTER) self._files = files_p #save reference to parent object so we keep it alive @@ -81,14 +82,12 @@ class Filenames(object): if self._files is None: raise NotmuchError(STATUS.NOT_INITIALIZED) - if not nmlib.notmuch_filenames_valid(self._files): - self._files = None - return + while nmlib.notmuch_filenames_valid(self._files): + yield Filenames._get(self._files) + nmlib.notmuch_filenames_move_to_next(self._files) + + self._files = None - file = Filenames._get (self._files) - nmlib.notmuch_filenames_move_to_next(self._files) - yield file - def __str__(self): """Represent Filenames() as newline-separated list of full paths @@ -105,4 +104,4 @@ class Filenames(object): def __del__(self): """Close and free the notmuch filenames""" if self._files is not None: - nmlib.notmuch_filenames_destroy (self._files) + nmlib.notmuch_filenames_destroy(self._files)