Line data Source code
1 : /*
2 : Authors:
3 : Jakub Hrozek <jhrozek@redhat.com>
4 :
5 : Copyright (C) 2011 Red Hat
6 :
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 : the Free Software Foundation; either version 3 of the License, or
10 : (at your option) any later version.
11 :
12 : This program 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 General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with this program. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include "src/util/sss_python.h"
22 : #include "config.h"
23 :
24 : PyObject *
25 2 : sss_exception_with_doc(char *name, char *doc, PyObject *base, PyObject *dict)
26 : {
27 : #ifdef HAVE_PYERR_NEWEXCEPTIONWITHDOC
28 2 : return PyErr_NewExceptionWithDoc(name, doc, base, dict);
29 : #else
30 : int result;
31 : PyObject *ret = NULL;
32 : PyObject *mydict = NULL; /* points to the dict only if we create it */
33 : PyObject *docobj;
34 :
35 : if (dict == NULL) {
36 : dict = mydict = PyDict_New();
37 : if (dict == NULL) {
38 : return NULL;
39 : }
40 : }
41 :
42 : if (doc != NULL) {
43 : docobj = PyString_FromString(doc);
44 : if (docobj == NULL)
45 : goto failure;
46 : result = PyDict_SetItemString(dict, "__doc__", docobj);
47 : Py_DECREF(docobj);
48 : if (result < 0)
49 : goto failure;
50 : }
51 :
52 : ret = PyErr_NewException(name, base, dict);
53 : failure:
54 : Py_XDECREF(mydict);
55 : return ret;
56 : #endif
57 : }
|