diff options
| author | Justus Winter <[email protected]> | 2016-05-24 10:29:32 +0000 | 
|---|---|---|
| committer | Justus Winter <[email protected]> | 2016-05-24 11:13:35 +0000 | 
| commit | 09803c4a81b9431fd4c8f30abb1c60c4c735f0cb (patch) | |
| tree | fd7e42c65876321b5e8d3a98027d8a14eaf57f28 /lang/python/helpers.c | |
| parent | python: Fix hook. (diff) | |
| download | gpgme-09803c4a81b9431fd4c8f30abb1c60c4c735f0cb.tar.gz gpgme-09803c4a81b9431fd4c8f30abb1c60c4c735f0cb.zip | |
python: Improve support for edit callbacks.
* lang/python/helpers.c (pyEditCb): Stash exceptions.
* lang/python/pyme/core.py (Context.op_edit): Hand in 'self'.
* lang/python/tests/Makefile.am (py_tests): Add new test.
* lang/python/tests/t-callbacks.py: Test edit callbacks.
* lang/python/tests/t-edit.py: New file.
Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'lang/python/helpers.c')
| -rw-r--r-- | lang/python/helpers.c | 12 | 
1 files changed, 8 insertions, 4 deletions
| diff --git a/lang/python/helpers.c b/lang/python/helpers.c index 0ee24a3f..d0c1f3b6 100644 --- a/lang/python/helpers.c +++ b/lang/python/helpers.c @@ -280,15 +280,18 @@ gpgme_error_t pyEditCb(void *opaque, gpgme_status_code_t status,    PyObject *func = NULL, *dataarg = NULL, *pyargs = NULL, *retval = NULL;    PyObject *pyopaque = (PyObject *) opaque;    gpgme_error_t err_status = 0; +  PyObject *self = NULL;    pygpgme_exception_init(); -  if (PyTuple_Check(pyopaque)) { -    func = PyTuple_GetItem(pyopaque, 0); -    dataarg = PyTuple_GetItem(pyopaque, 1); +  assert (PyTuple_Check(pyopaque)); +  assert (PyTuple_Size(pyopaque) == 2 || PyTuple_Size(pyopaque) == 3); +  self = PyTuple_GetItem(pyopaque, 0); +  func = PyTuple_GetItem(pyopaque, 1); +  if (PyTuple_Size(pyopaque) == 3) { +    dataarg = PyTuple_GetItem(pyopaque, 2);      pyargs = PyTuple_New(3);    } else { -    func = pyopaque;      pyargs = PyTuple_New(2);    } @@ -303,6 +306,7 @@ gpgme_error_t pyEditCb(void *opaque, gpgme_status_code_t status,    Py_DECREF(pyargs);    if (PyErr_Occurred()) {      err_status = pygpgme_exception2code(); +    pygpgme_stash_callback_exception(self);    } else {      if (fd>=0 && retval && PyUnicode_Check(retval)) {        const char *buffer; | 
