| 883 | /************************************************************************/ |
| 884 | |
| 885 | CPLString GetString(PyObject *obj, bool bEmitError) |
| 886 | { |
| 887 | PyObject *unicode = PyUnicode_AsUTF8String(obj); |
| 888 | if (PyErr_Occurred()) |
| 889 | { |
| 890 | if (bEmitError) |
| 891 | { |
| 892 | CPLError(CE_Failure, CPLE_AppDefined, "%s", |
| 893 | GetPyExceptionString().c_str()); |
| 894 | } |
| 895 | return CPLString(); |
| 896 | } |
| 897 | |
| 898 | const char *pszRet = PyBytes_AsString(unicode); |
| 899 | CPLString osRet = pszRet ? pszRet : ""; |
| 900 | Py_DecRef(unicode); |
| 901 | return osRet; |
| 902 | } |
| 903 | |
| 904 | /************************************************************************/ |
| 905 | /* GetPyExceptionString() */ |
no test coverage detected