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