[gnome-keysign: 70/75] tests: gpgmeh: Make it compatible with gpgme 1.8 and gpgme 1.9



commit 8454ce99313e92ce5c298ea466026e6ba323b6bd
Author: Tobias Mueller <muelli cryptobitch de>
Date:   Fri Sep 22 13:51:59 2017 +0200

    tests: gpgmeh: Make it compatible with gpgme 1.8 and gpgme 1.9
    
    It seems that newer versions of the gpgme python bindings set the mode
    when calling keylist().  This is nice, but is not possible to do in 1.8.
    1.9 also overwrites whatever you set before with set_keylist_mode.
    We now try to be compatible with both.
    Eventually, once we can safely ignore gpgme 1.8, we can get rid of the
    compatibility.
    Currently, Fedora ships gpgme 1.8.

 tests/test_gpgmeh.py | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/tests/test_gpgmeh.py b/tests/test_gpgmeh.py
index 9e9697c..712afb2 100644
--- a/tests/test_gpgmeh.py
+++ b/tests/test_gpgmeh.py
@@ -383,9 +383,20 @@ def get_signatures_for_uids_on_key(ctx, key):
     # What happens if keylist returns multiple keys, e.g. because there
     # is another key with a UID named as the fpr?  How can I make sure I
     # get the signatures of any given key?
-    ctx.set_keylist_mode(gpg.constants.keylist.mode.LOCAL
-                         | gpg.constants.keylist.mode.SIGS)
-    keys = list(ctx.keylist(key.fpr))
+    
+    # *sigh* gpgme is killing me. With gpgme 1.8 we have to
+    # set_keylist_mode before we can call keylist.  With gpgme 1.9
+    # keylist takes a mode argument and overrides whatever has been
+    # set before.  In order to come with something compatible with both
+    # 1.8 and 1.9 we have to set_keylist_mode and NOT call ctx.keylist
+    # but rather the bare op_keylist_all.  In 1.8 that requires two
+    # arguments.
+    mode = gpg.constants.keylist.mode.LOCAL | gpg.constants.keylist.mode.SIGS
+    secret = False
+    ctx.set_keylist_mode(mode)
+    keys = list(ctx.op_keylist_all(key.fpr, secret))
+    # With gpgme 1.9 we can simply do:
+    # keys = list(ctx.keylist(key.fpr), mode=mode)
     assert len(keys) == 1
     uid_sigs = {uid.uid: [s for s in uid.signatures] for uid in keys[0].uids}
     log.info("Signatures: %r", uid_sigs)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]