From 17ffa8255bfa6b5ead0b7c9cae32789807873f2f Mon Sep 17 00:00:00 2001 From: luz paz Date: Fri, 23 Apr 2021 17:44:15 -0400 Subject: [PATCH] Gui: remove py2 code --- src/Gui/CallTips.cpp | 12 ---- src/Gui/Command.cpp | 28 --------- src/Gui/PythonWorkbenchPyImp.cpp | 104 ------------------------------- src/Gui/ViewProviderPyImp.cpp | 15 ----- 4 files changed, 159 deletions(-) diff --git a/src/Gui/CallTips.cpp b/src/Gui/CallTips.cpp index d6e71d96fa..2a1a5e63b9 100644 --- a/src/Gui/CallTips.cpp +++ b/src/Gui/CallTips.cpp @@ -236,11 +236,7 @@ QMap CallTipsList::extractTips(const QString& context) const PyObject* eval = 0; if (PyCode_Check(code)) { -#if PY_MAJOR_VERSION >= 3 eval = PyEval_EvalCode(code, dict.ptr(), dict.ptr()); -#else - eval = PyEval_EvalCode(reinterpret_cast(code), dict.ptr(), dict.ptr()); -#endif } Py_DECREF(code); if (!eval) { @@ -276,14 +272,6 @@ QMap CallTipsList::extractTips(const QString& context) const else if (PyObject_IsSubclass(type.ptr(), typeobj.o) == 1) { obj = type; } -#if PY_MAJOR_VERSION < 3 - else if (PyInstance_Check(obj.ptr())) { - // instances of old style classes - PyInstanceObject* inst = reinterpret_cast(obj.ptr()); - PyObject* classobj = reinterpret_cast(inst->in_class); - obj = Py::Object(classobj); - } -#endif else if (PyObject_IsInstance(obj.ptr(), basetype.o) == 1) { // New style class which can be a module, type, list, tuple, int, float, ... // Make sure it's not a type object diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 83b9a92286..1647192f68 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -649,11 +649,7 @@ void Command::printPyCaller() { if(!frame) return; int line = PyFrame_GetLineNumber(frame); -#if PY_MAJOR_VERSION >= 3 const char *file = PyUnicode_AsUTF8(frame->f_code->co_filename); -#else - const char *file = PyString_AsString(frame->f_code->co_filename); -#endif printCaller(file?file:"",line); } @@ -1239,19 +1235,11 @@ const char* PythonCommand::getResource(const char* sName) const pcTemp = PyDict_GetItemString(_pcPyResourceDict,sName); if (!pcTemp) return ""; -#if PY_MAJOR_VERSION >= 3 if (!PyUnicode_Check(pcTemp)) { -#else - if (!PyString_Check(pcTemp)) { -#endif throw Base::TypeError("PythonCommand::getResource(): Method GetResources() of the Python " "command object returns a dictionary which holds not only strings"); } -#if PY_MAJOR_VERSION >= 3 return PyUnicode_AsUTF8(pcTemp); -#else - return PyString_AsString(pcTemp); -#endif } void PythonCommand::activated(int iMsg) @@ -1314,17 +1302,9 @@ const char* PythonCommand::getHelpUrl(void) const pcTemp = Interpreter().runMethodObject(_pcPyCommand, "CmdHelpURL"); if (! pcTemp ) return ""; -#if PY_MAJOR_VERSION >= 3 if (! PyUnicode_Check(pcTemp) ) -#else - if (! PyString_Check(pcTemp) ) -#endif throw Base::TypeError("PythonCommand::CmdHelpURL(): Method CmdHelpURL() of the Python command object returns no string"); -#if PY_MAJOR_VERSION >= 3 return PyUnicode_AsUTF8(pcTemp); -#else - return PyString_AsString(pcTemp); -#endif } Action * PythonCommand::createAction(void) @@ -1647,19 +1627,11 @@ const char* PythonGroupCommand::getResource(const char* sName) const pcTemp = PyDict_GetItemString(_pcPyResource, sName); if (!pcTemp) return ""; -#if PY_MAJOR_VERSION >= 3 if (!PyUnicode_Check(pcTemp)) { -#else - if (!PyString_Check(pcTemp)) { -#endif throw Base::ValueError("PythonGroupCommand::getResource(): Method GetResources() of the Python " "group command object returns a dictionary which holds not only strings"); } -#if PY_MAJOR_VERSION >= 3 return PyUnicode_AsUTF8(pcTemp); -#else - return PyString_AsString(pcTemp); -#endif } const char* PythonGroupCommand::getWhatsThis() const diff --git a/src/Gui/PythonWorkbenchPyImp.cpp b/src/Gui/PythonWorkbenchPyImp.cpp index 54c5a7e7a4..6a4b5d7a3f 100644 --- a/src/Gui/PythonWorkbenchPyImp.cpp +++ b/src/Gui/PythonWorkbenchPyImp.cpp @@ -63,36 +63,15 @@ PyObject* PythonWorkbenchPy::appendMenu(PyObject *args) for (int j=0; j= 3 const char* pItem = PyUnicode_AsUTF8(item); path.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - path.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(item)) { - char* pItem = PyString_AsString(item); - path.push_back(pItem); -#endif } else { continue; } } } else if (PyUnicode_Check(pPath)) { -#if PY_MAJOR_VERSION >= 3 const char* pItem = PyUnicode_AsUTF8(pPath); path.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(pPath, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - path.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(pPath)) { - // one single item - char* pItem = PyString_AsString(pPath); - path.push_back(pItem); -#endif } else { PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument"); return nullptr; @@ -105,36 +84,15 @@ PyObject* PythonWorkbenchPy::appendMenu(PyObject *args) for (int i=0; i= 3 const char* pItem = PyUnicode_AsUTF8(item); items.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - items.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(item)) { - char* pItem = PyString_AsString(item); - items.push_back(pItem); -#endif } else { continue; } } } else if (PyUnicode_Check(pItems)) { -#if PY_MAJOR_VERSION >= 3 const char* pItem = PyUnicode_AsUTF8(pItems); items.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(pItems, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - items.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(pItems)) { - // one single item - char* pItem = PyString_AsString(pItems); - items.push_back(pItem); -#endif } else { PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument"); return nullptr; @@ -175,36 +133,15 @@ PyObject* PythonWorkbenchPy::appendContextMenu(PyObject *args) for (int j=0; j= 3 const char* pItem = PyUnicode_AsUTF8(item); path.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - path.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(item)) { - char* pItem = PyString_AsString(item); - path.push_back(pItem); -#endif } else { continue; } } } else if (PyUnicode_Check(pPath)) { -#if PY_MAJOR_VERSION >= 3 const char* pItem = PyUnicode_AsUTF8(pPath); path.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(pPath, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - path.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(pPath)) { - // one single item - char* pItem = PyString_AsString(pPath); - path.push_back(pItem); -#endif } else { PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument"); return nullptr; @@ -217,36 +154,15 @@ PyObject* PythonWorkbenchPy::appendContextMenu(PyObject *args) for (int i=0; i= 3 const char* pItem = PyUnicode_AsUTF8(item); items.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - items.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(item)) { - char* pItem = PyString_AsString(item); - items.push_back(pItem); -#endif } else { continue; } } } else if (PyUnicode_Check(pItems)) { -#if PY_MAJOR_VERSION >= 3 const char* pItem = PyUnicode_AsUTF8(pItems); items.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(pItems, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - items.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(pItems)) { - // one single item - char* pItem = PyString_AsString(pItems); - items.push_back(pItem); -#endif } else { PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument"); return nullptr; @@ -289,18 +205,8 @@ PyObject* PythonWorkbenchPy::appendToolbar(PyObject *args) for (int i=0; i= 3 const char* pItem = PyUnicode_AsUTF8(item); items.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - items.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(item)) { - char* pItem = PyString_AsString(item); - items.push_back(pItem); -#endif } else { continue; } @@ -342,18 +248,8 @@ PyObject* PythonWorkbenchPy::appendCommandbar(PyObject *args) for (int i=0; i= 3 const char* pItem = PyUnicode_AsUTF8(item); items.push_back(pItem); -#else - PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0); - char* pItem = PyString_AsString(unicode); - items.push_back(pItem); - Py_DECREF(unicode); - } else if (PyString_Check(item)) { - char* pItem = PyString_AsString(item); - items.push_back(pItem); -#endif } else { continue; } diff --git a/src/Gui/ViewProviderPyImp.cpp b/src/Gui/ViewProviderPyImp.cpp index c8669d99f8..506050f9fc 100644 --- a/src/Gui/ViewProviderPyImp.cpp +++ b/src/Gui/ViewProviderPyImp.cpp @@ -320,11 +320,7 @@ PyObject* ViewProviderPy::listDisplayModes(PyObject *args) int i=0; for ( std::vector::iterator it = modes.begin(); it != modes.end(); ++it ) { -#if PY_MAJOR_VERSION >= 3 PyObject* str = PyUnicode_FromString(it->c_str()); -#else - PyObject* str = PyString_FromString(it->c_str()); -#endif PyList_SetItem(pyList, i++, str); } @@ -400,19 +396,8 @@ PyObject* ViewProviderPy::partialRender(PyObject* args) for (Py_ssize_t i = 0; i < nSize; ++i) { if(value) item = PySequence_GetItem(value, i); if (PyUnicode_Check(item)) { -#if PY_MAJOR_VERSION >= 3 values[i] = PyUnicode_AsUTF8(item); -#else - PyObject* unicode = PyUnicode_AsUTF8String(item); - values[i] = PyString_AsString(unicode); - Py_DECREF(unicode); -#endif } -#if PY_MAJOR_VERSION < 3 - else if (PyString_Check(item)) { - values[i] = PyString_AsString(item); - } -#endif else { std::string error = std::string("type must be str or unicode"); error += " not, ";