py3: Base: files R-Z ported to python3
issue 0000995
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user