python: Add function to raise exceptions from c.
* lang/python/helpers.c (pygpgme_raise_exception): New function. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
8426304b67
commit
5ebc205439
@ -1,4 +1,5 @@
|
||||
/*
|
||||
# Copyright (C) 2016 g10 Code GmbH
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
@ -41,6 +42,25 @@ void pygpgme_exception_init(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
pygpgme_raise_exception(gpgme_error_t err)
|
||||
{
|
||||
PyObject *e;
|
||||
|
||||
pygpgme_exception_init();
|
||||
if (GPGMEError == NULL)
|
||||
return PyErr_Format(PyExc_RuntimeError, "Got gpgme_error_t %d", err);
|
||||
|
||||
e = PyObject_CallFunction(GPGMEError, "l", (long) err);
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
|
||||
PyErr_SetObject(GPGMEError, e);
|
||||
Py_DECREF(e);
|
||||
|
||||
return NULL; /* raise */
|
||||
}
|
||||
|
||||
gpgme_error_t pygpgme_exception2code(void) {
|
||||
gpgme_error_t err_status = gpg_error(GPG_ERR_GENERAL);
|
||||
if (GPGMEError && PyErr_ExceptionMatches(GPGMEError)) {
|
||||
|
Loading…
Reference in New Issue
Block a user