+ if (!PyObject_HasAttrString(py_obj, attr)) {
+ srd_dbg("object has no attribute '%s'", attr);
+ return SRD_ERR_PYTHON;
+ }
+
+ if (!(py_str = PyObject_GetAttrString(py_obj, attr))) {
+ /* TODO: report exception message/traceback to err/dbg */
+ PyErr_Clear();
+ return SRD_ERR_PYTHON;
+ }
+
+ ret = py_str_as_str(py_str, outstr);
+ Py_XDECREF(py_str);
+
+ return ret;
+}
+
+
+/**
+ * Get the value of a python unicode string object, returned as a newly
+ * allocated char *.
+ *
+ * @param py_str The unicode string object.
+ * @param outstr ptr to char * storage to be filled in.
+ *
+ * @return SRD_OK upon success, a (negative) error code otherwise.
+ * The 'outstr' argument points to a malloc()ed string upon success.
+ */
+int py_str_as_str(PyObject *py_str, char **outstr)
+{
+ PyObject *py_encstr;
+ int ret;
+ char *str;
+
+ py_encstr = NULL;