Author: juhliarik Date: Wed Jul 2 09:47:42 2008 New Revision: 48748 URL: http://svn.opensuse.org/viewcvs/yast?rev=48748&view=rev Log: added function for conversion between dbus and python values Added: branches/tmp/lslezak/workshop/scr_dbus/DBusValueToPythonValue.py Added: branches/tmp/lslezak/workshop/scr_dbus/DBusValueToPythonValue.py URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/scr_dbus/DBusValueToPythonValue.py?rev=48748&view=auto ============================================================================== --- branches/tmp/lslezak/workshop/scr_dbus/DBusValueToPythonValue.py (added) +++ branches/tmp/lslezak/workshop/scr_dbus/DBusValueToPythonValue.py Wed Jul 2 09:47:42 2008 @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import dbus +import types + +def convertDbusTypeToPythonType (arg): + ## there is hack because dbus doesn't handle None value in python + if isinstance(arg, dbus.types.String): + tmp = types.StringType(arg) + if tmp == 'PyNone': + return None + else: + return tmp + + if isinstance(arg, dbus.types.Boolean): + return types.BooleanType(arg) + + if isinstance(arg, dbus.types.Int16) | isinstance(arg, dbus.types.Int32) : + return types.IntType(arg) + + if isinstance(arg, dbus.types.Int64): + return types.LongType(arg) + + if isinstance(arg, dbus.types.Array): + new_list = types.ListType() + for i in range(len(arg)): + new_list.append(convertDbusTypeToPythonType(arg[i])) + return new_list + + if isinstance(arg, dbus.types.Dictionary): + new_dict = types.DictionaryType() + for k, v in arg.iteritems(): + new_dict[convertDbusTypeToPythonType (k)]=convertDbusTypeToPythonType (v) + return new_dict + + return arg -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org