2 #include "PythonNode.hxx"
3 #include "RuntimeSALOME.hxx"
8 using namespace YACS::ENGINE;
11 PythonNode::PythonNode(const string& name): ElementaryNode(name)
13 _implementation = "Python";
14 cerr << "PythonNode::PythonNode " << name << endl;
17 void PythonNode::set_script(const string& script)
22 void PythonNode::execute()
24 cerr << "PyNode::run" << endl;
25 PyObject* context=PyDict_New();
26 if( PyDict_SetItemString( context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
29 msg << "Impossible to set builtins" << __FILE__ << ":" << __LINE__;
30 throw Exception(msg.str());
33 cerr << "---------------PyNode::inputs---------------" << endl;
34 set<InputPort *>::iterator iter2;
35 for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
37 InputPyPort *p=(InputPyPort *)*iter2;
38 cerr << "port name: " << p->getName() << endl;
39 cerr << "port kind: " << p->type()->kind() << endl;
40 PyObject* ob=p->getPyObj();
41 cerr << "ob refcnt: " << ob->ob_refcnt << endl;
42 PyObject_Print(ob,stdout,Py_PRINT_RAW);
44 int ier=PyDict_SetItemString(context,p->getName().c_str(),ob);
45 cerr << "ob refcnt: " << ob->ob_refcnt << endl;
48 cerr << "---------------End PyNode::inputs---------------" << endl;
51 cerr << "PyNode::calculation " << _script << endl;
52 PyObject *res=PyRun_String(_script.c_str(),Py_file_input,context,context);
60 cerr << "-----------------PyNode::outputs-----------------" << endl;
61 set<OutputPort *>::iterator iter;
62 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
64 OutputPyPort *p=(OutputPyPort *)*iter;
65 cerr << "port name: " << p->getName() << endl;
66 cerr << "port kind: " << p->type()->kind() << endl;
67 PyObject *ob=PyDict_GetItemString(context,p->getName().c_str());
68 cerr << "ob refcnt: " << ob->ob_refcnt << endl;
69 PyObject_Print(ob,stdout,Py_PRINT_RAW);
71 //Faut-il incrémenter ici ?
73 cerr << "ob refcnt: " << ob->ob_refcnt << endl;
77 cerr << "-----------------End PyNode::outputs-----------------" << endl;