]> git.notmuchmail.org Git - notmuch/blobdiff - bindings/python-cffi/notmuch2/_database.py
Fix typos
[notmuch] / bindings / python-cffi / notmuch2 / _database.py
index fc55fea8f50bd0260c377dde7fd69919875fe02c..5ab0f20a72644dfddb56b5d569292bab3f695258 100644 (file)
@@ -400,7 +400,7 @@ class Database(base.NotmuchObject):
               capi.lib.NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID]
         if ret not in ok:
             raise errors.NotmuchError(ret)
               capi.lib.NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID]
         if ret not in ok:
             raise errors.NotmuchError(ret)
-        msg = message.StandaloneMessage(self, msg_pp[0], db=self)
+        msg = message.Message(self, msg_pp[0], db=self)
         if sync_flags:
             msg.tags.from_maildir_flags()
         return self.AddedMessage(
         if sync_flags:
             msg.tags.from_maildir_flags()
         return self.AddedMessage(
@@ -422,7 +422,7 @@ class Database(base.NotmuchObject):
            of it as ``dup = db.remove_message(name); if dup: ...``.
         :rtype: bool
 
            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 ReadOnlyDatabaseError: The database is opened in
            READ_ONLY mode.
         :raises UpgradeRequiredError: The database must be upgraded
@@ -458,7 +458,7 @@ class Database(base.NotmuchObject):
         :raises LookupError: If no message was found.
         :raises OutOfMemoryError: When there is no memory to allocate
            the message instance.
         :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 **')
         :raises ObjectDestroyedError: if used after destroyed.
         """
         msg_pp = capi.ffi.new('notmuch_message_t **')
@@ -469,7 +469,7 @@ class Database(base.NotmuchObject):
         msg_p = msg_pp[0]
         if msg_p == capi.ffi.NULL:
             raise LookupError
         msg_p = msg_pp[0]
         if msg_p == capi.ffi.NULL:
             raise LookupError
-        msg = message.StandaloneMessage(self, msg_p, db=self)
+        msg = message.Message(self, msg_p, db=self)
         return msg
 
     def get(self, filename):
         return msg
 
     def get(self, filename):
@@ -489,7 +489,7 @@ class Database(base.NotmuchObject):
            a subclass of :exc:`KeyError`.
         :raises OutOfMemoryError: When there is no memory to allocate
            the message instance.
            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):
         :raises ObjectDestroyedError: if used after destroyed.
         """
         if not hasattr(os, 'PathLike') and isinstance(filename, pathlib.Path):
@@ -502,7 +502,7 @@ class Database(base.NotmuchObject):
         msg_p = msg_pp[0]
         if msg_p == capi.ffi.NULL:
             raise LookupError
         msg_p = msg_pp[0]
         if msg_p == capi.ffi.NULL:
             raise LookupError
-        msg = message.StandaloneMessage(self, msg_p, db=self)
+        msg = message.Message(self, msg_p, db=self)
         return msg
 
     @property
         return msg
 
     @property
@@ -664,6 +664,7 @@ class AtomicContext:
     def __init__(self, db, ptr_name):
         self._db = db
         self._ptr = lambda: getattr(db, ptr_name)
     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()
 
     def __del__(self):
         self._destroy()
@@ -679,18 +680,22 @@ class AtomicContext:
         ret = capi.lib.notmuch_database_begin_atomic(self._ptr())
         if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
             raise errors.NotmuchError(ret)
         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
 
         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)
 
         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
     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.
 
         useful if the original exit raised an exception and the atomic
         section is still open.  But things are pretty ugly by now.
 
@@ -704,6 +709,15 @@ class AtomicContext:
         if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
             raise errors.NotmuchError(ret)
 
         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:
 
 @functools.total_ordering
 class DbRevision: