D-Bus bridge: fixed getRoomsSubjects call + fixed dynamic addition of methods + added getLastGroupBlogs method

This commit is contained in:
Goffi 2012-04-01 19:45:35 +02:00
commit bb0f290924
3 changed files with 27 additions and 23 deletions

View file

@ -431,27 +431,29 @@ class DbusObject(dbus.service.Object):
"""Dynamically add a method to Dbus Bridge"""
inspect_args = inspect.getargspec(method)
_attributes = inspect_args.args
_arguments = inspect_args.args
_defaults = list(inspect_args.defaults or [])
if inspect.ismethod(method):
#if we have a method, we don't want the first argument (usually 'self')
del(_attributes[0])
del(_arguments[0])
#first arguments are for the _callback method
arguments_callback = ', '.join([repr(name)] + ((_arguments + ['callback=callback','errback=errback']) if async else _arguments))
if async:
_attributes.extend(['callback','errback'])
_defaults.extend(['callback', 'errback'])
_arguments.extend(['callback','errback'])
_defaults.extend([None, None])
attributes = ', '.join(_attributes)
#now we create a second list with default values
for i in range(1, len(_defaults)+1):
_attributes[-i] = "%s = %s" % (_attributes[-i], repr(_defaults[-i]))
_arguments[-i] = "%s = %s" % (_arguments[-i], repr(_defaults[-i]))
attributes_defaults = ', '.join(_attributes)
arguments_defaults = ', '.join(_arguments)
code = compile ('def %(name)s (self,%(attributes_defaults)s): return self.cb["%(name)s"](%(attributes)s)' %
{'name':name, 'attributes_defaults':attributes_defaults, 'attributes':attributes}, '<DBus bridge>','exec')
code = compile ('def %(name)s (self,%(arguments_defaults)s): return self._callback(%(arguments_callback)s)' %
{'name':name, 'arguments_defaults':arguments_defaults, 'arguments_callback':arguments_callback}, '<DBus bridge>','exec')
exec (code) #FIXME: to the same thing in a cleaner way, without compile/exec
method = locals()[name]
async_callbacks = ('callback', 'errback') if async else None

View file

@ -147,27 +147,29 @@ class DbusObject(dbus.service.Object):
"""Dynamically add a method to Dbus Bridge"""
inspect_args = inspect.getargspec(method)
_attributes = inspect_args.args
_arguments = inspect_args.args
_defaults = list(inspect_args.defaults or [])
if inspect.ismethod(method):
#if we have a method, we don't want the first argument (usually 'self')
del(_attributes[0])
del(_arguments[0])
#first arguments are for the _callback method
arguments_callback = ', '.join([repr(name)] + ((_arguments + ['callback=callback','errback=errback']) if async else _arguments))
if async:
_attributes.extend(['callback','errback'])
_defaults.extend(['callback', 'errback'])
_arguments.extend(['callback','errback'])
_defaults.extend([None, None])
attributes = ', '.join(_attributes)
#now we create a second list with default values
for i in range(1, len(_defaults)+1):
_attributes[-i] = "%s = %s" % (_attributes[-i], repr(_defaults[-i]))
_arguments[-i] = "%s = %s" % (_arguments[-i], repr(_defaults[-i]))
attributes_defaults = ', '.join(_attributes)
arguments_defaults = ', '.join(_arguments)
code = compile ('def %(name)s (self,%(attributes_defaults)s): return self.cb["%(name)s"](%(attributes)s)' %
{'name':name, 'attributes_defaults':attributes_defaults, 'attributes':attributes}, '<DBus bridge>','exec')
code = compile ('def %(name)s (self,%(arguments_defaults)s): return self._callback(%(arguments_callback)s)' %
{'name':name, 'arguments_defaults':arguments_defaults, 'arguments_callback':arguments_callback}, '<DBus bridge>','exec')
exec (code) #FIXME: to the same thing in a cleaner way, without compile/exec
method = locals()[name]
async_callbacks = ('callback', 'errback') if async else None

View file

@ -63,8 +63,8 @@ class DBusBridgeFrontend(BridgeFrontend):
def getRoomsJoined(self, profile_key):
return self.db_plugin_iface.getRoomsJoined(profile_key)
def getRoomsSubjectss(self, profile_key):
return self.db_plugin_iface.getRoomsSubjectss(profile_key)
def getRoomsSubjects(self, profile_key):
return self.db_plugin_iface.getRoomsSubjects(profile_key)
def joinMUC(self, room_jid, nick, options, profile_key):
if options == None:
@ -136,12 +136,12 @@ class DBusBridgeFrontend(BridgeFrontend):
def getLastMicroblogs(self, jid, max_items, profile_key, callback=None, errback=None):
return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
def getMblogNodes(self, profile_key, callback=None, errback=None):
return self.db_plugin_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback)
def sendGroupBlog(self, groups, message, profile_key):
return self.db_plugin_iface.sendGroupBlog(groups, message, profile_key)
def getLastGroupBlogs(self, jid, max_items, profile_key, callback=None, errback=None):
return self.db_plugin_iface.getLastGroupBlogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
def sendPersonalEvent(self, event_type, data, profile_key):
return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)