[git] GPGME - branch, master, updated. gpgme-1.6.0-337-gc0c5031

by Justus Winter cvs at cvs.gnupg.org
Mon Sep 12 17:28:17 CEST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, master has been updated
       via  c0c50318bd8ef6c8119ad9fdc53ad9087ded4c32 (commit)
       via  1d5bbbf1185a0d1f82750f10b69dad3999f7ef4c (commit)
       via  70999d81618b3d3ae6b61a43be2ce703ad284275 (commit)
       via  b48b852a846129914d6c63ec7b47388cdcf6acca (commit)
      from  dfd99ab50c3bc1d6745b6f682791e4885e8d8a9a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c0c50318bd8ef6c8119ad9fdc53ad9087ded4c32
Author: Justus Winter <justus at g10code.com>
Date:   Mon Sep 12 17:21:34 2016 +0200

    python: Avoid Python3-only form of super().
    
    * lang/python/pyme/core.py (GpgmeWrapper.__repr__): Use more
    compatible form of super.
    (GpgmeWrapper.__setattr__): Likewise.
    (Context.__init__): Likewise.
    (Data.__init__): Likewise.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py
index f9df6e8..4bbbc17 100644
--- a/lang/python/pyme/core.py
+++ b/lang/python/pyme/core.py
@@ -45,7 +45,8 @@ class GpgmeWrapper(object):
         self.wrapped = wrapped
 
     def __repr__(self):
-        return '<{}/{!r}>'.format(super().__repr__(), self.wrapped)
+        return '<{}/{!r}>'.format(super(GpgmeWrapper, self).__repr__(),
+                                  self.wrapped)
 
     def __str__(self):
         acc = ['{}.{}'.format(__name__, self.__class__.__name__)]
@@ -153,7 +154,7 @@ class GpgmeWrapper(object):
         if key in self._boolean_properties:
             self.__wrap_boolean_property(key, True, value)
         else:
-            super().__setattr__(key, value)
+            super(GpgmeWrapper, self).__setattr__(key, value)
 
 class Context(GpgmeWrapper):
     """Context for cryptographic operations
@@ -191,7 +192,7 @@ class Context(GpgmeWrapper):
             wrapped = gpgme.gpgme_ctx_t_p_value(tmp)
             gpgme.delete_gpgme_ctx_t_p(tmp)
             self.own = True
-        super().__init__(wrapped)
+        super(Context, self).__init__(wrapped)
         self.armor = armor
         self.textmode = textmode
         self.offline = offline
@@ -873,7 +874,7 @@ class Data(GpgmeWrapper):
         that file.
 
         """
-        super().__init__(None)
+        super(Data, self).__init__(None)
         self.data_cbs = None
 
         if cbs != None:

commit 1d5bbbf1185a0d1f82750f10b69dad3999f7ef4c
Author: Justus Winter <justus at g10code.com>
Date:   Mon Sep 12 17:11:19 2016 +0200

    python: Make type translation compatible with Python 2.7.
    
    * lang/python/gpgme.i: Avoid functions not available in Python 2.7.
    * lang/python/helpers.c: Likewise.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index dfa3775..bc957e5 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -36,11 +36,16 @@
 
 
 /* Allow use of Unicode objects, bytes, and None for strings.  */
-%typemap(in) const char * {
+%typemap(in) const char *(PyObject *encodedInput = NULL) {
   if ($input == Py_None)
     $1 = NULL;
   else if (PyUnicode_Check($input))
-    $1 = PyUnicode_AsUTF8($input);
+    {
+      encodedInput = PyUnicode_AsUTF8String($input);
+      if (encodedInput == NULL)
+        return NULL;
+      $1 = PyBytes_AsString(encodedInput);
+    }
   else if (PyBytes_Check($input))
     $1 = PyBytes_AsString($input);
   else {
@@ -50,19 +55,35 @@
     return NULL;
   }
 }
-%typemap(freearg) const char * "";
+%typemap(freearg) const char * {
+  Py_XDECREF(encodedInput$argnum);
+}
 
 /* Likewise for a list of strings.  */
-%typemap(in) const char *[] (void *vector = NULL) {
+%typemap(in) const char *[] (void *vector = NULL,
+                             size_t size,
+                             PyObject **pyVector = NULL) {
   /* Check if is a list */
   if (PyList_Check($input)) {
-    size_t i, size = PyList_Size($input);
+    size_t i, j;
+    size = PyList_Size($input);
     $1 = (char **) (vector = malloc((size+1) * sizeof(char *)));
+    pyVector = calloc(sizeof *pyVector, size);
 
     for (i = 0; i < size; i++) {
       PyObject *o = PyList_GetItem($input,i);
       if (PyUnicode_Check(o))
-        $1[i] = PyUnicode_AsUTF8(o);
+        {
+          pyVector[i] = PyUnicode_AsUTF8String(o);
+          if (pyVector[i] == NULL)
+            {
+              free(vector);
+              for (j = 0; j < i; j++)
+                Py_XDECREF(pyVector[j]);
+              return NULL;
+            }
+          $1[i] = PyBytes_AsString(pyVector[i]);
+        }
       else if (PyString_Check(o))
 	$1[i] = PyString_AsString(o);
       else {
@@ -83,7 +104,10 @@
   }
 }
 %typemap(freearg) const char *[] {
+  size_t i;
   free(vector$argnum);
+  for (i = 0; i < size$argnum; i++)
+    Py_XDECREF(pyVector$argnum[i]);
 }
 
 // Release returned buffers as necessary.
@@ -296,13 +320,22 @@
 }
 
 /* For gpgme_data_write, but should be universal.  */
-%typemap(in) (const void *buffer, size_t size) {
+%typemap(in) (const void *buffer, size_t size)(PyObject *encodedInput = NULL) {
   Py_ssize_t ssize;
 
   if ($input == Py_None)
     $1 = NULL, $2 = 0;
   else if (PyUnicode_Check($input))
-    $1 = PyUnicode_AsUTF8AndSize($input, &ssize);
+    {
+      encodedInput = PyUnicode_AsUTF8String($input);
+      if (encodedInput == NULL)
+        return NULL;
+      if (PyBytes_AsStringAndSize(encodedInput, (char **) &$1, &ssize) == -1)
+        {
+          Py_DECREF(encodedInput);
+          return NULL;
+        }
+    }
   else if (PyBytes_Check($input))
     PyBytes_AsStringAndSize($input, (char **) &$1, &ssize);
   else {
@@ -320,7 +353,9 @@
       $2 = (size_t) ssize;
     }
 }
-%typemap(freearg) (const void *buffer, size_t size) "";
+%typemap(freearg) (const void *buffer, size_t size) {
+  Py_XDECREF(encodedInput$argnum);
+}
 
 // Make types containing 'next' field to be lists
 %ignore next;
diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 0b4a773..6e63c97 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -191,14 +191,17 @@ _pyme_obj2gpgme_t(PyObject *input, const char *objtype, int argnum)
   pyname = PyObject_GetAttrString(input, "_ctype");
   if (pyname && PyUnicode_Check(pyname))
     {
-      if (strcmp(PyUnicode_AsUTF8(pyname), objtype) != 0)
+      PyObject *encoded = PyUnicode_AsUTF8String(pyname);
+      if (strcmp(PyBytes_AsString(encoded), objtype) != 0)
         {
           PyErr_Format(PyExc_TypeError,
                        "arg %d: Expected value of type %s, but got %s",
-                       argnum, objtype, PyUnicode_AsUTF8(pyname));
+                       argnum, objtype, PyBytes_AsString(encoded));
+          Py_DECREF(encoded);
           Py_DECREF(pyname);
           return NULL;
         }
+      Py_DECREF(encoded);
     }
   else
     return NULL;
@@ -334,6 +337,7 @@ static gpgme_error_t pyPassphraseCb(void *hook,
   PyObject *args = NULL;
   PyObject *retval = NULL;
   PyObject *dataarg = NULL;
+  PyObject *encoded = NULL;
   gpgme_error_t err_status = 0;
 
   _pyme_exception_init();
@@ -388,7 +392,17 @@ static gpgme_error_t pyPassphraseCb(void *hook,
       else if (PyUnicode_Check(retval))
         {
           Py_ssize_t ssize;
-          buf = PyUnicode_AsUTF8AndSize(retval, &ssize);
+          encoded = PyUnicode_AsUTF8String(retval);
+          if (encoded == NULL)
+            {
+              err_status = gpg_error(GPG_ERR_GENERAL);
+              goto leave;
+            }
+          if (PyBytes_AsStringAndSize(encoded, &buf, &ssize) == -1)
+            {
+              err_status = gpg_error(GPG_ERR_GENERAL);
+              goto leave;
+            }
           assert (! buf || ssize >= 0);
           len = (size_t) ssize;
         }
@@ -418,6 +432,7 @@ static gpgme_error_t pyPassphraseCb(void *hook,
   if (err_status)
     _pyme_stash_callback_exception(self);
 
+  Py_XDECREF(encoded);
   return err_status;
 }
 
@@ -676,10 +691,23 @@ gpgme_error_t _pyme_edit_cb(void *opaque, gpgme_status_code_t status,
     err_status = _pyme_exception2code();
   } else {
     if (fd>=0 && retval && PyUnicode_Check(retval)) {
+      PyObject *encoded = NULL;
       const char *buffer;
       Py_ssize_t size;
 
-      buffer = PyUnicode_AsUTF8AndSize(retval, &size);
+      encoded = PyUnicode_AsUTF8String(retval);
+      if (encoded == NULL)
+        {
+          err_status = gpg_error(GPG_ERR_GENERAL);
+          goto leave;
+        }
+      if (PyBytes_AsStringAndSize(encoded, &buffer, &size) == -1)
+        {
+          Py_DECREF(encoded);
+          err_status = gpg_error(GPG_ERR_GENERAL);
+          goto leave;
+        }
+
       if (write(fd, buffer, size) < 0) {
         err_status = gpgme_error_from_syserror ();
         _pyme_raise_exception (err_status);
@@ -688,8 +716,10 @@ gpgme_error_t _pyme_edit_cb(void *opaque, gpgme_status_code_t status,
         err_status = gpgme_error_from_syserror ();
         _pyme_raise_exception (err_status);
       }
+      Py_DECREF(encoded);
     }
   }
+ leave:
   if (err_status)
     _pyme_stash_callback_exception(self);
 

commit 70999d81618b3d3ae6b61a43be2ce703ad284275
Author: Justus Winter <justus at g10code.com>
Date:   Mon Sep 12 16:19:07 2016 +0200

    python: Avoid hardcoding the interpreter.
    
    * lang/python/setup.py.in: Avoid hardcoding the interpreter.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/lang/python/setup.py.in b/lang/python/setup.py.in
index 4477e09..22035cb 100755
--- a/lang/python/setup.py.in
+++ b/lang/python/setup.py.in
@@ -88,9 +88,9 @@ if not os.path.exists(gpg_error_h):
 print("Building pyme3 using {} and {}.".format(gpgme_h, gpg_error_h))
 
 # Cleanup gpgme.h from deprecated functions and typedefs.
-subprocess.check_call(["python3", "gpgme-h-clean.py", gpgme_h],
+subprocess.check_call([sys.executable, "gpgme-h-clean.py", gpgme_h],
                       stdout=open("gpgme.h", "w"))
-subprocess.check_call(["python3", "gpgme-h-clean.py", gpg_error_h],
+subprocess.check_call([sys.executable, "gpgme-h-clean.py", gpg_error_h],
                       stdout=open("errors.i", "w"))
 
 include_dirs = [os.getcwd()]

commit b48b852a846129914d6c63ec7b47388cdcf6acca
Author: Justus Winter <justus at g10code.com>
Date:   Mon Sep 12 16:18:31 2016 +0200

    python: Do not rely on subprocess.DEVNULL.
    
    * lang/python/setup.py.in: Do not rely on subprocess.DEVNULL.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/lang/python/setup.py.in b/lang/python/setup.py.in
index a524c95..4477e09 100755
--- a/lang/python/setup.py.in
+++ b/lang/python/setup.py.in
@@ -43,16 +43,21 @@ if os.path.exists("../../src/gpgme-config"):
         IN_TREE_BUILD=1,
     )
 
+if hasattr(subprocess, "DEVNULL"):
+    devnull = subprocess.DEVNULL
+else:
+    devnull = open(os.devnull, "w")
+
 try:
     subprocess.check_call([gpg_error_config, '--version'],
-                          stdout=subprocess.DEVNULL)
+                          stdout=devnull)
 except:
     sys.exit("Could not find gpg-error-config.  " +
              "Please install the libgpg-error development package.")
 
 try:
     subprocess.check_call([gpgme_config, '--version'],
-                          stdout=subprocess.DEVNULL)
+                          stdout=devnull)
 except:
     sys.exit("Could not find gpgme-config.  " +
              "Please install the libgpgme development package.")

-----------------------------------------------------------------------

Summary of changes:
 lang/python/gpgme.i      | 53 ++++++++++++++++++++++++++++++++++++++++--------
 lang/python/helpers.c    | 38 ++++++++++++++++++++++++++++++----
 lang/python/pyme/core.py |  9 ++++----
 lang/python/setup.py.in  | 13 ++++++++----
 4 files changed, 92 insertions(+), 21 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list