[git] GPGME - branch, master, updated. gpgme-1.8.0-9-g05896c2

by Tobias Mueller cvs at cvs.gnupg.org
Mon Dec 5 12:58:43 CET 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  05896c210f7fa9ce7b97784a75e49dc4489e9252 (commit)
       via  fb7f4cb973abc9f5eb05eb240607be35c1be986c (commit)
      from  ae21d2705fc46725e1f9af1651b68d16155d1501 (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 05896c210f7fa9ce7b97784a75e49dc4489e9252
Author: Tobias Mueller <muelli at cryptobitch.de>
Date:   Fri Dec 2 23:37:27 2016 +0100

    python: Try to be more helpful when given a string to encrypt().
    
    * lang/python/helpers.c (_gpg_obj2gpgme_data_t): Extended error
    message.
    * lang/python/tests/t-encrypt.py: Test for "encode" in error message.
    --
    The motivation is to help the user when encrypting fails. I claim that
    it is not obvious to not being able to encrypt a string directly.  To
    nudge the user into encoding it to bytes, the error message is a bit
    extended.
    
    Signed-off-by: Tobias Mueller <muelli at cryptobitch.de>

diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 8f71a30..576767c 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -293,8 +293,10 @@ _gpg_obj2gpgme_data_t(PyObject *input, int argnum, gpgme_data_t *wrapper,
     return _gpg_obj2gpgme_t(data, "gpgme_data_t", argnum);
 
   return PyErr_Format(PyExc_TypeError,
-                      "arg %d: expected gpg.Data, file, or an object "
-                      "implementing the buffer protocol, got %s",
+                      "arg %d: expected gpg.Data, file, "
+                      "bytes (not string!), or an object "
+                      "implementing the buffer protocol. Got: %s. "
+                      "If you provided a string, try to encode() it.",
                       argnum, data->ob_type->tp_name);
 }
 
diff --git a/lang/python/tests/t-encrypt.py b/lang/python/tests/t-encrypt.py
index 0c0ca35..3cbe8f2 100755
--- a/lang/python/tests/t-encrypt.py
+++ b/lang/python/tests/t-encrypt.py
@@ -62,3 +62,18 @@ with gpg.Context(armor=True) as c:
         assert support.sign_only.endswith(e.recipients[0].fpr)
     else:
         assert False, "Expected an InvalidRecipients error, got none"
+
+
+
+    try:
+        # People might be tempted to provide strings.
+        # We should raise something useful.
+        ciphertext, _, _ = c.encrypt("Hallo Leute\n",
+                                     recipients=keys,
+                                     sign=False,
+                                     always_trust=True)
+    except TypeError as e:
+        # This test is a bit fragile, because the message
+        # may very well change. So if the behaviour will change
+        # this test can easily be deleted.
+        assert "encode" in str(e)

commit fb7f4cb973abc9f5eb05eb240607be35c1be986c
Author: Tobias Mueller <muelli at cryptobitch.de>
Date:   Thu Dec 1 21:15:12 2016 +0100

    python: Define a macro for wrapping fragile result objects.
    
    * lang/python/gpgme.i (wrapresult): New Macro.
    --
    
    This reduces the amount of copy and pasted code at the expense of a
    slightly more complicated logic with a macro.
    
    Signed-off-by: Tobias Mueller <muelli at cryptobitch.de>

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index 783531f..73533d0 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -424,69 +424,24 @@
 

 
 /* Wrap the fragile result objects into robust Python ones.  */
-%typemap(out) gpgme_encrypt_result_t {
+%define wrapresult(cls, name)
+%typemap(out) cls {
   PyObject *fragile;
   fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
                                %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "EncryptResult");
+  $result = _gpg_wrap_result(fragile, name);
   Py_DECREF(fragile);
 }
+%enddef
 
-%typemap(out) gpgme_decrypt_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "DecryptResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_sign_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "SignResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_verify_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "VerifyResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_import_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "ImportResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_genkey_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "GenkeyResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_keylist_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "KeylistResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_vfs_mount_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "VFSMountResult");
-  Py_DECREF(fragile);
-}
+wrapresult(gpgme_encrypt_result_t, "EncryptResult")
+wrapresult(gpgme_decrypt_result_t, "DecryptResult")
+wrapresult(gpgme_sign_result_t, "SignResult")
+wrapresult(gpgme_verify_result_t, "VerifyResult")
+wrapresult(gpgme_import_result_t, "ImportResult")
+wrapresult(gpgme_genkey_result_t, "GenkeyResult")
+wrapresult(gpgme_keylist_result_t, "KeylistResult")
+wrapresult(gpgme_vfs_mount_result_t, "VFSMountResult")
 
 %typemap(out) gpgme_engine_info_t {
   int i;

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

Summary of changes:
 lang/python/gpgme.i            | 69 ++++++++----------------------------------
 lang/python/helpers.c          |  6 ++--
 lang/python/tests/t-encrypt.py | 15 +++++++++
 3 files changed, 31 insertions(+), 59 deletions(-)


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




More information about the Gnupg-commits mailing list