App: correctly handle int as argument for ocumentPy::getObject

Add a unit test to confirm correct behaviour
This commit is contained in:
wmayer
2022-03-09 23:02:22 +01:00
parent ae94c8489c
commit fa0e6dfa9e
2 changed files with 36 additions and 12 deletions
+25 -12
View File
@@ -564,20 +564,33 @@ PyObject* DocumentPy::purgeTouched(PyObject* args)
Py_Return;
}
PyObject* DocumentPy::getObject(PyObject *args)
PyObject* DocumentPy::getObject(PyObject *args)
{
long id = -1;
char *sName = 0;
if (!PyArg_ParseTuple(args, "s",&sName)) {
if (!PyArg_ParseTuple(args, "l", &id))
return nullptr;
}
DocumentObject* obj = nullptr;
DocumentObject *pcFtr = sName?getDocumentPtr()->getObject(sName):getDocumentPtr()->getObjectByID(id);
if (pcFtr)
return pcFtr->getPyObject();
else
Py_Return;
do {
char* name = nullptr;
if (PyArg_ParseTuple(args, "s", &name)) {
obj = getDocumentPtr()->getObject(name);
break;
}
PyErr_Clear();
long id = -1;
if (PyArg_ParseTuple(args, "l", &id)) {
obj = getDocumentPtr()->getObjectByID(id);
break;
}
PyErr_SetString(PyExc_TypeError, "a string or integer is required");
return nullptr;
}
while (0);
if (obj)
return obj->getPyObject();
Py_Return;
}
PyObject* DocumentPy::getObjectsByLabel(PyObject *args)