* 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
| 291 | * @private |
| 292 | */ |
| 293 | SRD_PRIV int py_dict_value_to_str(PyObject *py_obj, PyObject *py_key, |
| 294 | char **outstr) |
| 295 | { |
| 296 | PyObject *py_value; |
| 297 | PyGILState_STATE gstate; |
| 298 | |
| 299 | if (!py_obj || !py_key || !outstr) |
| 300 | return SRD_ERR_ARG; |
| 301 | |
| 302 | gstate = PyGILState_Ensure(); |
| 303 | |
| 304 | if (!PyDict_Check(py_obj)) { |
| 305 | srd_dbg("Object is not a dictionary."); |
| 306 | goto err; |
| 307 | } |
| 308 | |
| 309 | if (!(py_value = PyDict_GetItem(py_obj, py_key))) { |
| 310 | srd_dbg("Dictionary has no such key."); |
| 311 | goto err; |
| 312 | } |
| 313 | |
| 314 | if (!PyUnicode_Check(py_value)) { |
| 315 | srd_dbg("Dictionary value should be a string."); |
| 316 | goto err; |
| 317 | } |
| 318 | |
| 319 | PyGILState_Release(gstate); |
| 320 | |
| 321 | return py_str_as_str(py_value, outstr); |
| 322 | |
| 323 | err: |
| 324 | PyGILState_Release(gstate); |
| 325 | |
| 326 | return SRD_ERR_PYTHON; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Get the value of a Python dictionary item, returned as a newly |
nothing calls this directly
no test coverage detected