From de69fa496c09386d5e99747670d6887cf52dd09e Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 28 Jul 2016 12:40:54 +0200 Subject: python: Support the Assuan engine. * lang/python/gpgme.i: Add typemaps for the Assuan protocol callbacks. * lang/python/helpers.c (_pyme_assuan_{data,inquire,status}_cb): New functions. * lang/python/private.h (_pyme_assuan_{data,inquire,status}_cb): New prototypes. * lang/python/pyme/core.py (Context.assuan_transact): New method. * lang/python/pyme/util.py (percent_escape): New function. * lang/python/tests/Makefile.am (py_tests): Add new test. * lang/python/tests/t-protocol-assuan.py: New file. Signed-off-by: Justus Winter --- lang/python/gpgme.i | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'lang/python/gpgme.i') diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i index a372edd4..24adf74d 100644 --- a/lang/python/gpgme.i +++ b/lang/python/gpgme.i @@ -443,6 +443,60 @@ $2 = $input; } + + +/* The assuan protocol callbacks. */ +%typemap(in) (gpgme_assuan_data_cb_t data_cb, void *data_cb_value) { + if ($input == Py_None) + $1 = $2 = NULL; + else + { + if (! PyTuple_Check($input)) + return PyErr_Format(PyExc_TypeError, "callback must be a tuple"); + if (PyTuple_Size($input) != 2) + return PyErr_Format(PyExc_TypeError, + "callback must be a tuple of size 2"); + if (! PyCallable_Check(PyTuple_GetItem($input, 1))) + return PyErr_Format(PyExc_TypeError, "second item must be callable"); + $1 = _pyme_assuan_data_cb; + $2 = $input; + } +} + +%typemap(in) (gpgme_assuan_inquire_cb_t inq_cb, void *inq_cb_value) { + if ($input == Py_None) + $1 = $2 = NULL; + else + { + if (! PyTuple_Check($input)) + return PyErr_Format(PyExc_TypeError, "callback must be a tuple"); + if (PyTuple_Size($input) != 2) + return PyErr_Format(PyExc_TypeError, + "callback must be a tuple of size 2"); + if (! PyCallable_Check(PyTuple_GetItem($input, 1))) + return PyErr_Format(PyExc_TypeError, "second item must be callable"); + $1 = _pyme_assuan_inquire_cb; + $2 = $input; + } +} + +%typemap(in) (gpgme_assuan_status_cb_t stat_cb, void *stat_cb_value) { + if ($input == Py_None) + $1 = $2 = NULL; + else + { + if (! PyTuple_Check($input)) + return PyErr_Format(PyExc_TypeError, "callback must be a tuple"); + if (PyTuple_Size($input) != 2) + return PyErr_Format(PyExc_TypeError, + "callback must be a tuple of size 2"); + if (! PyCallable_Check(PyTuple_GetItem($input, 1))) + return PyErr_Format(PyExc_TypeError, "second item must be callable"); + $1 = _pyme_assuan_status_cb; + $2 = $input; + } +} + /* Include the unmodified for cc, and the cleaned-up local version for SWIG. We do, however, want to hide certain fields on some structs, which we provide prior to including the version for -- cgit v1.2.3