X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=bindings%2Fpython%2Fnotmuch%2Fdatabase.py;h=525f7c9a0ca9d0b2a933faa26185e3671e736e8f;hb=162687a99e412098729d639ed7bc27f01372cb84;hp=800264b7bd157f0e890714e21fdf7741b63f33d5;hpb=ba95980cf1a5e2b32104611ccdf2e9c43bf3305a;p=notmuch
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 800264b7..525f7c9a 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
import os
@@ -22,12 +22,6 @@ import codecs
from ctypes import c_char_p, c_void_p, c_uint, byref, POINTER
from notmuch.globals import (
nmlib,
- STATUS,
- FileError,
- NotmuchError,
- NullPointerError,
- NotInitializedError,
- ReadOnlyDatabaseError,
Enum,
_str,
NotmuchDatabaseP,
@@ -35,6 +29,14 @@ from notmuch.globals import (
NotmuchMessageP,
NotmuchTagsP,
)
+from .errors import (
+ STATUS,
+ FileError,
+ NotmuchError,
+ NullPointerError,
+ NotInitializedError,
+ ReadOnlyDatabaseError,
+)
from notmuch.message import Message
from notmuch.tag import Tags
from .query import Query
@@ -159,8 +161,13 @@ class Database(object):
else:
self.create(path)
+ _destroy = nmlib.notmuch_database_destroy
+ _destroy.argtypes = [NotmuchDatabaseP]
+ _destroy.restype = None
+
def __del__(self):
- self.close()
+ if self._db:
+ self._destroy(self._db)
def _assert_db_is_initialized(self):
"""Raises :exc:`NotInitializedError` if self._db is `None`"""
@@ -182,7 +189,7 @@ class Database(object):
:raises: :exc:`NotmuchError` in case of any failure
(possibly after printing an error message on stderr).
"""
- if self._db is not None:
+ if self._db:
raise NotmuchError(message="Cannot create db, this Database() "
"already has an open one.")
@@ -216,10 +223,11 @@ class Database(object):
_close.restype = None
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._db = None
def __enter__(self):
'''