changeset 1794:b0ed4863dbc7

bridge (D-Bus): fixed handling of profile in kwargs: kwargs are not handled by python D-Bus (i.e. they are not sent through D-Bus). The "profile" and "profile_key" kwargs are often used through SàT with the bridge, this was working so far because they were used for core methods (which have a signature in DBus.py handling profile), or in Libervia browser who ignore profile argument. But if the profile or profile_key was used as a keyword for plugin method outside of Libervia browser, they were ignored, this commit fix this by adding them to the args list.
author Goffi <goffi@goffi.org>
date Wed, 13 Jan 2016 18:44:32 +0100
parents f39ca2832774
children c38233e12c69
files frontends/src/bridge/DBus.py src/bridge/bridge_constructor/dbus_frontend_template.py
diffstat 2 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py	Wed Jan 13 18:15:20 2016 +0100
+++ b/frontends/src/bridge/DBus.py	Wed Jan 13 18:44:32 2016 +0100
@@ -100,15 +100,25 @@
                 #   - or if the last two arguments are callable
 
                 async = False
+                args = list(args)
 
                 if kwargs:
                     if 'callback' in kwargs:
                         async = True
                         _callback = kwargs.pop('callback')
                         _errback = kwargs.pop('errback', lambda failure: log.error(unicode(failure)))
+                    try:
+                        args.append(kwargs.pop('profile'))
+                    except KeyError:
+                        try:
+                            args.append(kwargs.pop('profile_key'))
+                        except KeyError:
+                            pass
+                    # at this point, kwargs should be empty
+                    if kwargs:
+                        log.warnings(u"unexpected keyword arguments, they will be ignored: {}".format(kwargs))
                 elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]):
                     async = True
-                    args = list(args)
                     _errback = args.pop()
                     _callback = args.pop()
 
--- a/src/bridge/bridge_constructor/dbus_frontend_template.py	Wed Jan 13 18:15:20 2016 +0100
+++ b/src/bridge/bridge_constructor/dbus_frontend_template.py	Wed Jan 13 18:44:32 2016 +0100
@@ -100,15 +100,25 @@
                 #   - or if the last two arguments are callable
 
                 async = False
+                args = list(args)
 
                 if kwargs:
                     if 'callback' in kwargs:
                         async = True
                         _callback = kwargs.pop('callback')
                         _errback = kwargs.pop('errback', lambda failure: log.error(unicode(failure)))
+                    try:
+                        args.append(kwargs.pop('profile'))
+                    except KeyError:
+                        try:
+                            args.append(kwargs.pop('profile_key'))
+                        except KeyError:
+                            pass
+                    # at this point, kwargs should be empty
+                    if kwargs:
+                        log.warnings(u"unexpected keyword arguments, they will be ignored: {}".format(kwargs))
                 elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]):
                     async = True
-                    args = list(args)
                     _errback = args.pop()
                     _callback = args.pop()