These little utilities are extracted from:
Mickey's own dbus introspection utility.
See: http://git.freesmartphone.org/?p=python-helpers.git;a=summary
(C) 2008-2009 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
class ObjectPath( object ):
def __init__( self, path ):
return "op%s" % repr(self.path)
if isinstance(v, dbus.Byte) \
or isinstance(v, dbus.Int64) \
or isinstance(v, dbus.UInt64) \
or isinstance(v, dbus.Int32) \
or isinstance(v, dbus.UInt32) \
or isinstance(v, dbus.Int16) \
or isinstance(v, dbus.UInt16) \
or type(v) == types.IntType:
elif isinstance(v, dbus.Double) or type(v) == types.FloatType:
elif isinstance(v, dbus.String) or type(v) == types.StringType:
elif isinstance(v, dbus.Dictionary) or type(v) == types.DictType:
return dict( (dbus_to_python(k), dbus_to_python(v)) for k,v in v.iteritems() )
elif isinstance(v, dbus.Array) or type(v) == types.ListType:
return [dbus_to_python(x) for x in v]
elif isinstance(v, dbus.Struct) or type(v) == types.TupleType:
return tuple(dbus_to_python(x) for x in v)
elif isinstance(v, dbus.Boolean) or type(v) == types.BooleanType:
elif isinstance(v, dbus.ObjectPath) or type(v) == ObjectPath:
raise TypeError("Can't convert type %s to python object" % type(v))
def prettyPrint( expression ):
from pprint import PrettyPrinter
pp = PrettyPrinter( indent=4 )
pp.pprint( dbus_to_python(expression) )