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 6a3a102964
commit 7d80f9012f
2 changed files with 12 additions and 13 deletions

View File

@@ -88,7 +88,7 @@ HighCarbonToolSteel CastAlloy, Ceramics, Diamond, Sialon or Undefined</UserDocu>
</Methode>
<Methode Name="fromTemplate">
<Documentation>
<UserDocu>fills receiver with values from the template string</UserDocu>
<UserDocu>fromTemplate(xmlString) ... fills receiver with values from the template string</UserDocu>
</Documentation>
</Methode>
<!--<ClassDeclarations>

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;
}