diff options
author | Justus Winter <[email protected]> | 2016-05-19 09:03:27 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2016-05-19 13:58:45 +0000 |
commit | d90857a08c4fe5b73b6d6d46fd6200efdd72db44 (patch) | |
tree | 93ce7fab9855dfa66bf0d1f45cba4010d3eba1af /lang/python/pyme/core.py | |
parent | Qt: Check for graphviz and set HAVE_DOT correctly (diff) | |
download | gpgme-d90857a08c4fe5b73b6d6d46fd6200efdd72db44.tar.gz gpgme-d90857a08c4fe5b73b6d6d46fd6200efdd72db44.zip |
python: Robust exception handling in callbacks.
* lang/python/helpers.c (pygpgme_stash_callback_exception): New
function.
(pygpgme_raise_callback_exception): Likewise.
(pyPassphraseCb): Stash python errors.
* lang/python/helpers.h (pygpgme_raise_callback_exception): New
prototype.
* lang/python/pyme/core.py ({Context,Data}.__init__): Move common
initialization to superclass.
(Context.set_progress_cb): Hand in 'self'.
* lang/python/pyme/util.py (GpgmeWrapper.__init__): New function.
(GpgmeWrapper.__getattr__): Raise stashed exceptions.
* lang/python/tests/Makefile.am (py_tests): Add new test.
* lang/python/tests/t-callbacks.py: New file.
Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'lang/python/pyme/core.py')
-rw-r--r-- | lang/python/pyme/core.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py index 2a0ca072..8a4c197e 100644 --- a/lang/python/pyme/core.py +++ b/lang/python/pyme/core.py @@ -54,14 +54,14 @@ class Context(GpgmeWrapper): def __init__(self, wrapped=None): if wrapped: - self.wrapped = wrapped self.own = False else: tmp = pygpgme.new_gpgme_ctx_t_p() errorcheck(pygpgme.gpgme_new(tmp)) - self.wrapped = pygpgme.gpgme_ctx_t_p_value(tmp) + wrapped = pygpgme.gpgme_ctx_t_p_value(tmp) pygpgme.delete_gpgme_ctx_t_p(tmp) self.own = True + super().__init__(wrapped) self.last_passcb = None self.last_progresscb = None @@ -167,9 +167,9 @@ class Context(GpgmeWrapper): else: self.last_passcb = pygpgme.new_PyObject_p_p() if hook == None: - hookdata = func + hookdata = (self, func) else: - hookdata = (func, hook) + hookdata = (self, func, hook) pygpgme.pygpgme_set_passphrase_cb(self.wrapped, hookdata, self.last_passcb) def set_progress_cb(self, func, hook=None): @@ -282,7 +282,7 @@ class Data(GpgmeWrapper): that file. Any other use will result in undefined or erroneous behavior.""" - self.wrapped = None + super().__init__(None) self.last_readcb = None if cbs != None: |