sss_python.c revision 887edd6b7c53fde44eb9f9060e09db5cd981ba37
259N/A/*
259N/A Authors:
259N/A Jakub Hrozek <jhrozek@redhat.com>
259N/A
259N/A Copyright (C) 2011 Red Hat
259N/A
259N/A This program is free software; you can redistribute it and/or modify
259N/A it under the terms of the GNU General Public License as published by
259N/A the Free Software Foundation; either version 3 of the License, or
259N/A (at your option) any later version.
259N/A
259N/A This program is distributed in the hope that it will be useful,
259N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
259N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
259N/A GNU General Public License for more details.
259N/A
259N/A You should have received a copy of the GNU General Public License
259N/A along with this program. If not, see <http://www.gnu.org/licenses/>.
259N/A*/
259N/A
259N/A#include "src/util/sss_python.h"
259N/A#include "config.h"
259N/A
259N/Abool
259N/Asss_python_set_check(PyObject *set)
259N/A{
259N/A#if HAVE_DECL_PYSET_CHECK
259N/A return PySet_Check(set);
259N/A#else
259N/A return PyObject_TypeCheck(set, &PySet_Type);
259N/A#endif
259N/A}
259N/A
259N/APyObject *
259N/Asss_python_unicode_from_string(const char *u)
259N/A{
259N/A#ifdef HAVE_PYUNICODE_FROMSTRING
259N/A return PyUnicode_FromString(u);
259N/A#else
259N/A return PyUnicode_DecodeUTF8(u, strlen(u), NULL);
259N/A#endif
259N/A}
259N/A
259N/APyObject *
259N/Asss_exception_with_doc(char *name, char *doc, PyObject *base, PyObject *dict)
259N/A{
259N/A#ifdef HAVE_PYERR_NEWEXCEPTIONWITHDOC
259N/A return PyErr_NewExceptionWithDoc(name, doc, base, dict);
259N/A#else
259N/A int result;
259N/A PyObject *ret = NULL;
259N/A PyObject *mydict = NULL; /* points to the dict only if we create it */
259N/A PyObject *docobj;
259N/A
if (dict == NULL) {
dict = mydict = PyDict_New();
if (dict == NULL) {
return NULL;
}
}
if (doc != NULL) {
docobj = PyString_FromString(doc);
if (docobj == NULL)
goto failure;
result = PyDict_SetItemString(dict, "__doc__", docobj);
Py_DECREF(docobj);
if (result < 0)
goto failure;
}
ret = PyErr_NewException(name, base, dict);
failure:
Py_XDECREF(mydict);
return ret;
#endif
}