+ goto err;
+ }
+
+ PyGILState_Release(gstate);
+
+ return py_str_as_str(py_value, outstr);
+
+err:
+ PyGILState_Release(gstate);
+
+ return SRD_ERR_PYTHON;
+}
+
+/**
+ * Get the value of a Python list item, returned as a newly
+ * allocated char *.
+ *
+ * @param[in] py_obj The list to probe.
+ * @param[in] idx Index of the list item to retrieve.
+ * @param[out] outstr Pointer to char * storage to be filled in.
+ *
+ * @return SRD_OK upon success, a (negative) error code otherwise.
+ * The 'outstr' argument points to a g_malloc()ed string upon success.
+ *
+ * @private
+ */
+SRD_PRIV int py_listitem_as_str(PyObject *py_obj, Py_ssize_t idx,
+ char **outstr)
+{
+ PyGILState_STATE gstate;
+ ssize_t item_idx;
+ PyObject *py_value;
+
+ gstate = PyGILState_Ensure();
+
+ if (!PyList_Check(py_obj)) {
+ srd_dbg("Object is not a list.");
+ goto err;
+ }
+
+ item_idx = idx;
+ if (!(py_value = PyList_GetItem(py_obj, item_idx))) {
+ srd_dbg("Couldn't get list item %zd.", item_idx);
+ goto err;
+ }
+
+ PyGILState_Release(gstate);
+
+ return py_str_as_str(py_value, outstr);
+
+err:
+ PyGILState_Release(gstate);
+
+ return SRD_ERR_PYTHON;
+}
+
+/**
+ * Get the value of a Python dictionary item, returned as a newly
+ * allocated char *.
+ *
+ * @param py_obj The dictionary to probe.
+ * @param py_key Key of the item to retrieve.
+ * @param outstr Pointer 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.
+ *
+ * @private
+ */
+SRD_PRIV int py_pydictitem_as_str(PyObject *py_obj, PyObject *py_key,
+ char **outstr)
+{
+ PyObject *py_value;
+ PyGILState_STATE gstate;
+
+ if (!py_obj || !py_key || !outstr)
+ return SRD_ERR_ARG;
+
+ gstate = PyGILState_Ensure();
+
+ if (!PyDict_Check(py_obj)) {
+ srd_dbg("Object is not a dictionary.");
+ goto err;
+ }
+
+ if (!(py_value = PyDict_GetItem(py_obj, py_key))) {
+ srd_dbg("Dictionary has no such key.");
+ goto err;