Author: juhliarik Date: Thu Nov 1 15:59:45 2007 New Revision: 41711 URL: http://svn.opensuse.org/viewcvs/yast?rev=41711&view=rev Log: added patch for finding namespace and function Modified: trunk/python-bindings/src/YPython.cc trunk/python-bindings/src/YPython.h trunk/python-bindings/src/YPythonNamespace.cc Modified: trunk/python-bindings/src/YPython.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.cc?rev=41711&r1=41710&r2=41711&view=diff ============================================================================== --- trunk/python-bindings/src/YPython.cc (original) +++ trunk/python-bindings/src/YPython.cc Thu Nov 1 15:59:45 2007 @@ -621,6 +621,36 @@ return ns; } + +/** + * Find function in Global Dictionary + * confirm if function is from imported module or not + * return 1 if module is in dictionary and function too + * retrun 0 if module is in dictionary and function not + * return -1 if missing both (module and dinctionary) +**/ + +int YPython::findModuleFuncInDict(string module, string function) { + + PyObject* pMainDict = NULL; // dictionary of module + PyObject* pFunc = NULL; // function from dictionary + + //obtain correct dictionary for module + pMainDict = PyDict_GetItemString(YPython::yPython()->pMainDicts(),module.c_str()); + + //obtain function from dictionary + if (pMainDict) + pFunc = PyDict_GetItemString(pMainDict, function.c_str()); + else + return -1; + + if (pFunc) + return 1; + else + return 0; +} + + /** * Convert Python Function to YCPCode. * @@ -643,11 +673,12 @@ //delete last 3 chars from module name ".py" module_name.erase(module_name.size()-3); + int find = findModuleFuncInDict(module_name, fun_name); + if (find) { Y2Namespace *ns = getNs (module_name.c_str(),fun_name.c_str()); if (ns) { - cout <<"ns bolo najdene!!! "<< endl; TableEntry *sym_te = ns->table ()->find (fun_name.c_str()); if (sym_te == NULL) { y2error ("No such symbol %s::%s", module_name.c_str(), fun_name.c_str()); @@ -662,6 +693,7 @@ return YCPNull(); } + } return YCPNull(); } Modified: trunk/python-bindings/src/YPython.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.h?rev=41711&r1=41710&r2=41711&view=diff ============================================================================== --- trunk/python-bindings/src/YPython.h (original) +++ trunk/python-bindings/src/YPython.h Thu Nov 1 15:59:45 2007 @@ -116,8 +116,16 @@ private: - + /** + * Find function in Global Dictionary + * confirm if function is from imported module or not + * return 1 if module is in dictionary and function too + * retrun 0 if module is in dictionary and function not + * return -1 if missing both (module and dinctionary) + **/ + + int findModuleFuncInDict(string module, string function); /** * Convert a Python list to a YCPList. Modified: trunk/python-bindings/src/YPythonNamespace.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPythonNamespace.cc?rev=41711&r1=41710&r2=41711&view=diff ============================================================================== --- trunk/python-bindings/src/YPythonNamespace.cc (original) +++ trunk/python-bindings/src/YPythonNamespace.cc Thu Nov 1 15:59:45 2007 @@ -154,7 +154,7 @@ PyObject * fun_code; //code of function //Declarations (using YPCDelcarations python module) - //YCPDeclarations *decl = YCPDeclarations::instance(); + YCPDeclarations *decl = YCPDeclarations::instance(); //YCPDeclarations *decl = new YCPDeclarations(); FunctionTypePtr sym_tp; @@ -192,7 +192,7 @@ fun_code = PyFunction_GetCode(pFunc); num = ((PyCodeObject *) fun_code)->co_argcount; - /* + if (decl->exists((PyFunctionObject *)pFunc) && decl->numParams((PyFunctionObject *)pFunc) == num){ @@ -203,14 +203,14 @@ for (int i=0; i < tmp; i++){ sym_tp->concat(list_of_types[i]); } - }else{*/ + }else{ sym_tp = new FunctionType(Type::Any); //y2milestone ("Number of parameters: %d", num); //add types and number of arguments into SymbolEntry table for (long j = 0; j < num; j++) { sym_tp->concat(Type::Any); } - //} + } //y2milestone ("Callable function %s", PyString_AsString(item)); // symbol entry for the function SymbolEntry *fun_se = new SymbolEntry ( -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org