[Pkg-gnupg-commit] [gpgme] 159/412: python: Move helper function.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:26:38 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit 26c3accc95ab77ddbe60db822e2938ad5f480d41
Author: Justus Winter <justus at g10code.com>
Date:   Thu Jun 2 17:14:53 2016 +0200

    python: Move helper function.
    
    * lang/python/gpgme.i (object_to_gpgme_t): Move...
    * lang/python/helpers.c: ... here.
    * lang/python/helpers.h (object_to_gpgme_t): New prototype.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 lang/python/gpgme.i   | 31 -------------------------------
 lang/python/helpers.c | 36 ++++++++++++++++++++++++++++++++++++
 lang/python/helpers.h |  2 ++
 3 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index 0d1322c..e3c761d 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -79,37 +79,6 @@
 %typemap(newfree) char * "free($1);";
 %newobject gpgme_data_release_and_get_mem;
 
-%{
-/* Convert object to a pointer to gpgme type */
-PyObject* object_to_gpgme_t(PyObject* input, const char* objtype, int argnum) {
-  PyObject *pyname = NULL, *pypointer = NULL;
-  pyname = PyObject_CallMethod(input, "_getctype", NULL);
-  if (pyname && PyUnicode_Check(pyname))
-    {
-      if (strcmp(PyUnicode_AsUTF8(pyname), objtype) != 0)
-        {
-          PyErr_Format(PyExc_TypeError,
-                       "arg %d: Expected value of type %s, but got %s",
-                       argnum, objtype, PyUnicode_AsUTF8(pyname));
-          Py_DECREF(pyname);
-          return NULL;
-        }
-    }
-  else
-    return NULL;
-
-  Py_DECREF(pyname);
-  pypointer = PyObject_GetAttrString(input, "wrapped");
-  if (pypointer == NULL) {
-    PyErr_Format(PyExc_TypeError,
-		 "arg %d: Use of uninitialized Python object %s",
-		 argnum, objtype);
-    return NULL;
-  }
-  return pypointer;
-}
-%}
-
 %typemap(arginit) gpgme_key_t [] {
   $1 = NULL;
 }
diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 4b6ac31..3ecbacc 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -146,7 +146,43 @@ PyObject *pygpgme_raise_callback_exception(PyObject *self)
   return Py_None;
 }
 #undef EXCINFO
+

+/* Argument conversion.  */
+
+/* Convert object to a pointer to gpgme type, generic version.  */
+PyObject *
+object_to_gpgme_t(PyObject *input, const char *objtype, int argnum)
+{
+  PyObject *pyname = NULL, *pypointer = NULL;
+  pyname = PyObject_CallMethod(input, "_getctype", NULL);
+  if (pyname && PyUnicode_Check(pyname))
+    {
+      if (strcmp(PyUnicode_AsUTF8(pyname), objtype) != 0)
+        {
+          PyErr_Format(PyExc_TypeError,
+                       "arg %d: Expected value of type %s, but got %s",
+                       argnum, objtype, PyUnicode_AsUTF8(pyname));
+          Py_DECREF(pyname);
+          return NULL;
+        }
+    }
+  else
+    return NULL;
+
+  Py_DECREF(pyname);
+  pypointer = PyObject_GetAttrString(input, "wrapped");
+  if (pypointer == NULL) {
+    PyErr_Format(PyExc_TypeError,
+		 "arg %d: Use of uninitialized Python object %s",
+		 argnum, objtype);
+    return NULL;
+  }
+  return pypointer;
+}
+
+

 
+/* Callback support.  */
 static gpgme_error_t pyPassphraseCb(void *hook,
 				    const char *uid_hint,
 				    const char *passphrase_info,
diff --git a/lang/python/helpers.h b/lang/python/helpers.h
index 1bfcaa6..952b31f 100644
--- a/lang/python/helpers.h
+++ b/lang/python/helpers.h
@@ -28,6 +28,8 @@
 void pygpgme_exception_init(void);
 gpgme_error_t pygpgme_exception2code(void);
 
+PyObject *object_to_gpgme_t(PyObject *input, const char *objtype, int argnum);
+
 void pygpgme_clear_generic_cb(PyObject **cb);
 PyObject *pygpgme_raise_callback_exception(PyObject *self);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list