aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/pyme/core.py
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-05-24 13:14:53 +0000
committerJustus Winter <[email protected]>2016-05-24 16:00:16 +0000
commit8b57f06e0c04f5c9b87a3c76618230d757412076 (patch)
treee7a0779263eb230b5e82cf2dd6abf2b9188655b3 /lang/python/pyme/core.py
parentpython: Improve docstring. (diff)
downloadgpgme-8b57f06e0c04f5c9b87a3c76618230d757412076.tar.gz
gpgme-8b57f06e0c04f5c9b87a3c76618230d757412076.zip
python: Support status callbacks.
* lang/python/helpers.c (pyStatusCb): New function. (pygpgme_set_status_cb): Likewise. * lang/python/helpers.h (pygpgme_set_status_cb): New prototype. * lang/python/pyme/core.py (Context.__init__): Initialize 'last_statuscb'. (Context._free_statuscb): New function. (Context.set_status_cb): Likewise. * lang/python/tests/t-callbacks.py: Test status callbacks. Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'lang/python/pyme/core.py')
-rw-r--r--lang/python/pyme/core.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py
index 43a24131..f15444be 100644
--- a/lang/python/pyme/core.py
+++ b/lang/python/pyme/core.py
@@ -64,6 +64,7 @@ class Context(GpgmeWrapper):
super().__init__(wrapped)
self.last_passcb = None
self.last_progresscb = None
+ self.last_statuscb = None
def __del__(self):
if not pygpgme:
@@ -91,6 +92,14 @@ class Context(GpgmeWrapper):
pygpgme.delete_PyObject_p_p(self.last_progresscb)
self.last_progresscb = None
+ def _free_statuscb(self):
+ if self.last_statuscb != None:
+ if pygpgme.pygpgme_clear_generic_cb:
+ pygpgme.pygpgme_clear_generic_cb(self.last_statuscb)
+ if pygpgme.delete_PyObject_p_p:
+ pygpgme.delete_PyObject_p_p(self.last_statuscb)
+ self.last_statuscb = None
+
def op_keylist_all(self, *args, **kwargs):
self.op_keylist_start(*args, **kwargs)
key = self.op_keylist_next()
@@ -195,6 +204,29 @@ class Context(GpgmeWrapper):
hookdata = (self, func, hook)
pygpgme.pygpgme_set_progress_cb(self.wrapped, hookdata, self.last_progresscb)
+ def set_status_cb(self, func, hook=None):
+ """Sets the status callback to the function specified by FUNC. If
+ FUNC is None, the callback will be cleared.
+
+ The function will be called with two arguments, keyword and
+ args. If HOOK is not None, it will be supplied as third
+ argument.
+
+ Please see the GPGME manual for more information.
+
+ """
+ self._free_statuscb()
+ if func == None:
+ hookdata = None
+ else:
+ self.last_statuscb = pygpgme.new_PyObject_p_p()
+ if hook == None:
+ hookdata = (self, func)
+ else:
+ hookdata = (self, func, hook)
+ pygpgme.pygpgme_set_status_cb(self.wrapped, hookdata,
+ self.last_statuscb)
+
def get_engine_info(self):
"""Returns this context specific engine info"""
return pygpgme.gpgme_ctx_get_engine_info(self.wrapped)