Author: dfiser
Date: Thu Sep 27 15:34:02 2007
New Revision: 41142
URL: http://svn.opensuse.org/viewcvs/yast?rev=41142&view=rev
Log:
- Added functions for handling with YCPTypes.
- Changed Makefile.am to cover YCPTypes and dependencies implied from
that.
- YCPTypes integrated into YCP (deleted old implementation of YCP types).
- YPython was rewritten to use new YCP types and to simplify interface.
Now there is available only two methods for transformation of types between
YCP and Python, other methods for this are private.
Modified:
trunk/python-bindings/src/Makefile.am
trunk/python-bindings/src/YCP.cc
trunk/python-bindings/src/YCPTypes.cc
trunk/python-bindings/src/YCPTypes.h
trunk/python-bindings/src/YCPTypes/Path.cc
trunk/python-bindings/src/YCPTypes/Term.cc
trunk/python-bindings/src/YCPTypes/YCPTypesInternal.cc
trunk/python-bindings/src/YCPTypes/YCPTypesInternal.h
trunk/python-bindings/src/YPython.cc
trunk/python-bindings/src/YPython.h
Modified: trunk/python-bindings/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/Makefile.am?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/Makefile.am (original)
+++ trunk/python-bindings/src/Makefile.am Thu Sep 27 15:34:02 2007
@@ -13,9 +13,15 @@
# plugin, libtool forces 'lib' prefix
plugin_LTLIBRARIES = libpy2lang_python.la
-noinst_LTLIBRARIES = liby2lang_python.la
+noinst_LTLIBRARIES = libYCPTypes.la liby2lang_python.la
pythonso_LTLIBRARIES = libYCP.la
+libYCPTypes_la_SOURCES = YCPTypes.cc YCPTypes.h \
+ YCPTypes/YCPTypesInternal.cc YCPTypes/YCPTypesInternal.h \
+ YCPTypes/Path.cc \
+ YCPTypes/Symbol.cc \
+ YCPTypes/Term.cc
+
# binary part of the python module
libYCP_la_SOURCES = \
$(liby2lang_python_la_SOURCES) \
@@ -43,6 +49,8 @@
-ly2util \
-version-info 2:0
+libYCP_la_LIBADD = libYCPTypes.la
+
libpy2lang_python_la_LDFLAGS = -version-info 2:0
@@ -50,10 +58,12 @@
# the yast libraries are apparently necessary when we're loaded by python.
-libpy2lang_python_la_LIBADD = $(PYTHON_LDFLAGS) \
+libpy2lang_python_la_LDFLAGS = $(PYTHON_LDFLAGS) \
-L$(libdir) -L$(plugindir) \
-lycp -ly2 -ly2util
+libpy2lang_python_la_LIBADD = libYCPTypes.la
+
liby2lang_python_la_LIBADD = $(PYTHON_LDFLAGS)
Modified: trunk/python-bindings/src/YCP.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCP.cc?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/YCP.cc (original)
+++ trunk/python-bindings/src/YCP.cc Thu Sep 27 15:34:02 2007
@@ -24,6 +24,8 @@
#include "YPython.h"
#include "PythonLogger.h"
+#include "YCPTypes.h"
+
/**
* Store pointer to ycp module itself.
*/
@@ -148,34 +150,6 @@
PyObject *traceback;
- char class_type_code[] =
- "class YCPType:\n\
- def __init__(self, value=''):\n\
- self.type = \"any\"\n\
- self.value = value\n\
- def identity(self):\n\
- return self.type";
-
- char class_symbol_type_code[] =
- "class Symbol(YCPType):\n\
- def __init__(self, value):\n\
- self.type = \"symbol\"\n\
- self.value = value";
-
- char class_path_type_code[] =
- "class Path(YCPType):\n\
- def __init__(self, value):\n\
- self.type = \"path\"\n\
- self.value = value";
-
-
- char class_term_type_code[] =
- "class Term(YCPType):\n\
- def __init__(self, name, *args):\n\
- self.type = \"term\"\n\
- self.name = name\n\
- self.value = args";
-
char func_y2internal[] =
"def y2internal(message):\n\
file, line, func, txt = traceback.extract_stack(None, 2)[0]\n\
@@ -210,6 +184,8 @@
PyRun_SimpleString("import sys, traceback");
Self = Py_InitModule("ycp", YCPMethods);
+ initYCPTypes(Self);
+
traceback = PyImport_AddModule("traceback");
PyModule_AddObject(Self,"traceback",traceback);
@@ -218,21 +194,6 @@
PyObject *dict = PyModule_GetDict(Self);
PyObject *code;
-
-
-
- code = PyRun_String(class_type_code, Py_single_input, dict, dict);
- Py_XDECREF(code);
-
-
- code = PyRun_String(class_symbol_type_code, Py_single_input, dict, dict);
- Py_XDECREF(code);
-
- code = PyRun_String(class_path_type_code, Py_single_input, dict, dict);
- Py_XDECREF(code);
-
- code = PyRun_String(class_term_type_code, Py_single_input, dict, dict);
- Py_XDECREF(code);
code = PyRun_String(func_y2internal, Py_single_input, dict, dict);
Py_XDECREF(code);
@@ -464,11 +425,8 @@
for (int i=0; i< number_args; i++) {
pPythonValue = PyTuple_GetItem(args, i);
if (pPythonValue) {
- if (!(ypython->PythonTypeToYCPSimpleType(pPythonValue,ycpArg))) {
- ycpArg = ypython->fromPythonListToYCPList (pPythonValue);
- if (ycpArg.isNull())
- ycpArg = ypython->fromPythonDictToYCPMap (pPythonValue);
- }
+ ycpArg = ypython->PythonTypeToYCPType(pPythonValue);
+
//convert the first argument to path
if (i==0) {
if (ycpArg->isString()) {
@@ -558,11 +516,7 @@
free(temp);
- pReturnValue = ypython->YCPTypeToPythonSimpleType(ycpRetValue);
- if (!pReturnValue)
- pReturnValue = ypython->fromYCPListToPythonList(ycpRetValue);
- if (!pReturnValue)
- pReturnValue = ypython->fromYCPMapToPythonDict(ycpRetValue);
+ pReturnValue = ypython->YCPTypeToPythonType(ycpRetValue);
if (pReturnValue)
return pReturnValue;
@@ -665,15 +619,8 @@
for (int i=2; i< number_args; i++) {
pPythonValue = PyTuple_GetItem(args, i);
if (pPythonValue) {
- if (!(ypython->PythonTypeToYCPSimpleType(pPythonValue,ycpArg))) {
- ycpArg = ypython->fromPythonListToYCPList(pPythonValue);
- if (ycpArg.isNull())
- ycpArg = ypython->fromPythonDictToYCPMap(pPythonValue);
- if (ycpArg.isNull())
- ycpArg = ypython->fromPythonTupleToYCPList(pPythonValue);
- if (ycpArg.isNull())
- ycpArg = ypython->fromPythonTermToYCPTerm(pPythonValue);
- }
+ ycpArg = ypython->PythonTypeToYCPType(pPythonValue);
+
if (fun_type->parameterType(i-2)->matchvalue(ycpArg) != 0) {
y2error ("Wrong type of argumment %d",i-2);
return PyExc_TypeError;
@@ -709,16 +656,7 @@
delete []ns_name;
delete []func_name;
- pReturnValue = ypython->YCPTypeToPythonSimpleType(ycpRetValue);
- if (!pReturnValue)
- pReturnValue = ypython->fromYCPListToPythonList(ycpRetValue);
- if (!pReturnValue)
- pReturnValue = ypython->fromYCPListToPythonTuple(ycpRetValue);
- if (!pReturnValue)
- pReturnValue = ypython->fromYCPMapToPythonDict(ycpRetValue);
- if (!pReturnValue)
- pReturnValue = ypython->fromYCPTermToPythonTerm(ycpRetValue);
-
+ pReturnValue = ypython->YCPTypeToPythonType(ycpRetValue);
return pReturnValue;
Modified: trunk/python-bindings/src/YCPTypes.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCPTypes.cc?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/YCPTypes.cc (original)
+++ trunk/python-bindings/src/YCPTypes.cc Thu Sep 27 15:34:02 2007
@@ -1,4 +1,5 @@
#include "YCPTypes.h"
+#include "YCPTypes/YCPTypesInternal.h"
using std::string;
bool initYCPTypes(PyObject *module)
@@ -27,7 +28,7 @@
return false;
}
-YCPType getType(PyObject *obj)
+YCPType getYCPType(PyObject *obj)
{
if (isSymbol(obj))
return SYMBOL;
@@ -42,8 +43,7 @@
/***** Symbol *****/
bool isSymbol(PyObject *obj)
{
- if (PyInstance_Check(obj)
- && PyObject_IsInstance(obj, (PyObject *)&SymbolType))
+ if (PyObject_IsInstance(obj, (PyObject *)&SymbolType))
return true;
return false;
}
@@ -55,14 +55,27 @@
}
return string();
}
+
+PyObject *Symbol_New(PyObject *value)
+{
+ return YCPTypeString_New(value, &SymbolType);
+}
+
+PyObject *Symbol_NewString(const char *value)
+{
+ PyObject *val = Py_BuildValue("s", value);
+ PyObject *ret = Symbol_New(val);
+ Py_DECREF(val);
+
+ return ret;
+}
/***** Symbol END *****/
/***** Path *****/
bool isPath(PyObject *obj)
{
- if (PyInstance_Check(obj)
- && PyObject_IsInstance(obj, (PyObject *)&PathType))
+ if (PyObject_IsInstance(obj, (PyObject *)&PathType))
return true;
return false;
}
@@ -74,14 +87,27 @@
}
return string();
}
+
+PyObject *Path_New(PyObject *value)
+{
+ return YCPTypeString_New(value, &PathType);
+}
+
+PyObject *Path_NewString(const char *value)
+{
+ PyObject *val = Py_BuildValue("s", value);
+ PyObject *ret = Path_New(val);
+ Py_DECREF(val);
+
+ return ret;
+}
/***** Path END *****/
/***** Term *****/
bool isTerm(PyObject *obj)
{
- if (PyInstance_Check(obj)
- && PyObject_IsInstance(obj, (PyObject *)&TermType))
+ if (PyObject_IsInstance(obj, (PyObject *)&TermType))
return true;
return false;
}
@@ -101,5 +127,62 @@
}
return Py_None;
}
+
+
+PyObject *Term_New(PyObject *name, PyObject *value)
+{
+ PyObject *ret;
+ PyObject *args;
+ int size, i;
+ PyObject *tmp;
+
+ if (!PyTuple_Check(value) || !PyString_Check(name)){
+ return Py_None;
+ }
+
+ // create args variable
+ size = PyTuple_Size(value);
+ args = PyTuple_New(size + 1);
+ Py_INCREF(name);
+ if (PyTuple_SetItem(args, 0, name) != 0){
+ Py_XDECREF(args);
+ Py_DECREF(name);
+ return Py_None;
+ }
+ for (i=1; i < size + 1; i++){
+ tmp = PyTuple_GetItem(value, i-1);
+ Py_INCREF(tmp);
+ if (PyTuple_SetItem(args, i, tmp) != 0){
+ Py_XDECREF(args);
+ Py_DECREF(tmp);
+ return Py_None;
+ }
+ }
+
+ // create new object
+ ret = Term_new(&TermType, Py_None, Py_None);
+ if (ret == NULL){
+ Py_XDECREF(args);
+ return Py_None;
+ }
+
+ // initialize object
+ if (Term_init((Term *)ret, args, Py_None) == -1){
+ Py_XDECREF(args);
+ return Py_None;
+ }
+
+ Py_XDECREF(args);
+ return ret;
+}
+
+PyObject *Term_NewString(const char *name, PyObject *value)
+{
+ PyObject *nam = Py_BuildValue("s", name);
+ PyObject *ret = Term_New(nam, value);
+ Py_DECREF(nam);
+
+ return ret;
+}
/***** Term END *****/
Modified: trunk/python-bindings/src/YCPTypes.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCPTypes.h?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/YCPTypes.h (original)
+++ trunk/python-bindings/src/YCPTypes.h Thu Sep 27 15:34:02 2007
@@ -24,6 +24,13 @@
bool isSymbol(PyObject *);
std::string Symbol_getValue(Symbol *);
+/**
+ * Return new object created from str.
+ * Return New Reference!
+ */
+PyObject *Symbol_New(PyObject *str);
+PyObject *Symbol_NewString(const char *);
+
/**
* Path
@@ -34,6 +41,9 @@
bool isPath(PyObject *);
std::string Path_getValue(Path *);
+PyObject *Path_New(PyObject *str);
+PyObject *Path_NewString(const char *);
+
/**
* Term
@@ -56,6 +66,9 @@
*/
PyObject *Term_getValue(Term *);
+PyObject *Term_New(PyObject *name, PyObject *list_value);
+PyObject *Term_NewString(const char *name, PyObject *list_value);
+
/**
* Initialize alll YCP types
@@ -75,6 +88,6 @@
* }
*/
enum YCPType { NOT_YCP_TYPE, PATH, SYMBOL, TERM };
-YCPType getType(PyObject *);
+YCPType getYCPType(PyObject *);
#endif
Modified: trunk/python-bindings/src/YCPTypes/Path.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCPTypes/Path.cc?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/YCPTypes/Path.cc (original)
+++ trunk/python-bindings/src/YCPTypes/Path.cc Thu Sep 27 15:34:02 2007
@@ -2,37 +2,6 @@
using std::string;
/**
- * Returns new Path object created from string str.
- * Returns New Reference!
- */
-static PyObject *Path_StringNew(const char *str)
-{
- PyObject *ret;
- PyObject *args;
-
- // create args variable
- args = Py_BuildValue("(s)", str);
-
- // create new Path object
- ret = YCPTypeString_new(&PathType, Py_None, Py_None);
- if (ret == NULL){
- Py_XDECREF(args);
- return Py_None;
- }
-
- // initialize Path object
- if (YCPTypeString_init((YCPTypeString *)ret, args, Py_None) == -1){
- Py_XDECREF(args);
- return Py_None;
- }
-
- Py_XDECREF(args);
- return ret;
-}
-
-
-
-/**
* Compare two Path objects.
* If obj1 or obj2 are not Paths returns -1 (it means not equal)
*/
@@ -75,7 +44,7 @@
new_value += ".";
new_value += str;
- return Path_StringNew(new_value.c_str());
+ return Path_NewString(new_value.c_str());
}
/**
@@ -96,7 +65,7 @@
new_value += ".";
new_value += PyString_AsString(self->value);
- return Path_StringNew(new_value.c_str());
+ return Path_NewString(new_value.c_str());
}
static PyMethodDef Path_methods[] = {
Modified: trunk/python-bindings/src/YCPTypes/Term.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCPTypes/Term.cc?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/YCPTypes/Term.cc (original)
+++ trunk/python-bindings/src/YCPTypes/Term.cc Thu Sep 27 15:34:02 2007
@@ -14,7 +14,7 @@
* This function is called before Term_init.
* In this function is set only default values.
*/
-static PyObject *Term_new(PyTypeObject *type, PyObject *args,
+PyObject *Term_new(PyTypeObject *type, PyObject *args,
PyObject *kwds)
{
Term *self;
@@ -83,7 +83,7 @@
/**
* Returns hash of Term object.
*/
-long Term_hash(Term *self)
+static long Term_hash(Term *self)
{
if (self->hash != -1){
self->hash = PyObject_Hash(self->name) + PyObject_Hash(self->value);
Modified: trunk/python-bindings/src/YCPTypes/YCPTypesInternal.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCPTypes/YCPTypesInternal.cc?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/YCPTypes/YCPTypesInternal.cc (original)
+++ trunk/python-bindings/src/YCPTypes/YCPTypesInternal.cc Thu Sep 27 15:34:02 2007
@@ -50,3 +50,38 @@
}
return self->hash;
}
+
+PyObject *YCPTypeString_New(PyObject *value, PyTypeObject *type)
+{
+ PyObject *ret;
+ PyObject *args;
+
+ if (!PyString_Check(value)){
+ return Py_None;
+ }
+
+ // create args variable
+ args = PyTuple_New(1);
+ Py_INCREF(value);
+ if (PyTuple_SetItem(args, 0, value) != 0){
+ Py_XDECREF(args);
+ Py_DECREF(value);
+ }
+
+ // create new Path object
+ ret = YCPTypeString_new(type, Py_None, Py_None);
+ if (ret == NULL){
+ Py_XDECREF(args);
+ return Py_None;
+ }
+
+ // initialize Path object
+ if (YCPTypeString_init((YCPTypeString *)ret, args, Py_None) == -1){
+ Py_XDECREF(args);
+ return Py_None;
+ }
+
+ Py_XDECREF(args);
+ return ret;
+}
+
Modified: trunk/python-bindings/src/YCPTypes/YCPTypesInternal.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCPTypes/YCPTypesInternal.h?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/YCPTypes/YCPTypesInternal.h (original)
+++ trunk/python-bindings/src/YCPTypes/YCPTypesInternal.h Thu Sep 27 15:34:02 2007
@@ -29,4 +29,13 @@
*/
long YCPTypeString_hash(YCPTypeString *self);
+/**
+ * Return new object that has type type.
+ */
+PyObject *YCPTypeString_New(PyObject *str, PyTypeObject *type);
+
+
+
+PyObject *Term_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
+int Term_init(Term *self, PyObject *args, PyObject *kwds);
#endif
Modified: trunk/python-bindings/src/YPython.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.cc?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/YPython.cc (original)
+++ trunk/python-bindings/src/YPython.cc Thu Sep 27 15:34:02 2007
@@ -1,7 +1,7 @@
/*---------------------------------------------------------------------\
-| |
-| __ __ ____ _____ ____ |
-| \ \ / /_ _/ ___|_ _|___ \ |
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
| \ V / _` \___ \ | | __) | |
| | | (_| |___) || | / __/ |
| |_|\__,_|____/ |_| |_____| |
@@ -47,29 +47,19 @@
#include
#include
#include
-YPython * YPython::_yPython = 0;
-
-YPython::YPython() {
- PyObject* pMain;
- PyObject* pMainDict;
- pMain = PyImport_AddModule("__main__");
- PyRun_SimpleString("from ycp import *");
- pMainDict = PyModule_GetDict(pMain);
- pPathClass = PyDict_GetItemString(pMainDict, "Path");
- pSymbolClass = PyDict_GetItemString(pMainDict, "Symbol");
- pTermClass = PyDict_GetItemString(pMainDict, "Term");
-
-}
+#include "YCPTypes.h"
+#include <iostream>
+#define DBG(str) \
+ std::cerr << __FILE__ << ": " << __LINE__ << ": " << str << std::endl; \
+ std::cerr.flush()
+YPython * YPython::_yPython = 0;
-YPython::~YPython() {
+YPython::YPython(){}
- Py_CLEAR(pPathClass);
- Py_CLEAR(pSymbolClass);
- Py_CLEAR(pTermClass);
-}
+YPython::~YPython(){}
YPython *
@@ -113,7 +103,7 @@
* evaluate of function from python
* @param string name of module
* @param string name of function
- * @param bool is it method?
+ * @param bool is it method? TODO !!
* @param YCPList argumnets from YCP to python function(0 - dummy)
* @return YCPValue return value from python's function
*/
@@ -121,441 +111,311 @@
YPython::callInner (string module, string function, bool method,
YCPList argList)
{
-
+ PyObject* pMain;
+ PyObject* pMainDict;
+ PyObject* pFunc;
+ PyObject* pArgs;
+ PyObject* pReturn;
+ YCPValue result = YCPNull ();
- PyObject* pMain;
- PyObject* pMainDict;
- PyObject* pFunc;
- PyObject* pArgs;
- PyObject* pReturn;
-
- YCPValue result = YCPNull ();
-
-
- pMain = PyImport_AddModule("__main__");
- //PyRun_SimpleString("import __main__");
- pMainDict = PyModule_GetDict(pMain);
-
-
-
- pFunc = PyDict_GetItemString(pMainDict, function.c_str());
-
-
- pArgs = PyTuple_New(argList->size()-1);
-
- PyObject *pArg;
- //Parsing argumments
-
- y2milestone ("name of function %s and nuber of arguments %d", function.c_str(), argList->size()-1);
-
- for ( int i=1; i < argList->size(); i++ ) {
- //FIXME add checking for all types from YCP and conversion to python types...
-
- pArg = YCPTypeToPythonSimpleType(argList->value(i));
-
- if (!pArg)
- pArg = fromYCPListToPythonList(argList->value(i));
-
- if (!pArg)
- pArg = fromYCPListToPythonTuple(argList->value(i));
-
- if (!pArg)
- pArg = fromYCPMapToPythonDict(argList->value(i));
- if (!pArg)
- pArg = fromYCPTermToPythonTerm(argList->value(i));
-
- PyTuple_SetItem(pArgs,i-1, pArg);
-
- }
-
-
- pReturn = PyObject_CallObject(pFunc, pArgs);
-
- Py_CLEAR(pArgs);
-
-
-
- if (pReturn) {
- //result = YCPInteger(PyInt_AsLong(pReturn)); //new YCPValue();
-
- if (!PythonTypeToYCPSimpleType(pReturn, result))
- result = fromPythonTupleToYCPList(pReturn);
-
- if (result.isNull())
- result = fromPythonListToYCPList (pReturn);
-
- if (result.isNull())
- result = fromPythonDictToYCPMap (pReturn);
-
- if (result.isNull())
- result = fromPythonTermToYCPTerm(pReturn);
-
-
- }
- Py_CLEAR(pReturn);
-
- if (result.isNull ()) {
- y2error ("Result is NULL when returning from %s", function.c_str());
- result = YCPVoid ();
- }
-
- return result;
-}
-
-
- /**
- * Transfer from python simple type to ycp simple type
- * transfered are: boolean, integer, string, float,
- **/
-bool YPython::PythonTypeToYCPSimpleType(PyObject* pPythonValue, YCPValue &out) {
- PyObject * value;
- // boolean value handling
- if (PyBool_Check(pPythonValue)) {
- PyObject * true_value = PyBool_FromLong(1);
- int compare = PyObject_Compare(pPythonValue, true_value);
- if (compare == 0) {
- out = YCPBoolean (true);
- } else if (compare < 1) {
- out = YCPBoolean (false);
- } else {
- return false;
- }
- return true;
- }
-
- //integer value handling
- if (PyInt_Check(pPythonValue)) {
-
- out = YCPInteger(PyInt_AsLong(pPythonValue));
- return true;
- }
-
- //float value handling
- if (PyFloat_Check(pPythonValue)) {
-
- out = YCPFloat(PyFloat_AsDouble(pPythonValue));
- return true;
- }
-
- //string value handling
- if (PyString_Check(pPythonValue)) {
-
- out = YCPString(PyString_AsString(pPythonValue));
- return true;
- }
-
- if (pPythonValue == Py_None) {
- out = YCPNull();
- return true;
- }
-
- if (PyInstance_Check(pPythonValue)) {
- if (PyObject_HasAttrString(pPythonValue, "type")) {
- PyObject * py_attr = PyObject_GetAttrString(pPythonValue,"type");
- if (PyString_Check(py_attr)) {
- string type = PyString_AsString(py_attr);
- if (type.compare("symbol") == 0) {
- value = PyObject_GetAttrString(pPythonValue,"value");
- out = YCPSymbol(PyString_AsString(value));
- return true;
- }
- if (type.compare("path") == 0) {
- value = PyObject_GetAttrString(pPythonValue,"value");
- out = YCPPath(PyString_AsString(value));
- return true;
- }
- } //end of if (PyString_Check(py_attr))
- } //end of if (PyObject_HasAttrString(pPythonValue, "type"))
- }
- return false;
-}
-
- /**
- * Transfer from ycp simple type to python simple type
- * transfered are: boolean, integer, string, float,
- **/
-PyObject* YPython::YCPTypeToPythonSimpleType(YCPValue in) {
-
- if (in.isNull()) {
- return Py_None;
-
- } else if (in->isBoolean()) {
- long val = 0;
- bool true_false = in->asBoolean()->value();
- true_false ? val = 1 : val =0;
- return PyBool_FromLong(val);
-
- } else if (in->isInteger()) {
- return PyInt_FromLong(in->asInteger()->value());
-
- } else if (in->isFloat()) {
- double val = in->asFloat()->value();
- return PyFloat_FromDouble(val);
-
- } else if (in->isString()) {
- return PyString_FromString((in->asString()->value()).c_str());
-
- } else if (in->isVoid()) {
- return Py_None;
-
- } else if (in->isPath()) {
- if (pPathClass) {
- PyObject *value = PyString_FromString(in->asPath()->toString().c_str());
- PyObject *pyArgs = PyTuple_New(1);
- PyTuple_SetItem(pyArgs, 0, value);
- return PyInstance_New(pPathClass, pyArgs, NULL);
+ pMain = PyImport_AddModule("__main__");
+ //PyRun_SimpleString("import __main__");
+ pMainDict = PyModule_GetDict(pMain);
+ pFunc = PyDict_GetItemString(pMainDict, function.c_str());
+ pArgs = PyTuple_New(argList->size()-1);
- } else {
- return Py_None;
- }
- } else if (in->isSymbol()) {
- if (pSymbolClass) {
- //add hack delete first char (`) from output
- PyObject *value = PyString_FromString(in->asSymbol()->toString().erase(0,1).c_str());
- PyObject *pyArgs = PyTuple_New(1);
- PyTuple_SetItem(pyArgs, 0, value);
- return PyInstance_New(pSymbolClass, pyArgs, NULL);
+ //Parsing argumments
+ PyObject *pArg;
+ y2milestone ("name of function %s and number of arguments %d", function.c_str(), argList->size()-1);
+ for ( int i=1; i < argList->size(); i++ ) {
+ pArg = YCPTypeToPythonType(argList->value(i));
+ PyTuple_SetItem(pArgs,i-1, pArg);
+ }
+
+ pReturn = PyObject_CallObject(pFunc, pArgs);
+
+ Py_CLEAR(pArgs);
+
+ if (pReturn){
+ result = PythonTypeToYCPType(pReturn); // create YCP value
+ }else
+ y2error("pReturn == 0");
+ Py_CLEAR(pReturn);
+
+ if (result.isNull ()) {
+ y2error ("Result is NULL when returning from %s", function.c_str());
+ result = YCPVoid ();
+ }
+
+ return result;
+}
+
+
+YCPValue YPython::PythonTypeToYCPType(PyObject *pythonValue)
+{
+ // null (in python None)
+ if (pythonValue == Py_None)
+ return YCPNull();
+
+ //boolean
+ if (PyBool_Check(pythonValue)){
+ int cmp_result = PyObject_Compare(pythonValue, Py_True);
+ if (PyErr_Occurred() != NULL){
+ return YCPNull();
+ }
+ if (cmp_result == 0){
+ return YCPBoolean(true);
+ }else{
+ return YCPBoolean(false);
+ }
+ }
+
+ // integer
+ if (PyInt_Check(pythonValue))
+ return YCPInteger(PyInt_AsLong(pythonValue));
+
+ //float
+ if (PyFloat_Check(pythonValue))
+ return YCPFloat(PyFloat_AsDouble(pythonValue));
+
+ //string
+ if (PyString_Check(pythonValue))
+ return YCPString(PyString_AsString(pythonValue));
+
+ //list
+ if (PyList_Check(pythonValue))
+ return fromPythonListToYCPList(pythonValue);
+
+ //tuple -> list
+ if (PyTuple_Check(pythonValue))
+ return fromPythonTupleToYCPList(pythonValue);
+
+ //dict -> map
+ if (PyDict_Check(pythonValue))
+ return fromPythonDictToYCPMap(pythonValue);
- } else {
+ // term, symbol, path
+ switch (getYCPType(pythonValue)){
+ case SYMBOL:
+ return YCPSymbol(Symbol_getValue((Symbol *)pythonValue));
+ case PATH:
+ return YCPPath(Path_getValue((Path *)pythonValue));
+ case TERM:
+ return fromPythonTermToYCPTerm(pythonValue);
+ case NOT_YCP_TYPE:
+ return YCPNull();
+ }
+
+ return YCPNull();
+}
+
+
+PyObject *YPython::YCPTypeToPythonType(YCPValue value)
+{
+ // null -> None
+ if (value.isNull())
+ return Py_None;
+ //void -> None
+ if (value->isVoid())
return Py_None;
- }
- } else
- return NULL;
+
+ // boolean
+ if (value->isBoolean()){
+ if (value->asBoolean()->value())
+ return PyBool_FromLong(1);
+ return PyBool_FromLong(0);
+ }
+
+ //integer
+ if (value->isInteger())
+ return PyInt_FromLong(value->asInteger()->value());
+
+ //float
+ if (value->isFloat())
+ return PyFloat_FromDouble(value->asFloat()->value());
+
+ //string
+ if (value->isString())
+ return PyString_FromString(value->asString()->value().c_str());
+
+ //list -> tuple
+ if (value->isList())
+ return fromYCPListToPythonTuple(value->asList());
+
+ //map -> dict
+ if (value->isMap())
+ return fromYCPMapToPythonDict(value->asMap());
+
+ //path
+ if (value->isPath())
+ return Path_NewString(value->asPath()->toString().c_str());
+
+ //symbol
+ if (value->isSymbol())
+ return Symbol_NewString(value->asSymbol()->toString().erase(0,1).c_str());
+
+ //term
+ if (value->isTerm())
+ return fromYCPTermToPythonTerm(value->asTerm());
+
+ return Py_None;
}
+
+
+
+
+/********** PRIVATE: **********/
+
/**
* Convert a Python list to a YCPList.
**/
-
YCPList YPython::fromPythonListToYCPList (PyObject* pPythonList) {
- YCPList ycp_List;
- PyObject * pItem;
- YCPValue ycp_value;
- //checking for list (is it really list?)
- if (PyList_Check(pPythonList) > 0) {
- int list_size = PyList_Size(pPythonList);
- for (int i = 0; i < list_size; i++) {
- pItem = PyList_GetItem(pPythonList, i);
- if (PythonTypeToYCPSimpleType(pItem, ycp_value)) {
+ YCPList ycp_List;
+ PyObject * pItem;
+ YCPValue ycp_value;
+
+ //checking for list (is it really list?)
+ if (PyList_Check(pPythonList) > 0) {
+ int list_size = PyList_Size(pPythonList);
+ for (int i = 0; i < list_size; i++) {
+ pItem = PyList_GetItem(pPythonList, i);
+ ycp_value = PythonTypeToYCPType(pItem);
+
if (!ycp_value.isNull ()) {
- ycp_List->add(ycp_value);
+ ycp_List->add(ycp_value);
} else {
- return YCPNull ();
+ return YCPNull ();
}
- } else { //end of if (PythonTypeToYCPSimpleType(item, ycp_value))
- ycp_value = fromPythonListToYCPList(pItem);
- if (ycp_value.isNull ())
- ycp_value = fromPythonDictToYCPMap (pItem);
- if (ycp_value.isNull ())
- ycp_value = fromPythonTupleToYCPList(pItem);
- if (ycp_value.isNull ())
- ycp_value = fromPythonTermToYCPTerm(pItem);
-
- if (!ycp_value.isNull ())
- ycp_List->add(ycp_value);
- else
- return YCPNull ();
- } // end of else for if (PythonTypeToYCPSimpleType(item, ycp_value))
- } //end of for (int i = 0; i < list_size; i++)
- } else { //end if (PyList_Check(pPythonList) > 0)
- y2milestone ("Value is not Python List");
- return YCPNull ();
- } //end else of if (PyList_Check(pPythonList) > 0)
+ }
+ }else{
+ y2milestone ("Value is not Python List");
+ return YCPNull ();
+ }
- return ycp_List;
+ return ycp_List;
}
/**
* Convert a Python Tuple to a YCPList.
**/
YCPList YPython::fromPythonTupleToYCPList (PyObject* pPythonTuple) {
- YCPList ycp_List;
- PyObject * pItem;
- YCPValue ycp_value;
- //checking for list (is it really list?)
- if (PyTuple_Check(pPythonTuple) > 0) {
- int list_size = PyTuple_Size(pPythonTuple);
- for (int i = 0; i < list_size; i++) {
- pItem = PyTuple_GetItem(pPythonTuple, i);
- if (PythonTypeToYCPSimpleType(pItem, ycp_value)) {
+ YCPList ycp_List;
+ PyObject * pItem;
+ YCPValue ycp_value;
+
+ //checking for list (is it really list?)
+ if (PyTuple_Check(pPythonTuple) > 0) {
+ int list_size = PyTuple_Size(pPythonTuple);
+ for (int i = 0; i < list_size; i++) {
+ pItem = PyTuple_GetItem(pPythonTuple, i);
+ ycp_value = PythonTypeToYCPType(pItem);
+
if (!ycp_value.isNull ()) {
- ycp_List->add(ycp_value);
+ ycp_List->add(ycp_value);
} else {
- return YCPNull ();
- }
- } else { //end of if (PythonTypeToYCPSimpleType(item, ycp_value))
- ycp_value = fromPythonListToYCPList(pItem);
-
- if (ycp_value.isNull ())
- ycp_value = fromPythonTupleToYCPList(pItem);
-
- if (ycp_value.isNull ())
- ycp_value = fromPythonDictToYCPMap(pItem);
-
- if (ycp_value.isNull ())
- ycp_value = fromPythonTermToYCPTerm(pItem);
-
- if (!ycp_value.isNull ())
- ycp_List->add(ycp_value);
- else
return YCPNull ();
- } // end of else for if (PythonTypeToYCPSimpleType(item, ycp_value))
- } //end of for (int i = 0; i < list_size; i++)
- } else { //end if (PyTuple_Check(pPythonList) > 0)
- y2milestone ("Value is not Python Tuple");
- return YCPNull ();
- } //end else of if (PyTuple_Check(pPythonList) > 0)
+ }
+ }
+ }else{
+ y2milestone ("Value is not Python Tuple");
+ return YCPNull ();
+ }
- return ycp_List;
+ return ycp_List;
}
/**
* Convert a YCPList to a Python list.
**/
PyObject* YPython::fromYCPListToPythonList (YCPValue ycp_List) {
+ PyObject* pPythonList;
+ PyObject* pItem;
+ int ret = 0;
- PyObject* pPythonList;
- PyObject* pItem;
- int ret = 0;
- if (ycp_List->isList()) {
- if (ycp_List->asList()->size()>0)
+ if (ycp_List->isList()) {
pPythonList = PyList_New(ycp_List->asList()->size());
- else {
- y2error("YCP list is empty.");
- return Py_None;
- }
- y2milestone ("Size of list %d",ycp_List->asList()->size());
- for ( int i = 0; i < ycp_List->asList()->size(); i++ ) {
- pItem = YCPTypeToPythonSimpleType(ycp_List->asList()->value(i));
- if (!pItem)
- pItem = fromYCPListToPythonList(ycp_List->asList()->value(i));
+ y2milestone ("Size of list %d",ycp_List->asList()->size());
+ for ( int i = 0; i < ycp_List->asList()->size(); i++ ) {
+ pItem = YCPTypeToPythonType(ycp_List->asList()->value(i));
+ ret = PyList_SetItem(pPythonList, i, pItem);
- if (!pItem)
- pItem = fromYCPListToPythonTuple(ycp_List->asList()->value(i));
-
- if (!pItem)
- pItem = fromYCPMapToPythonDict(ycp_List->asList()->value(i));
-
- if (!pItem)
- pItem = fromYCPTermToPythonTerm(ycp_List->asList()->value(i));
-
- ret = PyList_SetItem(pPythonList, i, pItem);
-
- if (ret <0)
- y2error("PyList_SetItem doesn't add item into python list.");
-
- }
- Py_INCREF(pPythonList);
- return pPythonList;
+ if (ret <0)
+ y2error("PyList_SetItem doesn't add item into python list.");
+ }
+ Py_INCREF(pPythonList); //TODO: Review this - is it really needed? PyList_New returns New Reference.
+ return pPythonList;
- } else {
- y2milestone ("Value is not YCPList");
- return NULL;
- }
+ } else {
+ y2milestone ("Value is not YCPList");
+ return Py_None;
+ }
}
/**
* Convert a YCPList to a Python tuple.
**/
PyObject* YPython::fromYCPListToPythonTuple (YCPValue ycp_List) {
+ PyObject* pPythonTuple;
+ PyObject* pItem;
+ int ret = 0;
- PyObject* pPythonTuple;
- PyObject* pItem;
- int ret = 0;
- if (ycp_List->isList()) {
- if (ycp_List->asList()->size()>0)
+ if (ycp_List->isList()) {
pPythonTuple = PyTuple_New(ycp_List->asList()->size());
- else {
- y2error("YCP list is empty.");
- return Py_None;
- }
- y2milestone ("Size of list %d",ycp_List->asList()->size());
- for ( int i = 0; i < ycp_List->asList()->size(); i++ ) {
- pItem = YCPTypeToPythonSimpleType(ycp_List->asList()->value(i));
-
- if (!pItem)
- pItem = fromYCPListToPythonList(ycp_List->asList()->value(i));
-
- if (!pItem)
- pItem = fromYCPListToPythonTuple(ycp_List->asList()->value(i));
-
- if (!pItem)
- pItem = fromYCPMapToPythonDict(ycp_List->asList()->value(i));
-
- if (!pItem)
- pItem = fromYCPTermToPythonTerm(ycp_List->asList()->value(i));
- ret = PyTuple_SetItem(pPythonTuple, i, pItem);
+ y2milestone ("Size of list %d",ycp_List->asList()->size());
+ for ( int i = 0; i < ycp_List->asList()->size(); i++ ) {
+ pItem = YCPTypeToPythonType(ycp_List->asList()->value(i));
+ ret = PyTuple_SetItem(pPythonTuple, i, pItem);
- if (ret <0)
- y2error("PyList_SetItem doesn't add item into python list.");
-
- }
- Py_INCREF(pPythonTuple);
- return pPythonTuple;
+ if (ret <0)
+ y2error("PyList_SetItem doesn't add item into python list.");
+ }
+ Py_INCREF(pPythonTuple); //TODO: Review this.
+ return pPythonTuple;
- } else {
- y2milestone ("Value is not YCPList");
- return NULL;
- }
+ } else {
+ y2milestone ("Value is not YCPList");
+ return NULL;
+ }
}
/**
* Convert a YCPMap to a Python Dictionary.
+ * If something goes wrong, iteration is trying proceed...
**/
PyObject* YPython::fromYCPMapToPythonDict (YCPValue ycp_Map) {
+ PyObject* pPythonDict;
+ PyObject* pKey;
+ PyObject* pValue;
+ int ret = -1;
- PyObject* pPythonDict;
- PyObject* pKey;
- PyObject* pValue;
- int ret = -1;
- if (ycp_Map->isMap()) {
- if (ycp_Map->asMap()->size()>0) {
+ if (ycp_Map->isMap()) {
pPythonDict = PyDict_New();
+
for (YCPMapIterator it = ycp_Map->asMap()->begin(); it != ycp_Map->asMap()->end(); ++it ) {
- pKey = YCPTypeToPythonSimpleType(it.key());
- if (!pKey) {
- y2error("Transfer key YCPMap to PyObject falsed.");
- return NULL;
- }
- pValue = YCPTypeToPythonSimpleType(it.value());
- if (!pValue)
- pValue = fromYCPListToPythonList(it.value());
- if (!pValue)
- pValue = fromYCPListToPythonTuple(it.value());
- if (!pValue)
- pValue = fromYCPMapToPythonDict(it.value());
- if (!pValue)
- pValue = fromYCPTermToPythonTerm(it.value());
-
-
- if (pValue) {
- ret = PyDict_SetItem(pPythonDict, pKey, pValue);
- if (ret < 0) {
- y2error("Adding value and key from YCPMap to Python Dictionary falsed.");
- return NULL;
- }
- } else {
- y2error("Transfer value from YCPMap to PyObject falsed.");
- return NULL;
-
- }
- } // end of for (YCPMapIterator it = ycp_Map->begin(); it != ycp_Map->end(); ++it )
+ pKey = YCPTypeToPythonType(it.key());
+ pValue = YCPTypeToPythonType(it.value());
- } else { // end if (ycp_Map->asMap()->size()>0)
- y2error("YCP map is empty.");
- return NULL;
- } // end else of if (ycp_Map->asMap()->size()>0)
+ if (pValue && pKey){
+ ret = PyDict_SetItem(pPythonDict, pKey, pValue);
+
+ if (ret < 0)
+ y2error("Adding value and key from YCPMap to Python Dictionary falsed.");
+ }else{
+ y2error("Transformation key and/or value to python type failed.");
+ }
+ }
+ }else{
+ y2milestone ("Value is not YCPMap");
+ return Py_None;
+ }
- } else { // end if (ycp_Map->isMap())
- y2milestone ("Value is not YCPMap");
- return NULL;
- } // end else of if (ycp_Map->isMap())
- Py_INCREF(pPythonDict);
- return pPythonDict;
+ Py_INCREF(pPythonDict);// TODO: Review this
+ return pPythonDict;
}
@@ -563,140 +423,75 @@
* Convert a Python Dictionary to a YCPMap.
**/
YCPMap YPython::fromPythonDictToYCPMap (PyObject* pPythonDict) {
+ YCPValue ycp_key;
+ YCPValue ycp_value;
+ YCPMap ycp_Map;
+
+ if (PyDict_Check(pPythonDict)>0) {
+ if (PyDict_Size(pPythonDict) == 0)
+ return ycp_Map;
+
+ PyObject *key, *value;
+ Py_ssize_t pos = 0;
+
+ while (PyDict_Next(pPythonDict, &pos, &key, &value)) {
+ ycp_key = PythonTypeToYCPType(key);
+ ycp_value = PythonTypeToYCPType(value);
- PyObject* pListKeys;
- PyObject* pListValues;
- YCPValue ycp_key;
- YCPValue ycp_value;
- YCPMap ycp_Map;
- if (PyDict_Check(pPythonDict)>0) {
- if (PyDict_Size(pPythonDict)>0) {
- pListKeys = PyDict_Keys(pPythonDict);
- pListValues = PyDict_Values(pPythonDict);
- for (int i=0; i < PyList_Size(pListKeys); i++) {
- if (PythonTypeToYCPSimpleType(PyList_GetItem(pListKeys, i),ycp_key)) {
- if (PythonTypeToYCPSimpleType(PyList_GetItem(pListValues, i),ycp_value)) {
- ycp_Map->add (ycp_key, ycp_value);
- } else {
- ycp_value = fromPythonListToYCPList(PyList_GetItem(pListValues, i));
- if (ycp_value.isNull ())
- ycp_value = fromPythonTupleToYCPList(PyList_GetItem(pListValues, i));
- if (ycp_value.isNull ())
- ycp_value = fromPythonDictToYCPMap (PyList_GetItem(pListValues, i));
- if (ycp_value.isNull ())
- ycp_value = fromPythonTermToYCPTerm(PyList_GetItem(pListValues, i));
-
- ycp_Map->add (ycp_key, ycp_value);
- }
+ ycp_Map->add(ycp_key, ycp_value);
+ }
+ }else{
+ y2milestone ("Value is not python dictionary");
+ return YCPNull();
+ }
- } else {
- y2error("Cannot convert key from python dictionary");
- return YCPNull ();
- }
- }
-
- } else {
- y2milestone ("Python dictionary is empty");
- return YCPNull ();
- }
- } else {
- y2milestone ("Value is not python dictionary");
- return YCPNull ();
- }
- return ycp_Map;
+ return ycp_Map;
}
+
/**
* Convert a Python Term to a YCPTerm.
+ * Argument should be Term!
**/
+YCPTerm YPython::fromPythonTermToYCPTerm (PyObject* pythonTerm) {
+ PyObject *value;
+ string name;
+ YCPValue ycp_value;
+
+ if (!isTerm(pythonTerm)){
+ y2error("Argument is not Term!");
+ return YCPNull();
+ }
+
+ name = Term_getName((Term *)pythonTerm);
+ value = Term_getValue((Term *)pythonTerm);
+ ycp_value = fromPythonTupleToYCPList(value);
-YCPTerm YPython::fromPythonTermToYCPTerm (PyObject* pPythonTerm) {
- PyObject *value;
- PyObject *pyName;
- string name;
- YCPValue ycp_value;
-
- if (PyInstance_Check(pPythonTerm)) {
- if (PyObject_HasAttrString(pPythonTerm, "type")) {
- PyObject * py_attr = PyObject_GetAttrString(pPythonTerm,"type");
- if (PyString_Check(py_attr)) {
- string type = PyString_AsString(py_attr);
- if (type.compare("term") == 0) {
- pyName = PyObject_GetAttrString(pPythonTerm,"name");
- if (PyString_Check(pyName)) {
- name = PyString_AsString(pyName);
- value = PyObject_GetAttrString(pPythonTerm,"value");
- if (PyTuple_Check(value))
-
- ycp_value = fromPythonTupleToYCPList(value);
-
- if (!ycp_value.isNull ()) {
- //printf("term is: %s\n",YCPTerm(name,ycp_value->asList())->toString().c_str());
- return YCPTerm(name,ycp_value->asList());
-
- } else {
- y2error("Value was not converted to YCPTerm");
- return YCPNull ();
- }
- } else {
- y2error ("The name of Term is not string");
- return YCPNull ();
- }
- } else {
- y2milestone ("Value is not python Term");
- return YCPNull ();
- }
- } else {
- y2error ("Value is not any python class for ycp types");
- return YCPNull ();
- }
- }
- } else {
- return YCPNull ();
- }
- return YCPNull ();
+ if (!ycp_value.isNull())
+ return YCPTerm(name, ycp_value->asList());
+
+ return YCPNull();
}
/**
* Convert a YCPTerm to a Python Term.
+ * Given argument should be term!
**/
PyObject* YPython::fromYCPTermToPythonTerm (YCPValue ycp_Term) {
+ PyObject *value;
- PyObject* pPythonTerm;
- PyObject* pName;
- PyObject* pValue;
-
- if (ycp_Term->isTerm()) {
- if (ycp_Term->asTerm()->args()->size()>0) {
- pName = PyString_FromString(ycp_Term->asTerm()->name().c_str());
- YCPValue list = ycp_Term->asTerm()->args();
- pValue = fromYCPListToPythonTuple(list);
- if (pValue) {
- if (pTermClass) {
- PyObject *pyArgs = PyTuple_New(2);
- PyTuple_SetItem(pyArgs, 0, pName);
- PyTuple_SetItem(pyArgs, 1, pValue);
- pPythonTerm = PyInstance_New(pTermClass, pyArgs, NULL);
- } else {
- y2error("There is missing Term class in python");
- return Py_None;
- }
- } else {
- y2error("Converting to python tuple failed");
- return Py_None;
- }
-
- } else { // end if (ycp_Map->asMap()->size()>0)
- y2error("YCP term is empty.");
- return NULL;
- } // end else of if (ycp_Map->asMap()->size()>0)
+ if (!ycp_Term->isTerm()){
+ y2error("Argument is not term!");
+ return Py_None;
+ }
+
+ value = fromYCPListToPythonTuple(ycp_Term->asTerm()->args());
+ if (value == Py_None){
+ y2error("fromYCPListToPythonTuple FIALED");
+ return Py_None;
+ }
- } else { // end if (ycp_Map->isMap())
- y2milestone ("Value is not YCPTerm");
- return NULL;
- } // end else of if (ycp_Map->isMap())
- Py_INCREF(pPythonTerm);
- return pPythonTerm;
+ return Term_NewString(ycp_Term->asTerm()->name().c_str(), value);
}
Modified: trunk/python-bindings/src/YPython.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.h?rev=41142&r1=41141&r2=41142&view=diff
==============================================================================
--- trunk/python-bindings/src/YPython.h (original)
+++ trunk/python-bindings/src/YPython.h Thu Sep 27 15:34:02 2007
@@ -63,18 +63,20 @@
static YPython * _yPython;
- /**
- * Transfer from python simple type to ycp simple type
- * transfered are: boolean, integer, string, float,
- **/
- bool PythonTypeToYCPSimpleType(PyObject* pPythonValue, YCPValue &out);
-
- /**
- * Transfer from ycp simple type to python simple type
- * transfered are: boolean, integer, string, float,
- **/
- PyObject* YCPTypeToPythonSimpleType(YCPValue in);
+ /**
+ * Transform Python type to YCP type and return new YCPValue built
+ * from python object.
+ */
+ YCPValue PythonTypeToYCPType(PyObject*);
+
+ /**
+ * Transform YCP type to Python type and return reference to new
+ * Python object.
+ */
+ PyObject *YCPTypeToPythonType(YCPValue);
+
+private:
/**
* Convert a Python list to a YCPList.
**/
@@ -116,12 +118,6 @@
**/
PyObject* fromYCPTermToPythonTerm (YCPValue ycp_Term);
-
- PyObject *pPathClass;
- PyObject *pSymbolClass;
- PyObject *pTermClass;
-
-
protected:
/**
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org