Author: juhliarik
Date: Wed Dec 5 09:55:10 2007
New Revision: 42687
URL: http://svn.opensuse.org/viewcvs/yast?rev=42687&view=rev
Log:
bugfixing:
bug# 345133 - Python-Bindings: Calling function with None as argument failed
bug# 343283 - Python-Bindings: Missing error messages
Modified:
trunk/python-bindings/src/YCP.cc
trunk/python-bindings/src/YPython.cc
trunk/python-bindings/src/YPython.h
Modified: trunk/python-bindings/src/YCP.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCP.cc?rev=42687&r1=42686&r2=42687&view=diff
==============================================================================
--- trunk/python-bindings/src/YCP.cc (original)
+++ trunk/python-bindings/src/YCP.cc Wed Dec 5 09:55:10 2007
@@ -20,6 +20,7 @@
#include
#include
#include
+#include
#include
#include "YPython.h"
@@ -201,9 +202,13 @@
//cout << textdomain << endl;
- string _fun = "_ = gettext.gettext";
+ string _fun =
+ "def _(str): \n\
+ return gettext.gettext(str)";
+
PyRun_SimpleString("import sys, traceback");
+ PyRun_SimpleString(_fun.c_str());
Self = Py_InitModule("ycp", YCPMethods);
initYCPTypes(Self);
@@ -738,12 +743,14 @@
pPythonValue = PyTuple_GetItem(args, i);
if (pPythonValue) {
ycpArg = ypython->PythonTypeToYCPType(pPythonValue);
-
+ //transform YCPNull to YCPVoid
+ if (ycpArg.isNull()) {
+ ycpArg = YCPVoid();
+ }
/*XXX
if (fun_type->parameterType(i-2)->matchvalue(ycpArg) != 0) {
y2error ("Wrong type of argumment %d",i-2);
return PyExc_TypeError;
-
}*/
bool ok = func_call->appendParameter (ycpArg);
if (!ok) {
Modified: trunk/python-bindings/src/YPython.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.cc?rev=42687&r1=42686&r2=42687&view=diff
==============================================================================
--- trunk/python-bindings/src/YPython.cc (original)
+++ trunk/python-bindings/src/YPython.cc Wed Dec 5 09:55:10 2007
@@ -151,7 +151,9 @@
y2error("Can't import module %s", module_name.c_str());
if (PyErr_Occurred() != NULL){
- PyErr_Print();
+ //string err = PyErrorHandler();
+ y2error("Python error: %s", PyErrorHandler().c_str());
+ //PyErr_Print();
}
return YCPError("The module was not imported");
@@ -212,8 +214,10 @@
result = PythonTypeToYCPType(pReturn); // create YCP value
else{
y2error("PyObject_CallObject(pFunc, pArgs) failed!");
- PyErr_Print();
- y2error("pReturn == 0");
+ if (PyErr_Occurred() != NULL){
+ y2error("Python error: %s", PyErrorHandler().c_str());
+ //PyErr_Print();
+ }
}
//delete pReturn
Py_CLEAR(pReturn);
@@ -805,6 +809,62 @@
+string YPython::PyErrorHandler() {
+ /* process Python-related errors */
+ /* call after Python API raises an exception */
+
+ PyObject *errobj, *errdata, *errtraceback, *pystring;
+
+ string result = "error type: ";
+ /* get latest python exception info */
+ PyErr_Fetch(&errobj, &errdata, &errtraceback);
+
+ pystring = NULL;
+ if (errobj != NULL &&
+ (pystring = PyObject_Str(errobj)) != NULL && /* str(object) */
+ (PyString_Check(pystring))
+ )
+ //strcpy(save_error_type, PyString_AsString(pystring));
+ result += PyString_AsString(pystring);
+ else
+ result += "<unknown exception type>";
+ Py_XDECREF(pystring);
+ result +="; error value: ";
+
+ pystring = NULL;
+ if (errdata != NULL &&
+ (pystring = PyObject_Str(errdata)) != NULL &&
+ (PyString_Check(pystring))
+ )
+ //strcpy(save_error_info, PyString_AsString(pystring));
+ result += PyString_AsString(pystring);
+ else
+ //strcpy(save_error_info, "<unknown exception data>");
+ result += "<unknown exception value>";
+ Py_XDECREF(pystring);
+
+ result +="; error traceback: ";
+
+ pystring = NULL;
+ if (errdata != NULL &&
+ (pystring = PyObject_Str(errtraceback)) != NULL &&
+ (PyString_Check(pystring))
+ )
+ //strcpy(save_error_info, PyString_AsString(pystring));
+ result += PyString_AsString(pystring);
+ else
+ //strcpy(save_error_info, "<unknown exception data>");
+ result += "<unknown exception traceback>";
+ Py_XDECREF(pystring);
+ //printf("%s\n%s\n", save_error_type, save_error_info);
+ Py_XDECREF(errobj);
+ Py_XDECREF(errdata); /* caller owns all 3 */
+ Py_XDECREF(errtraceback); /* already NULL'd out */
+ return result;
+
+}
+
+
YPythonCode::YPythonCode (PyObject *pFunc):YCode() {
m_kind = YCode::yeReference;
_pFunc = pFunc;
@@ -833,7 +893,10 @@
result = YPython::yPython()->PythonTypeToYCPType(pReturn); // create YCP value
} else {
y2error("pReturn == 0");
- PyErr_Print();
+ if (PyErr_Occurred() != NULL){
+ y2error("Python error: %s", YPython::PyErrorHandler().c_str());
+ //PyErr_Print();
+ }
}
}
return result;
Modified: trunk/python-bindings/src/YPython.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.h?rev=42687&r1=42686&r2=42687&view=diff
==============================================================================
--- trunk/python-bindings/src/YPython.h (original)
+++ trunk/python-bindings/src/YPython.h Wed Dec 5 09:55:10 2007
@@ -113,7 +113,11 @@
*/
PyObject *YCPTypeToPythonType(YCPValue);
-
+ /**
+ * Handler for python errors, info will be saved into yast logs
+ * FUnction saves info from void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
+ **/
+ static string PyErrorHandler();
private:
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org