aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/pyme/util.py
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-05-19 09:03:27 +0000
committerJustus Winter <[email protected]>2016-05-19 13:58:45 +0000
commitd90857a08c4fe5b73b6d6d46fd6200efdd72db44 (patch)
tree93ce7fab9855dfa66bf0d1f45cba4010d3eba1af /lang/python/pyme/util.py
parentQt: Check for graphviz and set HAVE_DOT correctly (diff)
downloadgpgme-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/util.py')
-rw-r--r--lang/python/pyme/util.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/lang/python/pyme/util.py b/lang/python/pyme/util.py
index 3c34c79e..b54cd4dc 100644
--- a/lang/python/pyme/util.py
+++ b/lang/python/pyme/util.py
@@ -32,6 +32,11 @@ def process_constants(starttext, dict):
class GpgmeWrapper(object):
"""Base class all Pyme wrappers for GPGME functionality. Not to be
instantiated directly."""
+
+ def __init__(self, wrapped):
+ self._callback_excinfo = None
+ self.wrapped = wrapped
+
def __repr__(self):
return '<instance of %s.%s with GPG object at %s>' % \
(__name__, self.__class__.__name__,
@@ -78,11 +83,16 @@ class GpgmeWrapper(object):
if self._errorcheck(name):
def _funcwrap(slf, *args, **kwargs):
- return errorcheck(func(slf.wrapped, *args, **kwargs),
- "Invocation of " + name)
+ result = func(slf.wrapped, *args, **kwargs)
+ if slf._callback_excinfo:
+ pygpgme.pygpgme_raise_callback_exception(slf)
+ return errorcheck(result, "Invocation of " + name)
else:
def _funcwrap(slf, *args, **kwargs):
- return func(slf.wrapped, *args, **kwargs)
+ result = func(slf.wrapped, *args, **kwargs)
+ if slf._callback_excinfo:
+ pygpgme.pygpgme_raise_callback_exception(slf)
+ return result
_funcwrap.__doc__ = getattr(func, "__doc__")