mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
make Session a context manager
This commit is contained in:
@@ -117,6 +117,15 @@ class Session(GnuCashCoreClass):
|
||||
self.destroy()
|
||||
raise
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
# Roll back changes on exception by not calling save. Only works for XMl backend.
|
||||
if not exc_type:
|
||||
self.save()
|
||||
self.end()
|
||||
|
||||
def raise_backend_errors(self, called_function="qof_session function"):
|
||||
"""Raises a GnuCashBackendException if there are outstanding
|
||||
QOF_BACKEND errors.
|
||||
|
||||
Reference in New Issue
Block a user