python: Fix hook.

* lang/python/helpers.c (pyProgressCb): Fix getting hook data.
* lang/python/tests/t-callbacks.py: Show that this works.

Signed-off-by: Justus Winter <justus@gnupg.org>
This commit is contained in:
Justus Winter 2016-05-23 18:23:34 +02:00
parent 5476ca6813
commit 283f0bdc3d
2 changed files with 3 additions and 2 deletions

View File

@ -235,7 +235,7 @@ static void pyProgressCb(void *hook, const char *what, int type, int current,
self = PyTuple_GetItem(pyhook, 0); self = PyTuple_GetItem(pyhook, 0);
func = PyTuple_GetItem(pyhook, 1); func = PyTuple_GetItem(pyhook, 1);
if (PyTuple_Size(pyhook) == 3) { if (PyTuple_Size(pyhook) == 3) {
dataarg = PyTuple_GetItem(pyhook, 1); dataarg = PyTuple_GetItem(pyhook, 2);
args = PyTuple_New(5); args = PyTuple_New(5);
} else { } else {
args = PyTuple_New(4); args = PyTuple_New(4);

View File

@ -91,12 +91,13 @@ Expire-Date: 2020-12-31
messages = [] messages = []
def progress_cb(what, typ, current, total, hook=None): def progress_cb(what, typ, current, total, hook=None):
assert hook == messages
messages.append( messages.append(
"PROGRESS UPDATE: what = {}, type = {}, current = {}, total = {}" "PROGRESS UPDATE: what = {}, type = {}, current = {}, total = {}"
.format(what, typ, current, total)) .format(what, typ, current, total))
c = core.Context() c = core.Context()
c.set_progress_cb(progress_cb, None) c.set_progress_cb(progress_cb, messages)
c.op_genkey(parms, None, None) c.op_genkey(parms, None, None)
assert len(messages) > 0 assert len(messages) > 0