From a458e7fe2006d92bd5a838e2747fb66bbac4b1b8 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Fri, 16 Sep 2016 14:56:29 +0200 Subject: python: Adapt to 'gpgme_op_interact'. * lang/python/examples/inter-edit.py: Update example. * lang/python/gpgme.i (gpgme_edit_cb_t): Turn into 'gpgme_interact_cb_t'. * lang/python/helpers.c (_pyme_edit_cb): Turn into '_pyme_interact_cb_t'. * lang/python/private.h (_pyme_edit_cb): Likewise. * lang/python/pyme/constants/__init__.py: Replace numeric status codes with the keywords. * lang/python/pyme/constants/status.py: Likewise. * lang/python/pyme/core.py (Context.interact): New method. (Context.op_edit): Deprecate, update docstring, implement using Context.interact. * lang/python/tests/t-edit.py: Test both interfaces. Signed-off-by: Justus Winter --- lang/python/helpers.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'lang/python/helpers.c') diff --git a/lang/python/helpers.c b/lang/python/helpers.c index bc8aed40..bb2128c9 100644 --- a/lang/python/helpers.c +++ b/lang/python/helpers.c @@ -656,11 +656,16 @@ pyme_set_status_cb(PyObject *self, PyObject *cb) { Py_INCREF(Py_None); return Py_None; } + -/* Edit callbacks. */ -gpgme_error_t _pyme_edit_cb(void *opaque, gpgme_status_code_t status, - const char *args, int fd) { + +/* Interact callbacks. */ +gpgme_error_t +_pyme_interact_cb(void *opaque, const char *keyword, + const char *args, int fd) +{ PyObject *func = NULL, *dataarg = NULL, *pyargs = NULL, *retval = NULL; + PyObject *py_keyword; PyObject *pyopaque = (PyObject *) opaque; gpgme_error_t err_status = 0; PyObject *self = NULL; @@ -678,7 +683,15 @@ gpgme_error_t _pyme_edit_cb(void *opaque, gpgme_status_code_t status, pyargs = PyTuple_New(2); } - PyTuple_SetItem(pyargs, 0, PyLong_FromLong((long) status)); + if (keyword) + py_keyword = PyUnicode_FromString(keyword); + else + { + Py_INCREF(Py_None); + py_keyword = Py_None; + } + + PyTuple_SetItem(pyargs, 0, py_keyword); PyTuple_SetItem(pyargs, 1, PyUnicode_FromString(args)); if (dataarg) { Py_INCREF(dataarg); /* Because GetItem doesn't give a ref but SetItem taketh away */ @@ -726,7 +739,9 @@ gpgme_error_t _pyme_edit_cb(void *opaque, gpgme_status_code_t status, Py_XDECREF(retval); return err_status; } + + /* Data callbacks. */ /* Read up to SIZE bytes into buffer BUFFER from the data object with -- cgit v1.2.3