42 if (!PyObject_HasAttrString((PyObject *)py_obj, attr)) {
43 srd_dbg(
"%s object has no attribute '%s'.",
44 Py_TYPE(py_obj)->tp_name, attr);
48 if (!(py_str = PyObject_GetAttrString((PyObject *)py_obj, attr))) {
53 if (!PyUnicode_Check(py_str)) {
54 srd_dbg(
"%s attribute should be a string, but is a %s.",
55 attr, Py_TYPE(py_str)->tp_name);
83 if (!PyDict_Check((PyObject *)py_obj)) {
84 srd_dbg(
"Object is a %s, not a dictionary.",
85 Py_TYPE((PyObject *)py_obj)->tp_name);
89 if (!(py_value = PyDict_GetItemString((PyObject *)py_obj, key))) {
90 srd_dbg(
"Dictionary has no attribute '%s'.", key);
94 if (!PyUnicode_Check(py_value)) {
95 srd_dbg(
"Dictionary value for %s should be a string, but is "
96 "a %s.", key, Py_TYPE(py_value)->tp_name);
125 if (!PyUnicode_Check((PyObject *)py_str)) {
126 srd_dbg(
"Object is a %s, not a string object.",
127 Py_TYPE((PyObject *)py_str)->tp_name);
132 if (!(py_encstr = PyUnicode_AsEncodedString((PyObject *)py_str,
137 if (!(str = PyBytes_AS_STRING(py_encstr))) {
142 if (!(*outstr = g_strdup(str))) {
143 srd_dbg(
"Failed to g_malloc() outstr.");
150 Py_XDECREF(py_encstr);
152 if (PyErr_Occurred()) {
175 list_len = PyList_Size((PyObject *)py_strlist);
176 if (!(out = g_try_malloc(
sizeof(
char *) * (list_len + 1)))) {
177 srd_err(
"Failed to g_malloc() 'out'.");
180 for (i = 0; i < list_len; i++) {
181 if (!(py_str = PyUnicode_AsEncodedString(
182 PyList_GetItem((PyObject *)py_strlist, i),
"utf-8", NULL)))
184 if (!(str = PyBytes_AS_STRING(py_str)))
186 out[i] = g_strdup(str);