Arch: Survey: fix py3 unicode problems

This commit is contained in:
looooo
2018-06-04 19:23:42 +02:00
parent 881059fd61
commit 59e06142dc
2 changed files with 40 additions and 19 deletions

View File

@@ -1752,6 +1752,16 @@ void PropertyStringList::setPyObject(PyObject *value)
if (PyString_Check(value)) {
setValue(PyString_AsString(value));
}
#endif
else if (PyUnicode_Check(value)) {
#if PY_MAJOR_VERSION >= 3
setValue(PyUnicode_AsUTF8(value));
}
#else
PyObject* unicode = PyUnicode_AsUTF8String(value);
setValue(PyString_AsString(unicode));
Py_DECREF(unicode);
}
#endif
else if (PySequence_Check(value)) {
Py_ssize_t nSize = PySequence_Size(value);
@@ -1781,16 +1791,6 @@ void PropertyStringList::setPyObject(PyObject *value)
setValues(values);
}
else if (PyUnicode_Check(value)) {
#if PY_MAJOR_VERSION >= 3
setValue(PyUnicode_AsUTF8(value));
}
#else
PyObject* unicode = PyUnicode_AsUTF8String(value);
setValue(PyString_AsString(unicode));
Py_DECREF(unicode);
}
#endif
else {
std::string error = std::string("type must be str or unicode or list of str or list of unicodes, not ");
error += value->ob_type->tp_name;