py3: Base: files R-Z ported to python3

issue 0000995
This commit is contained in:
Yorik van Havre
2017-05-18 19:31:32 +02:00
committed by wmayer
parent 769bc97f63
commit d4b7100bb2
5 changed files with 67 additions and 7 deletions

View File

@@ -153,12 +153,17 @@ std::string Base::Tools::escapedUnicodeFromUtf8(const char *s)
return escapedstr;
PyObject* escaped = PyUnicode_AsUnicodeEscapeString(unicode);
if (escaped) {
#if PY_MAJOR_VERSION >= 3
escapedstr = std::string(PyBytes_AsString(escaped));
#else
escapedstr = std::string(PyString_AsString(escaped));
#endif
Py_DECREF(escaped);
}
Py_DECREF(unicode);
return escapedstr;
}
@@ -170,7 +175,11 @@ std::string Base::Tools::escapedUnicodeToUtf8(const std::string& s)
PyObject* unicode = PyUnicode_DecodeUnicodeEscape(s.c_str(), s.size(), "strict");
if (!unicode)
return string;
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(unicode)) {
string = PyUnicode_AsUTF8(unicode);
}
#else
if (PyUnicode_Check(unicode)) {
PyObject* value = PyUnicode_AsUTF8String(unicode);
string = PyString_AsString(value);
@@ -179,7 +188,7 @@ std::string Base::Tools::escapedUnicodeToUtf8(const std::string& s)
else if (PyString_Check(unicode)) {
string = PyString_AsString(unicode);
}
#endif
Py_DECREF(unicode);
return string;
}