diff frontends/src/bridge/DBus.py @ 1073:f094583732de

bridge: DBusException also transports the twisted failure condition
author souliane <souliane@mailoo.org>
date Sun, 15 Jun 2014 16:06:02 +0200
parents d123d61976c8
children bf2927e6a0f5
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py	Sun Jun 15 00:18:28 2014 +0200
+++ b/frontends/src/bridge/DBus.py	Sun Jun 15 16:06:02 2014 +0200
@@ -27,6 +27,8 @@
 from dbus.mainloop.glib import DBusGMainLoop
 DBusGMainLoop(set_as_default=True)
 
+import ast
+
 const_INT_PREFIX = "org.goffi.SAT"  # Interface prefix
 const_ERROR_PREFIX = const_INT_PREFIX + ".error"
 const_OBJ_PATH = '/org/goffi/SAT/bridge'
@@ -42,7 +44,15 @@
     @return: BridgeException
     """
     name = dbus_e.get_dbus_name()[len(const_ERROR_PREFIX) + 1:]
-    return BridgeException(name, dbus_e.get_dbus_message())
+    # XXX: dbus_e.args doesn't contain the original DBusException args, but we
+    # receive its serialized form in dbus_e.args[0]. From that we can rebuild
+    # the original arguments list thanks to ast.literal_eval (secure eval).
+    message = dbus_e.get_dbus_message()  # similar to dbus_e.args[0]
+    try:
+        message, condition = ast.literal_eval(message)
+    except (SyntaxError, ValueError, TypeError):
+        condition = ''
+    return BridgeException(name, message, condition)
 
 
 class DBusBridgeFrontend(BridgeFrontend):