Lines 746-754
QString PythonQtConv::PyObjGetRepresenta
Link Here
|
746 |
QString PythonQtConv::PyObjGetString(PyObject* val, bool strict, bool& ok) { |
746 |
QString PythonQtConv::PyObjGetString(PyObject* val, bool strict, bool& ok) { |
747 |
QString r; |
747 |
QString r; |
748 |
ok = true; |
748 |
ok = true; |
|
|
749 |
#ifndef PY3K |
750 |
// in Python 3, we don't want to convert to QString, since we don't know anything about the encoding |
751 |
// in Python 2, we assume the default for str is latin-1 |
749 |
if (val->ob_type == &PyBytes_Type) { |
752 |
if (val->ob_type == &PyBytes_Type) { |
750 |
r = QString(PyBytes_AS_STRING(val)); |
753 |
r = QString::fromLatin1(PyBytes_AS_STRING(val)); |
751 |
} else if (PyUnicode_Check(val)) { |
754 |
} else |
|
|
755 |
#endif |
756 |
if (PyUnicode_Check(val)) { |
752 |
#ifdef PY3K |
757 |
#ifdef PY3K |
753 |
r = QString::fromUtf8(PyUnicode_AsUTF8(val)); |
758 |
r = QString::fromUtf8(PyUnicode_AsUTF8(val)); |
754 |
#else |
759 |
#else |
Lines 976-983
QVariant PythonQtConv::PyObjToQVariant(P
Link Here
|
976 |
#endif |
981 |
#endif |
977 |
) { |
982 |
) { |
978 |
// no special type requested |
983 |
// no special type requested |
979 |
if (PyBytes_Check(val) || PyUnicode_Check(val)) { |
984 |
if (PyBytes_Check(val)) { |
980 |
// NOTE: for compatibility reasons between Python 2/3 we don't use ByteArray for PyBytes_Type |
985 |
#ifdef PY3K |
|
|
986 |
// In Python 3, it is a ByteArray |
987 |
type = QVariant::ByteArray; |
988 |
#else |
989 |
// In Python 2, we need to use String, since it might be a string |
990 |
type = QVariant::String; |
991 |
#endif |
992 |
} else if (PyUnicode_Check(val)) { |
981 |
type = QVariant::String; |
993 |
type = QVariant::String; |
982 |
} else if (val == Py_False || val == Py_True) { |
994 |
} else if (val == Py_False || val == Py_True) { |
983 |
type = QVariant::Bool; |
995 |
type = QVariant::Bool; |
Lines 1117-1122
QVariant PythonQtConv::PyObjToQVariant(P
Link Here
|
1117 |
} |
1129 |
} |
1118 |
|
1130 |
|
1119 |
case QVariant::ByteArray: |
1131 |
case QVariant::ByteArray: |
|
|
1132 |
{ |
1133 |
bool ok; |
1134 |
#ifdef PY3K |
1135 |
v = QVariant(PyObjGetBytes(val, false, ok)); |
1136 |
#else |
1137 |
v = QVariant(PyObjGetString(val, false, ok)); |
1138 |
#endif |
1139 |
} |
1120 |
case QVariant::String: |
1140 |
case QVariant::String: |
1121 |
{ |
1141 |
{ |
1122 |
bool ok; |
1142 |
bool ok; |
Lines 1504-1510
QByteArray PythonQtConv::getCPPTypeName(
Link Here
|
1504 |
bool PythonQtConv::isStringType(PyTypeObject* type) |
1524 |
bool PythonQtConv::isStringType(PyTypeObject* type) |
1505 |
{ |
1525 |
{ |
1506 |
#ifdef PY3K |
1526 |
#ifdef PY3K |
1507 |
return type == &PyUnicode_Type |
1527 |
return type == &PyUnicode_Type; |
1508 |
#else |
1528 |
#else |
1509 |
return type == &PyUnicode_Type || type == &PyString_Type; |
1529 |
return type == &PyUnicode_Type || type == &PyString_Type; |
1510 |
#endif |
1530 |
#endif |