From 7faef33d13fa8efce152ca7aa6e9d39030c1cf08 Mon Sep 17 00:00:00 2001 From: Ben McGinnes Date: Thu, 28 Jun 2018 00:57:37 +1000 Subject: [PATCH] python bindings: export public keys * Updated key_export and key_export_minimal to return None where a pattern matched no keys in a manner simnilar to the possible result of key_export_secret. --- lang/python/src/core.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lang/python/src/core.py b/lang/python/src/core.py index 86a62b51..d7db7de8 100644 --- a/lang/python/src/core.py +++ b/lang/python/src/core.py @@ -578,7 +578,8 @@ class Context(GpgmeWrapper): Returns: -- A key block containing one or more OpenPGP keys in either ASCII armoured or binary format as determined - by the Context(). + by the Context(). If there are no matching keys it + returns None. Raises: GPGMEError -- as signaled by the underlying library. @@ -588,9 +589,14 @@ class Context(GpgmeWrapper): try: self.op_export(pattern, mode, data) data.seek(0, os.SEEK_SET) - result = data.read() + pk_result = data.read() except GPGMEError as e: - result = e + pk_result = e + + if len(pk_result) > 0: + result = pk_result + else: + result = None return result @@ -607,7 +613,8 @@ class Context(GpgmeWrapper): Returns: -- A key block containing one or more minimised OpenPGP keys in either ASCII armoured or binary format as - determined by the Context(). + determined by the Context(). If there are no matching + keys it returns None. Raises: GPGMEError -- as signaled by the underlying library. @@ -617,9 +624,14 @@ class Context(GpgmeWrapper): try: self.op_export(pattern, mode, data) data.seek(0, os.SEEK_SET) - result = data.read() + pk_result = data.read() except GPGMEError as e: - result = e + pk_result = e + + if len(pk_result) > 0: + result = pk_result + else: + result = None return result