X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=bindings%2Fpython%2Fnotmuch%2Fdatabase.py;h=1db332fe333b0b83b79a3e6c004de8485d29ad63;hb=fcfb619b44b0011ac6bc557e6cbe2d516bc58f8a;hp=800264b7bd157f0e890714e21fdf7741b63f33d5;hpb=ba95980cf1a5e2b32104611ccdf2e9c43bf3305a;p=obsolete%2Fnotmuch-old
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 800264b7..1db332fe 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
@@ -54,21 +56,14 @@ class Database(object):
:class:`Database` objects implement the context manager protocol
so you can use the :keyword:`with` statement to ensure that the
- database is properly closed.
+ database is properly closed. See :meth:`close` for more
+ information.
.. note::
Any function in this class can and will throw an
:exc:`NotInitializedError` if the database was not intitialized
properly.
-
- .. note::
-
- Do remember that as soon as we tear down (e.g. via `del db`) this
- object, all underlying derived objects such as queries, threads,
- messages, tags etc will be freed by the underlying library as well.
- Accessing these objects will lead to segfaults and other unexpected
- behavior. See above for more details.
"""
_std_db_path = None
"""Class attribute to cache user's default database"""
@@ -159,8 +154,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 +182,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 +216,18 @@ 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.
+
+ .. warning::
+
+ This function closes the notmuch database. From that point
+ on every method invoked on any object ever derived from
+ the closed database may cease to function and raise a
+ NotmuchError.
+ '''
+ if self._db:
self._close(self._db)
- self._db = None
def __enter__(self):
'''