Python: Problem with adding method to interfce

John (J5) Palmieri johnp at redhat.com
Fri Mar 3 09:07:42 PST 2006


Using 

method = dbus.server.method('some.interface')(method)

While it works, confuses what is actually happening.  The above code is
the implementation of python decorators
(@dbus.server.method('some.interface')) except that decorators have
semantics that the implementation does not convey.  Namely that they
have to be executed before object creation.  All the decorator does is
mark the method for export.  Our metaclass, upon class realization (when
the class is parsed not instantiated) then looks at the marked methods
and readies them to be handled once the object is is instantiated and
exported over the bus.

So using the above code inside the init only causes the method to be
marked but the code to have it be handled has long since been run.

On Fri, 2006-03-03 at 13:54 +0100, Marcin wrote:
> Hi everyone.
> 
> 	I have problem with adding method to dbus interface in __init__. Take a  
> look:
> 
> class A(dbus.service.Object):
> 	def method(self):
> 		pass
> 	# var 1
> 	method = dbus.server.method('some.interface')(method) # <- this variant  
> works
> 	
> 	def __init__(self):
> 		# var 2
> 		self.method = dbus.server.method('some.interface')(self.method)
> 		# ^^^ this variant doesn't work...?
> 		dbus.service.Object.__init__(self, dbus.service.BusName('some.service',  
> bus=dbus.								SessionBus()), '/some/object')
> ob = A()
> 
> Does anyone know why var 2 doesn't work?
> 
> A obtain that error:
>    File "/usr/lib/python2.4/site-packages/dbus/decorators.py", line 31, in  
> decorator
>      func._dbus_is_method = True
> AttributeError: 'instancemethod' object has no attribute '_dbus_is_method'
> 
> Thanks for any help.
> 
> Marcin		

-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list