aboutsummaryrefslogtreecommitdiffstats
path: root/lang
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-05-23 16:09:22 +0000
committerJustus Winter <[email protected]>2016-05-23 16:09:22 +0000
commit5476ca6813fc9d8833d5224f19d4bb7515380ab5 (patch)
treef949f61996e7a90b944b01a40b5d5164c95a7d08 /lang
parentpython: Port more tests. (diff)
downloadgpgme-5476ca6813fc9d8833d5224f19d4bb7515380ab5.tar.gz
gpgme-5476ca6813fc9d8833d5224f19d4bb7515380ab5.zip
python: Move edit callback function.
* lang/python/gpgme.i (pyEditCb): Move... * lang/python/helpers.c: ... here. * lang/python/helpers.h (pyEditCb): New prototype. Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'lang')
-rw-r--r--lang/python/gpgme.i45
-rw-r--r--lang/python/helpers.c45
-rw-r--r--lang/python/helpers.h3
3 files changed, 48 insertions, 45 deletions
diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index fb882c85..a82efb55 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -283,48 +283,3 @@ FILE *fdopen(int fildes, const char *mode);
#include "helpers.h"
%}
%include "helpers.h"
-
-%{
-gpgme_error_t pyEditCb(void *opaque, gpgme_status_code_t status,
- const char *args, int fd) {
- PyObject *func = NULL, *dataarg = NULL, *pyargs = NULL, *retval = NULL;
- PyObject *pyopaque = (PyObject *) opaque;
- gpgme_error_t err_status = 0;
-
- pygpgme_exception_init();
-
- if (PyTuple_Check(pyopaque)) {
- func = PyTuple_GetItem(pyopaque, 0);
- dataarg = PyTuple_GetItem(pyopaque, 1);
- pyargs = PyTuple_New(3);
- } else {
- func = pyopaque;
- pyargs = PyTuple_New(2);
- }
-
- PyTuple_SetItem(pyargs, 0, PyLong_FromLong((long) status));
- PyTuple_SetItem(pyargs, 1, PyUnicode_FromString(args));
- if (dataarg) {
- Py_INCREF(dataarg); /* Because GetItem doesn't give a ref but SetItem taketh away */
- PyTuple_SetItem(pyargs, 2, dataarg);
- }
-
- retval = PyObject_CallObject(func, pyargs);
- Py_DECREF(pyargs);
- if (PyErr_Occurred()) {
- err_status = pygpgme_exception2code();
- } else {
- if (fd>=0 && retval && PyUnicode_Check(retval)) {
- const char *buffer;
- Py_ssize_t size;
-
- buffer = PyUnicode_AsUTF8AndSize(retval, &size);
- write(fd, buffer, size);
- write(fd, "\n", 1);
- }
- }
-
- Py_XDECREF(retval);
- return err_status;
-}
-%}
diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 7ced04a4..e3055741 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -272,3 +272,48 @@ void pygpgme_set_progress_cb(gpgme_ctx_t ctx, PyObject *cb, PyObject **freelater
*freelater = cb;
gpgme_set_progress_cb(ctx, (gpgme_progress_cb_t) pyProgressCb, (void *) cb);
}
+
+
+/* Edit callbacks. */
+gpgme_error_t pyEditCb(void *opaque, gpgme_status_code_t status,
+ const char *args, int fd) {
+ PyObject *func = NULL, *dataarg = NULL, *pyargs = NULL, *retval = NULL;
+ PyObject *pyopaque = (PyObject *) opaque;
+ gpgme_error_t err_status = 0;
+
+ pygpgme_exception_init();
+
+ if (PyTuple_Check(pyopaque)) {
+ func = PyTuple_GetItem(pyopaque, 0);
+ dataarg = PyTuple_GetItem(pyopaque, 1);
+ pyargs = PyTuple_New(3);
+ } else {
+ func = pyopaque;
+ pyargs = PyTuple_New(2);
+ }
+
+ PyTuple_SetItem(pyargs, 0, PyLong_FromLong((long) status));
+ PyTuple_SetItem(pyargs, 1, PyUnicode_FromString(args));
+ if (dataarg) {
+ Py_INCREF(dataarg); /* Because GetItem doesn't give a ref but SetItem taketh away */
+ PyTuple_SetItem(pyargs, 2, dataarg);
+ }
+
+ retval = PyObject_CallObject(func, pyargs);
+ Py_DECREF(pyargs);
+ if (PyErr_Occurred()) {
+ err_status = pygpgme_exception2code();
+ } else {
+ if (fd>=0 && retval && PyUnicode_Check(retval)) {
+ const char *buffer;
+ Py_ssize_t size;
+
+ buffer = PyUnicode_AsUTF8AndSize(retval, &size);
+ write(fd, buffer, size);
+ write(fd, "\n", 1);
+ }
+ }
+
+ Py_XDECREF(retval);
+ return err_status;
+}
diff --git a/lang/python/helpers.h b/lang/python/helpers.h
index 81d17ffa..4bd8ef81 100644
--- a/lang/python/helpers.h
+++ b/lang/python/helpers.h
@@ -35,3 +35,6 @@ PyObject *pygpgme_raise_callback_exception(PyObject *self);
void pygpgme_set_passphrase_cb(gpgme_ctx_t ctx, PyObject *cb,
PyObject **freelater);
void pygpgme_set_progress_cb(gpgme_ctx_t ctx, PyObject *cb, PyObject **freelater);
+
+gpgme_error_t pyEditCb(void *opaque, gpgme_status_code_t status,
+ const char *args, int fd);