[Pkg-gnupg-commit] [gpgme] 165/412: python: Add function to raise exceptions from c.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Thu Sep 22 21:26:39 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gpgme.
commit 5ebc205439cac266685d2532466df8b3457dea23
Author: Justus Winter <justus at g10code.com>
Date: Wed Jun 8 17:54:45 2016 +0200
python: Add function to raise exceptions from c.
* lang/python/helpers.c (pygpgme_raise_exception): New function.
Signed-off-by: Justus Winter <justus at g10code.com>
---
lang/python/helpers.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 7e1c1c3..5c620e6 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -1,4 +1,5 @@
/*
+# Copyright (C) 2016 g10 Code GmbH
# Copyright (C) 2004 Igor Belyi <belyi at users.sourceforge.net>
# Copyright (C) 2002 John Goerzen <jgoerzen at 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)) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git
More information about the Pkg-gnupg-commit
mailing list