Changing c-py interface to use 's' instead of 'S' for py 2/3 compatibility; also makes the code simpler.

This commit is contained in:
Markus Lampert
2017-06-21 11:41:15 -07:00
parent 5e4533c959
commit d4e4af52e7
2 changed files with 12 additions and 13 deletions

View File

@@ -330,19 +330,18 @@ PyObject* ToolPy::copy(PyObject * args)
PyObject* ToolPy::fromTemplate(PyObject * args)
{
PyObject *pcObj;
if (PyArg_ParseTuple(args, "S", &pcObj)) {
if (PyString_Check(pcObj)) {
// embed actual string in dummy tag so XMLReader can consume that on construction
std::ostringstream os;
os << "<snippet>" << PyString_AsString(pcObj) << "</snippet>";
std::istringstream is(os.str());
Base::XMLReader reader("", is);
getToolPtr()->Restore(reader);
Py_Return ;
}
char *pstr = 0;
if (PyArg_ParseTuple(args, "s", &pstr)) {
// embed actual string in dummy tag so XMLReader can consume that on construction
std::ostringstream os;
os << "<snippet>" << pstr << "</snippet>";
std::istringstream is(os.str());
Base::XMLReader reader("", is);
getToolPtr()->Restore(reader);
Py_Return ;
}
throw Py::Exception("only string argument accepted.");
PyErr_SetString(PyExc_TypeError, "argument must be a string");
return 0;
}