Mon 25 Apr 2005
I have just released dbus-0.33 which include my update to the Python bindings. There is still a lot to be done in them but now everything else can remain behind the scenes as the API should remain stable baring anything I have forgotten. I perticularly like the clean soltuion to implementing the Introspectable interface:
class Object:
"""A base class for exporting your own Objects across the Bus.
Just inherit from Object and provide a list of methods to share
across the Bus. These will appear as member functions of your
ServiceObject.
"""
__metaclass__ = ObjectType
def __init__(self, object_path, service):
self._object_path = object_path
self._service = service
self._bus = service.get_bus()
self._connection = self._bus.get_connection()
self._connection.register_object_path(object_path, self._unregister_cb, self._message_cb)
def _unregister_cb(self, connection):
print ('Unregister')
def _message_cb(self, connection, message):
target_method_name = message.get_member()
target_methods = self._dbus_method_vtable[target_method_name]
args = message.get_args_list()
reply = _dispatch_dbus_method_call(target_methods, self, args, message)
self._connection.send(reply)
@method('org.freedesktop.DBus.Introspectable')
def Introspect(self):
reflection_data = '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">\n'
reflection_data = reflection_data + '<node name="%s">\n'%(self._object_path)
reflection_data = reflection_data + self._dbus_reflection_data
reflection_data = reflection_data + '</node>\n'
return reflection_data
Since every dbus object will inherit from the dbus.Object class, it will automaticly get the org.freedesktop.DBus.Introspectable interface without any fear of namespace clashing. Most of the reflection magic happens in the ObjectType metaclass and the method and signal decorators.
[read this post in: ar de es fr it ja ko pt ru zh-CN ]
April 25th, 2005 at 11:07 pm
Just took a look at the code, and it looks pretty good. I noticed that you have some pretty bulky code for inserting values into a “dictionary of lists of strings”. This is something where the dict.setdefault() method can come in handy.
It checks to see if a key is in the dictionary, and if not it sets the key to the given value. So to insert a string, you’d use something like this:
dict.setdefault(key, []).append(value)
April 26th, 2005 at 4:36 am
Not being funny, but you’ve used some odd spellings in the last few entries. Maybe get a spelll checker word press plugin or something?