python: wrap and use notmuch_database_destroy as destructor

Adapt the python bindings to the notmuch_database_close split.

Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
This commit is contained in:
Justus Winter 2012-04-22 14:07:57 +02:00 committed by David Bremner
parent 288feb7cdf
commit 7bfc4bf501

View file

@ -161,8 +161,13 @@ class Database(object):
else: else:
self.create(path) self.create(path)
_destroy = nmlib.notmuch_database_destroy
_destroy.argtypes = [NotmuchDatabaseP]
_destroy.restype = None
def __del__(self): def __del__(self):
self.close() if self._db:
self._destroy(self._db)
def _assert_db_is_initialized(self): def _assert_db_is_initialized(self):
"""Raises :exc:`NotInitializedError` if self._db is `None`""" """Raises :exc:`NotInitializedError` if self._db is `None`"""
@ -218,10 +223,11 @@ class Database(object):
_close.restype = None _close.restype = None
def close(self): def close(self):
"""Close and free the notmuch database if needed""" '''
if self._db is not None: Closes the notmuch database.
'''
if self._db:
self._close(self._db) self._close(self._db)
self._db = None
def __enter__(self): def __enter__(self):
''' '''