python decorations

hrotzing at kip.uni-heidelberg.de hrotzing at kip.uni-heidelberg.de
Fri Jun 9 08:38:43 PDT 2006


Hi all,

I'm quite new to dbus and python but I want to use the python dbus bindings to 
write a few programs which communicate over dbus.
All these small programs should use a python base class similar to this 

class  service(dbus.service.Object):
	def __init__(self,ServiceName):
	self.InterfaceServiceName='/x.../y.../'
	self.MyServiceName=ServiceName 
			bus = dbus.Bus()	
			bus_name = dbus.service.BusName(ServiceName,
							bus=dbus.SessionBus())
			dbus.service.Object.__init__(self, bus_name,InterfaceServiceName)
      	# a set of  default functions for every inherited object, e.g.
	@dbus.service.method(MyServiceName)
	def EchoString(self, original):
		return original
	...

and inherit this class in this way 

ServiceName='org.valid.testName'
class MySubClass(service):
        @dbus.service.method(ServiceName)
        def func(self):
                return "foo"

service_obj = MySubClass(ServiceName)

This works, if the ServiceName is set statically before the service class gets 
called.

Setting the ServiceName in the __init_() func of the service class like above 
did not work. The @dbus.service.method(MyServiceName) decoration is always 
throwing exceptions, usually from the 
_util._validate_interface_or_name(dbus_interface)  function showing that the 
string MyServiceName was not set.

Is it possible to modify the @dbus.service.method(MyServiceName) decoration at 
run time ? If I would use a static bus_interface, all objects would use the 
same bus_interface name on the bus.


Thank you for your answer,
Hannes


More information about the dbus mailing list