[git] GPGME - branch, master, updated. gpgme-1.7.0-50-gf526d0e
by Justus Winter
cvs at cvs.gnupg.org
Thu Oct 13 13:22:24 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 f526d0e22e8b881ccbca66b46a0e1b68bbc4cd6b (commit)
via 1e6073ffa98db2c265adbcf0dbbe70c067a910f0 (commit)
via cabd4c74e52c8983d624b6877cddc7f8912eff04 (commit)
from 56302e7bb6a694a7c570f389f9a7883efdfdaf42 (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 f526d0e22e8b881ccbca66b46a0e1b68bbc4cd6b
Author: Justus Winter <justus at g10code.com>
Date: Thu Oct 13 13:13:23 2016 +0200
python: Make 'get_key' more idiomatic.
* lang/python/pyme/core.py (Context.get_key): Raise errors.KeyNotFound
if the key is not found. This error is both a KeyError for idiomatic
error handling as well as a GPGMEError so we don't break existing
code.
* lang/python/pyme/errors.py (KeyNotFound): New class.
* lang/python/tests/support.py (no_such_key): New variable.
* lang/python/tests/t-keylist.py: Test the new behavior.
Signed-off-by: Justus Winter <justus at g10code.com>
diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py
index cd5217f..f0eab43 100644
--- a/lang/python/pyme/core.py
+++ b/lang/python/pyme/core.py
@@ -680,11 +680,19 @@ class Context(GpgmeWrapper):
-- the matching key
Raises:
+ KeyError -- if the key was not found
GPGMEError -- as signaled by the underlying library
"""
ptr = gpgme.new_gpgme_key_t_p()
- errorcheck(gpgme.gpgme_get_key(self.wrapped, fpr, ptr, secret))
+
+ try:
+ errorcheck(gpgme.gpgme_get_key(self.wrapped, fpr, ptr, secret))
+ except errors.GPGMEError as e:
+ if e.getcode() == errors.EOF:
+ raise errors.KeyNotFound(fpr)
+ raise e
+
key = gpgme.gpgme_key_t_p_value(ptr)
gpgme.delete_gpgme_key_t_p(ptr)
assert key
diff --git a/lang/python/pyme/errors.py b/lang/python/pyme/errors.py
index e26c747..0fd85ef 100644
--- a/lang/python/pyme/errors.py
+++ b/lang/python/pyme/errors.py
@@ -21,10 +21,12 @@ del absolute_import, print_function, unicode_literals
from . import gpgme
from . import util
-util.process_constants('GPG_ERR_', globals())
+# To appease static analysis tools, we define some constants here.
+# They are overwritten with the proper values by process_constants.
+NO_ERROR = None
+EOF = None
-# To appease static analysis tools, we define some constants here:
-NO_ERROR = 0
+util.process_constants('GPG_ERR_', globals())
class PymeError(Exception):
pass
@@ -58,6 +60,20 @@ def errorcheck(retval, extradata = None):
if retval:
raise GPGMEError(retval, extradata)
+class KeyNotFound(GPGMEError, KeyError):
+ """Raised if a key was not found
+
+ GPGME indicates this condition with EOF, which is not very
+ idiomatic. We raise this error that is both a GPGMEError
+ indicating EOF, and a KeyError.
+
+ """
+ def __init__(self, keystr):
+ self.keystr = keystr
+ GPGMEError.__init__(self, EOF)
+ def __str__(self):
+ return self.keystr
+
# These errors are raised in the idiomatic interface code.
class EncryptionError(PymeError):
diff --git a/lang/python/tests/support.py b/lang/python/tests/support.py
index 4d7135e..f1ffdc3 100644
--- a/lang/python/tests/support.py
+++ b/lang/python/tests/support.py
@@ -27,6 +27,7 @@ alpha = "A0FF4590BB6122EDEF6E3C542D727CC768697734"
bob = "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2"
encrypt_only = "F52770D5C4DB41408D918C9F920572769B9FE19C"
sign_only = "7CCA20CCDE5394CEE71C9F0BFED153F12F18F45D"
+no_such_key = "A" * 40
def make_filename(name):
return os.path.join(os.environ['top_srcdir'], 'tests', 'gpg', name)
diff --git a/lang/python/tests/t-keylist.py b/lang/python/tests/t-keylist.py
index 5e8b333..f7f6674 100755
--- a/lang/python/tests/t-keylist.py
+++ b/lang/python/tests/t-keylist.py
@@ -20,6 +20,7 @@
from __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
+import pyme
from pyme import core, constants
import support
@@ -244,3 +245,25 @@ for i, key in enumerate(c.keylist()):
if misc_check:
misc_check (uids[0][0], key)
+
+
+# check get_key()
+with pyme.Context() as c:
+ c.get_key(support.alpha)
+ c.get_key(support.alpha, secret=True)
+
+ c.get_key(support.bob)
+ try:
+ c.get_key(support.bob, secret=True)
+ except KeyError:
+ pass
+ else:
+ assert False, "Expected KeyError"
+
+ # Legacy error
+ try:
+ c.get_key(support.no_such_key)
+ except pyme.errors.GPGMEError:
+ pass
+ else:
+ assert False, "Expected GPGMEError"
commit 1e6073ffa98db2c265adbcf0dbbe70c067a910f0
Author: Justus Winter <justus at g10code.com>
Date: Thu Oct 13 12:05:59 2016 +0200
python: Return public keys by default.
* 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 at g10code.com>
diff --git a/lang/python/examples/testCMSgetkey.py b/lang/python/examples/testCMSgetkey.py
index 4467b6c..62c35d2 100644
--- a/lang/python/examples/testCMSgetkey.py
+++ b/lang/python/examples/testCMSgetkey.py
@@ -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:
diff --git a/lang/python/examples/verifydetails.py b/lang/python/examples/verifydetails.py
index fa34926..81f82e9 100755
--- a/lang/python/examples/verifydetails.py
+++ b/lang/python/examples/verifydetails.py
@@ -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:
diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py
index 88a086b..cd5217f 100644
--- a/lang/python/pyme/core.py
+++ b/lang/python/pyme/core.py
@@ -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)
commit cabd4c74e52c8983d624b6877cddc7f8912eff04
Author: Justus Winter <justus at g10code.com>
Date: Thu Oct 13 12:45:50 2016 +0200
python: Fix example.
* lang/python/examples/inter-edit.py: Fix example.
Fixes-commit: a458e7fe
Signed-off-by: Justus Winter <justus at g10code.com>
diff --git a/lang/python/examples/inter-edit.py b/lang/python/examples/inter-edit.py
index 39d6f17..3c0f29b 100644
--- a/lang/python/examples/inter-edit.py
+++ b/lang/python/examples/inter-edit.py
@@ -40,8 +40,8 @@ with pyme.Context() as c:
print("Editing key {} ({}):".format(key.uids[0].uid, key.subkeys[0].fpr))
def edit_fnc(keyword, args):
- print("Status: {} ({}), args: {} > ".format(
- keyword, status, args), end='', flush=True)
+ print("Status: {}, args: {} > ".format(
+ keyword, args), end='', flush=True)
if not 'GET' in keyword:
# no prompt
-----------------------------------------------------------------------
Summary of changes:
lang/python/examples/inter-edit.py | 4 ++--
lang/python/examples/testCMSgetkey.py | 2 +-
lang/python/examples/verifydetails.py | 2 +-
lang/python/pyme/core.py | 31 +++++++++++++++++++++++++------
lang/python/pyme/errors.py | 22 +++++++++++++++++++---
lang/python/tests/support.py | 1 +
lang/python/tests/t-keylist.py | 23 +++++++++++++++++++++++
7 files changed, 72 insertions(+), 13 deletions(-)
hooks/post-receive
--
GnuPG Made Easy
http://git.gnupg.org
More information about the Gnupg-commits
mailing list