import weakref
import notmuch2._base as base
+import notmuch2._config as config
import notmuch2._capi as capi
import notmuch2._errors as errors
import notmuch2._message as message
of it as ``dup = db.remove_message(name); if dup: ...``.
:rtype: bool
- :raises XapianError: A Xapian exception ocurred.
+ :raises XapianError: A Xapian exception occurred.
:raises ReadOnlyDatabaseError: The database is opened in
READ_ONLY mode.
:raises UpgradeRequiredError: The database must be upgraded
:raises LookupError: If no message was found.
:raises OutOfMemoryError: When there is no memory to allocate
the message instance.
- :raises XapianError: A Xapian exception ocurred.
+ :raises XapianError: A Xapian exception occurred.
:raises ObjectDestroyedError: if used after destroyed.
"""
msg_pp = capi.ffi.new('notmuch_message_t **')
a subclass of :exc:`KeyError`.
:raises OutOfMemoryError: When there is no memory to allocate
the message instance.
- :raises XapianError: A Xapian exception ocurred.
+ :raises XapianError: A Xapian exception occurred.
:raises ObjectDestroyedError: if used after destroyed.
"""
if not hasattr(os, 'PathLike') and isinstance(filename, pathlib.Path):
self._cached_tagset = weakref.ref(tagset)
return tagset
+ @property
+ def config(self):
+ """Return a mutable mapping with the settings stored in this database.
+
+ This returns an mutable dict-like object implementing the
+ collections.abc.MutableMapping Abstract Base Class.
+
+ :rtype: Config
+
+ :raises ObjectDestroyedError: if used after destroyed.
+ """
+ try:
+ ref = self._cached_config
+ except AttributeError:
+ config_mapping = None
+ else:
+ config_mapping = ref()
+ if config_mapping is None:
+ config_mapping = config.ConfigMapping(self, '_db_p')
+ self._cached_config = weakref.ref(config_mapping)
+ return config_mapping
+
def _create_query(self, query, *,
omit_excluded=EXCLUDE.TRUE,
sort=SORT.UNSORTED, # Check this default
if exclude_tags is not None:
for tag in exclude_tags:
if isinstance(tag, str):
- tag = str.encode('utf-8')
+ tag = tag.encode('utf-8')
capi.lib.notmuch_query_add_tag_exclude(query_p, tag)
return querymod.Query(self, query_p)
def __init__(self, db, ptr_name):
self._db = db
self._ptr = lambda: getattr(db, ptr_name)
+ self._exit_fn = lambda: None
def __del__(self):
self._destroy()
ret = capi.lib.notmuch_database_begin_atomic(self._ptr())
if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
raise errors.NotmuchError(ret)
+ self._exit_fn = self._end_atomic
return self
- def __exit__(self, exc_type, exc_value, traceback):
+ def _end_atomic(self):
ret = capi.lib.notmuch_database_end_atomic(self._ptr())
if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
raise errors.NotmuchError(ret)
+ def __exit__(self, exc_type, exc_value, traceback):
+ self._exit_fn()
+
def force_end(self):
"""Force ending the atomic section.
This can only be called once __exit__ has been called. It
- will attept to close the atomic section (again). This is
+ will attempt to close the atomic section (again). This is
useful if the original exit raised an exception and the atomic
section is still open. But things are pretty ugly by now.
if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
raise errors.NotmuchError(ret)
+ def abort(self):
+ """Abort the transaction.
+
+ Aborting a transaction will not commit any of the changes, but
+ will also implicitly close the database.
+ """
+ self._exit_fn = lambda: None
+ self._db.close()
+
@functools.total_ordering
class DbRevision: