24 #include <structmember.h>
31 #define getpid _getpid
56 if (!PyArg_ParseTuple(args,
"t#:write",&c, &l))
60 *(
self->out)=*(self->out)+std::string(c);
68 PyDoc_STR(
"write(string) -> None")},
73 {(
char*)
"softspace", T_INT, offsetof(
PyStdOut, softspace), 0,
74 (
char*)
"flag indicating that a space needs to be printed; used by print"},
81 PyObject_HEAD_INIT(NULL)
99 PyObject_GenericGetAttr,
101 PyObject_GenericSetAttr,
127 #define PyStdOut_Check(v) ((v)->ob_type == &PyStdOut_Type)
132 self = PyObject_New(
PyStdOut, &PyStdOut_Type);
137 return (PyObject*)
self;
140 PyObject *
evalPy(
const std::string& funcName,
const std::string& strToEval)
142 std::ostringstream oss0; oss0 <<
"def " << funcName <<
"():\n";
143 std::string::size_type i0(0);
144 while(i0<strToEval.length() && i0!=std::string::npos)
146 std::string::size_type i2(strToEval.find(
'\n',i0));
147 std::string::size_type lgth(i2!=std::string::npos?i2-i0:std::string::npos);
148 std::string part(strToEval.substr(i0,lgth));
150 oss0 <<
" " << part <<
"\n";
151 i0=i2!=std::string::npos?i2+1:std::string::npos;
153 std::string zeCodeStr(oss0.str());
154 std::ostringstream stream;
155 stream <<
"/tmp/PythonNode_";
158 PyDict_SetItemString( context,
"__builtins__", PyEval_GetBuiltins() );
159 AutoPyRef code(Py_CompileString(zeCodeStr.c_str(),
"kkkk", Py_file_input));
162 std::string errorDetails;
164 PySys_SetObject((
char*)
"stderr", new_stderr);
166 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
167 Py_DECREF(new_stderr);
168 std::ostringstream oss; oss <<
"evalPy failed : " << errorDetails;
171 AutoPyRef res(PyEval_EvalCode(reinterpret_cast<PyCodeObject *>((PyObject *)code),context,context));
172 PyObject *
ret(PyDict_GetItemString(context,funcName.c_str()));
182 throw YACS::Exception(
"evalFuncPyWithNoParams : input func is NULL !");