python: Improve error handling.

* lang/python/pyme/core.py (Context.protocol): Check that the engine
is usable before setting the protocol.
(Context._errorcheck): Add missing functions.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2016-07-28 17:44:18 +02:00
parent b9e6eacd06
commit 5a7c7a86f7

View File

@ -546,6 +546,7 @@ class Context(GpgmeWrapper):
return self.get_protocol() return self.get_protocol()
@protocol.setter @protocol.setter
def protocol(self, value): def protocol(self, value):
errorcheck(gpgme.gpgme_engine_check_version(value))
self.set_protocol(value) self.set_protocol(value)
_ctype = 'gpgme_ctx_t' _ctype = 'gpgme_ctx_t'
@ -553,14 +554,23 @@ class Context(GpgmeWrapper):
def _errorcheck(self, name): def _errorcheck(self, name):
"""This function should list all functions returning gpgme_error_t""" """This function should list all functions returning gpgme_error_t"""
if (name.startswith('gpgme_op_') and \ return ((name.startswith('gpgme_op_')
not name.endswith('_result')) or \ and not name.endswith('_result'))
name == 'gpgme_signers_add' or \ or name in {
name == 'gpgme_set_locale' or \ 'gpgme_set_ctx_flag',
name == 'gpgme_set_keylist_mode' or \ 'gpgme_set_protocol',
name == 'gpgme_set_protocol': 'gpgme_set_sub_protocol',
return 1 'gpgme_set_keylist_mode',
return 0 'gpgme_set_pinentry_mode',
'gpgme_set_locale',
'gpgme_set_engine_info',
'gpgme_signers_add',
'gpgme_get_sig_key',
'gpgme_sig_notation_add',
'gpgme_cancel',
'gpgme_cancel_async',
'gpgme_cancel_get_key',
})
_boolean_properties = {'armor', 'textmode', 'offline'} _boolean_properties = {'armor', 'textmode', 'offline'}