python: Return public keys by default.
authorJustus Winter <justus@g10code.com>
Thu, 13 Oct 2016 10:05:59 +0000 (12:05 +0200)
committerJustus Winter <justus@g10code.com>
Thu, 13 Oct 2016 11:19:47 +0000 (13:19 +0200)
* lang/python/pyme/core.py (Core.get_key): Return public keys by
default, improve docstring.
* lang/python/examples/testCMSgetkey.py: Update example.
* lang/python/examples/verifydetails.py: Likewise.

GnuPG-bug-id: 2751
Signed-off-by: Justus Winter <justus@g10code.com>
lang/python/examples/testCMSgetkey.py
lang/python/examples/verifydetails.py
lang/python/pyme/core.py

index 4467b6c..62c35d2 100644 (file)
@@ -28,7 +28,7 @@ if len(sys.argv) != 2:
     sys.exit("fingerprint or unique key ID for gpgme_get_key()")
 
 with pyme.Context(protocol=pyme.constants.PROTOCOL_CMS) as c:
-    key = c.get_key(sys.argv[1], False)
+    key = c.get_key(sys.argv[1])
 
     print("got key: ", key.subkeys[0].fpr)
     for uid in key.uids:
index fa34926..81f82e9 100755 (executable)
@@ -52,7 +52,7 @@ def verifyprintdetails(filename, detached_sig_filename=None):
             print("  status:      %#0x" % (sign.status))
             print("  timestamp:  ", sign.timestamp)
             print("  fingerprint:", sign.fpr)
-            print("  uid:        ", c.get_key(sign.fpr, 0).uids[0].uid)
+            print("  uid:        ", c.get_key(sign.fpr).uids[0].uid)
 
     # Print "unsigned" text if inline signature
     if data:
index 88a086b..cd5217f 100644 (file)
@@ -670,15 +670,26 @@ class Context(GpgmeWrapper):
             key.__del__ = lambda self: gpgme.gpgme_key_unref(self)
             return key
 
-    def get_key(self, fpr, secret):
-        """Return the key corresponding to the fingerprint 'fpr'"""
+    def get_key(self, fpr, secret=False):
+        """Get a key given a fingerprint
+
+        Keyword arguments:
+        secret         -- to request a secret key
+
+        Returns:
+                        -- the matching key
+
+        Raises:
+        GPGMEError     -- as signaled by the underlying library
+
+        """
         ptr = gpgme.new_gpgme_key_t_p()
         errorcheck(gpgme.gpgme_get_key(self.wrapped, fpr, ptr, secret))
         key = gpgme.gpgme_key_t_p_value(ptr)
         gpgme.delete_gpgme_key_t_p(ptr)
-        if key:
-            key.__del__ = lambda self: gpgme.gpgme_key_unref(self)
-            return key
+        assert key
+        key.__del__ = lambda self: gpgme.gpgme_key_unref(self)
+        return key
 
     def op_trustlist_all(self, *args, **kwargs):
         self.op_trustlist_start(*args, **kwargs)