| 127 | } |
| 128 | |
| 129 | inline bool vtkPythonGetStdStringValue(PyObject* o, std::string& a, const char* exctext) |
| 130 | { |
| 131 | if (PyBytes_Check(o)) |
| 132 | { |
| 133 | char* val; |
| 134 | Py_ssize_t len; |
| 135 | PyBytes_AsStringAndSize(o, &val, &len); |
| 136 | a = std::string(val, len); |
| 137 | return true; |
| 138 | } |
| 139 | else if (PyUnicode_Check(o)) |
| 140 | { |
| 141 | Py_ssize_t len; |
| 142 | const char* val = PyUnicode_AsUTF8AndSize(o, &len); |
| 143 | a = std::string(val, len); |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | PyErr_SetString(PyExc_TypeError, exctext); |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | //------------------------------------------------------------------------------ |
| 152 | // Overloaded methods, mostly based on the above templates |
no test coverage detected