_dbus_bindings: debug-impl.h -> debug.c
[dbus-python-phuang.git] / _dbus_bindings / exceptions-impl.h
blob690f4020af89ad5dec81b57ad5e44fc08e665a6c
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 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", error->name, error->message);
33 dbus_error_free(error);
34 return NULL;
37 static inline PyObject *
38 DBusException_UnusableMessage(void)
40 PyErr_SetString(DBusPyException,
41 "Message object is uninitialized, or has become unusable "
42 "due to error while appending arguments");
43 return NULL;
46 static inline int
47 init_exception_types(void)
49 PyObject *docstring;
51 /* We call it dbus.DBusException because that's where you should import it
52 from. */
53 DBusPyException = PyErr_NewException("dbus.DBusException", NULL, NULL);
54 if (!DBusPyException) return 0;
55 docstring = PyString_FromString(DBusException__doc__);
56 if (!docstring) return 0;
57 if (PyObject_SetAttrString(DBusPyException, "__doc__", docstring)) return 0;
58 Py_DECREF(docstring);
59 return 1;
62 static inline int
63 insert_exception_types(PyObject *this_module)
65 if (PyModule_AddObject(this_module, "DBusException", DBusPyException) < 0) {
66 return 0;
68 return 1;
71 /* vim:set ft=c cino< sw=4 sts=4 et: */