py3: App: files D-Z ported to python3

issue 0000995
diff to py3-branch will remain in the following files in src/App:
- ExtensionContainer.cpp
- FeaturePythonPyImp.h +.inl
most likely these files depend on Tools and Base
This commit is contained in:
looooo
2017-05-11 09:55:40 +02:00
committed by wmayer
parent ce67325616
commit e6202f46e9
10 changed files with 389 additions and 20 deletions

View File

@@ -325,10 +325,14 @@ void PropertyPythonObject::Restore(Base::XMLReader &reader)
if (reader.hasAttribute("module") && reader.hasAttribute("class")) {
Py::Module mod(PyImport_ImportModule(reader.getAttribute("module")),true);
PyObject* cls = mod.getAttr(reader.getAttribute("class")).ptr();
#if PY_MAJOR_VERSION >= 3
if (PyType_Check(cls)) {
#else
if (PyClass_Check(cls)) {
this->object = PyInstance_NewRaw(cls, 0);
}
else if (PyType_Check(cls)) {
#endif
this->object = PyType_GenericAlloc((PyTypeObject*)cls, 0);
}
else {
@@ -340,7 +344,11 @@ void PropertyPythonObject::Restore(Base::XMLReader &reader)
std::string nam = std::string(what[1].first, what[1].second);
std::string cls = std::string(what[2].first, what[2].second);
Py::Module mod(PyImport_ImportModule(nam.c_str()),true);
#if PY_MAJOR_VERSION >= 3
this->object = PyObject_CallObject(mod.getAttr(cls).ptr(), NULL);
#else
this->object = PyInstance_NewRaw(mod.getAttr(cls).ptr(), 0);
#endif
load_pickle = true;
buffer = std::string(what[2].second, end);
}