py3: App: files A-C ported to python3

This commit is contained in:
Yorik van Havre
2017-05-10 00:07:47 +02:00
committed by wmayer
parent 36960df73e
commit 0d033757ae
2 changed files with 50 additions and 10 deletions

View File

@@ -352,7 +352,11 @@ PyObject* Application::sGetConfig(PyObject * /*self*/, PyObject *args,PyObject *
}
else {
// do not set an error because this may break existing python code
#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromString("");
#else
return PyString_FromString("");
#endif
}
}
@@ -364,7 +368,11 @@ PyObject* Application::sDumpConfig(PyObject * /*self*/, PyObject *args,PyObject
PyObject *dict = PyDict_New();
for (std::map<std::string,std::string>::iterator It= GetApplication()._mConfig.begin();
It!=GetApplication()._mConfig.end();++It) {
#if PY_MAJOR_VERSION >= 3
PyDict_SetItemString(dict,It->first.c_str(), PyUnicode_FromString(It->second.c_str()));
#else
PyDict_SetItemString(dict,It->first.c_str(), PyString_FromString(It->second.c_str()));
#endif
}
return dict;
}
@@ -559,7 +567,11 @@ PyObject* Application::sListDocuments(PyObject * /*self*/, PyObject *args,PyObje
for (std::map<std::string,Document*>::const_iterator It = GetApplication().DocMap.begin();
It != GetApplication().DocMap.end();++It) {
#if PY_MAJOR_VERSION >= 3
pKey = PyUnicode_FromString(It->first.c_str());
#else
pKey = PyString_FromString(It->first.c_str());
#endif
// GetPyObject() increments
pValue = static_cast<Base::PyObjectBase*>(It->second->getPyObject());
PyDict_SetItem(pDict, pKey, pValue);