Update NEWS, README for 0.80.0
[dbus-python-phuang.git] / _dbus_bindings / exceptions.c
blobefa3df26ff04f8ea6de269a06d38af787d46ecc9
1 /* D-Bus exception base classes.
3 * Copyright (C) 2006 Collabora Ltd.
5 * Licensed under the Academic Free License version 2.1
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "dbus_bindings-internal.h"
27 PyObject *DBusPyException;
29 PyDoc_STRVAR(DBusException__doc__, "Represents any D-Bus-related error.");
31 PyObject *
32 DBusPyException_ConsumeError(DBusError *error)
34 PyErr_Format(DBusPyException, "%s: %s",
35 error->name, error->message);
36 dbus_error_free(error);
37 return NULL;
40 dbus_bool_t
41 dbus_py_init_exception_types(void)
43 PyObject *bases;
44 PyObject *dict = PyDict_New();
45 PyObject *name;
47 if (!dict)
48 return 0;
49 if (PyDict_SetItemString(dict, "__doc__",
50 PyString_FromString(DBusException__doc__)) < 0)
51 return 0;
52 if (PyDict_SetItemString(dict, "__module__",
53 PyString_FromString("dbus")) < 0)
54 return 0;
55 bases = Py_BuildValue("(O)", (PyObject *)PyExc_Exception);
56 if (!bases) {
57 Py_DECREF(dict);
58 return 0;
60 name = PyString_FromString("DBusException");
61 if (!name) {
62 Py_DECREF(dict);
63 Py_DECREF(bases);
64 return 0;
66 DBusPyException = PyClass_New(bases, dict, name);
67 Py_DECREF(bases);
68 Py_DECREF(dict);
69 if (!DBusPyException)
70 return 0;
71 return 1;
74 dbus_bool_t
75 dbus_py_insert_exception_types(PyObject *this_module)
77 if (PyModule_AddObject(this_module, "DBusException", DBusPyException) < 0) {
78 return 0;
80 return 1;
83 /* vim:set ft=c cino< sw=4 sts=4 et: */