* =========== PYTHON ==============
* ==================================*/
-typedef struct {
- PyObject_HEAD
- int softspace;
- std::string *out;
- } PyStdOut;
-
-static void
-PyStdOut_dealloc(PyStdOut *self)
-{
- PyObject_Del(self);
-}
-
-static PyObject *
-PyStdOut_write(PyStdOut *self, PyObject *args)
+namespace
{
- char *c;
- int l;
- if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
- return NULL;
-
- //std::cerr << c ;
- *(self->out)=*(self->out)+c;
-
- Py_INCREF(Py_None);
- return Py_None;
-}
+ typedef struct {
+ PyObject_HEAD
+ int softspace;
+ std::string *out;
+ } PyStdOut;
+
+ static void
+ PyStdOut_dealloc(PyStdOut *self)
+ {
+ PyObject_Del(self);
+ }
-static PyMethodDef PyStdOut_methods[] = {
- {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
- PyDoc_STR("write(string) -> None")},
- {NULL, NULL} /* sentinel */
-};
-
-static PyMemberDef PyStdOut_memberlist[] = {
- {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
- (char*)"flag indicating that a space needs to be printed; used by print"},
- {NULL} /* Sentinel */
-};
-
-static PyTypeObject PyStdOut_Type = {
- /* The ob_type field must be initialized in the module init function
- * to be portable to Windows without using C++. */
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "PyOut", /*tp_name*/
- sizeof(PyStdOut), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor)PyStdOut_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- PyObject_GenericGetAttr, /*tp_getattro*/
- /* softspace is writable: we must supply tp_setattro */
- PyObject_GenericSetAttr, /* tp_setattro */
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- PyStdOut_methods, /*tp_methods*/
- PyStdOut_memberlist, /*tp_members*/
- 0, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- 0, /*tp_init*/
- 0, /*tp_alloc*/
- 0, /*tp_new*/
- 0, /*tp_free*/
- 0, /*tp_is_gc*/
-};
-
-PyObject * newPyStdOut( std::string& out )
-{
- PyStdOut *self;
- self = PyObject_New(PyStdOut, &PyStdOut_Type);
- if (self == NULL)
- return NULL;
- self->softspace = 0;
- self->out=&out;
- return (PyObject*)self;
+ static PyObject*
+ PyStdOut_write(PyStdOut* self, PyObject* args)
+ {
+ char *c;
+ int l;
+ if (!PyArg_ParseTuple(args, "t#:write", &c, &l))
+ return NULL;
+
+ *(self->out) = *(self->out) + c;
+
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ static PyMethodDef PyStdOut_methods[] = {
+ {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
+ PyDoc_STR("write(string) -> None")},
+ {NULL, NULL} /* sentinel */
+ };
+
+ static PyMemberDef PyStdOut_memberlist[] = {
+ {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
+ (char*)"flag indicating that a space needs to be printed; used by print"},
+ {NULL} /* Sentinel */
+ };
+
+ static PyTypeObject PyStdOut_Type = {
+ /* The ob_type field must be initialized in the module init function
+ * to be portable to Windows without using C++. */
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "PyOut", /*tp_name*/
+ sizeof(PyStdOut), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor)PyStdOut_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ PyObject_GenericGetAttr, /*tp_getattro*/
+ /* softspace is writable: we must supply tp_setattro */
+ PyObject_GenericSetAttr, /* tp_setattro */
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ PyStdOut_methods, /*tp_methods*/
+ PyStdOut_memberlist, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ 0, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ };
+
+ PyObject* newPyStdOut( std::string& out )
+ {
+ PyStdOut* self = PyObject_New(PyStdOut, &PyStdOut_Type);
+ if (self) {
+ self->softspace = 0;
+ self->out=&out;
+ }
+ return (PyObject*)self;
+ }
}
-
////////////////////////END PYTHON///////////////////////////
//=============================================================================
/*!
PyObject* main_dict = PyModule_GetDict(main_mod);
PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
- printf("%s\n", aPyScript.ToCString());
if (obj == NULL) {
SetErrorCode("Error during executing of python script !!!");
else
coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
- PyObject* new_stderr = NULL;
-
if (coords == NULL){
fflush(stderr);
std::string err_description="";
- new_stderr = newPyStdOut(err_description);
+ PyObject* new_stderr = newPyStdOut(err_description);
+ PyObject* old_stderr = PySys_GetObject((char*)"stderr");
PySys_SetObject((char*)"stderr", new_stderr);
PyErr_Print();
- PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
+ PySys_SetObject((char*)"stderr", old_stderr);
Py_DECREF(new_stderr);
MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description);
SetErrorCode("Can't evaluate the expressions, please check them !!!");
## Raise an Error, containing the Method_name, if Operation is Failed
## @ingroup l1_geomBuilder_auxiliary
def RaiseIfFailed (Method_name, Operation):
- if Operation.IsDone() == 0 and Operation.GetErrorCode() != "NOT_FOUND_ANY":
+ if not Operation.IsDone() and Operation.GetErrorCode() != "NOT_FOUND_ANY":
raise RuntimeError, Method_name + " : " + Operation.GetErrorCode()
## Return list of variables value from salome notebook
anObj = self.CurvesOp.MakeCurveParametricNew(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType)
else:
anObj = self.CurvesOp.MakeCurveParametric(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType)
- RaiseIfFailed("MakeSplineInterpolation", self.CurvesOp)
+ RaiseIfFailed("MakeCurveParametric", self.CurvesOp)
anObj.SetParameters(Parameters)
self._autoPublish(anObj, theName, "curve")
return anObj