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 static PyObject
*imported_dbus_exception
= NULL
;
28 import_exception(void)
33 if (imported_dbus_exception
!= NULL
) {
37 name
= PyString_FromString("dbus.exceptions");
41 exceptions
= PyImport_Import(name
);
43 if (exceptions
== NULL
) {
46 imported_dbus_exception
= PyObject_GetAttrString(exceptions
,
48 Py_DECREF(exceptions
);
50 return (imported_dbus_exception
!= NULL
);
54 DBusPyException_SetString(const char *msg
)
56 if (imported_dbus_exception
!= NULL
|| import_exception()) {
57 PyErr_SetString(imported_dbus_exception
, msg
);
63 DBusPyException_ConsumeError(DBusError
*error
)
65 PyObject
*exc_value
= NULL
;
67 if (imported_dbus_exception
== NULL
&& !import_exception()) {
71 exc_value
= PyObject_CallFunction(imported_dbus_exception
,
73 error
->message
? error
->message
76 PyObject
*name
= PyString_FromString(error
->name
);
81 ret
= PyObject_SetAttrString(exc_value
, "_dbus_error_name", name
);
88 PyErr_SetObject(imported_dbus_exception
, exc_value
);
91 Py_XDECREF(exc_value
);
92 dbus_error_free(error
);
96 /* vim:set ft=c cino< sw=4 sts=4 et: */