comparison 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
comparison
equal deleted inserted replaced
1072:d123d61976c8 1073:f094583732de
25 from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError 25 from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError
26 26
27 from dbus.mainloop.glib import DBusGMainLoop 27 from dbus.mainloop.glib import DBusGMainLoop
28 DBusGMainLoop(set_as_default=True) 28 DBusGMainLoop(set_as_default=True)
29 29
30 import ast
31
30 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix 32 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix
31 const_ERROR_PREFIX = const_INT_PREFIX + ".error" 33 const_ERROR_PREFIX = const_INT_PREFIX + ".error"
32 const_OBJ_PATH = '/org/goffi/SAT/bridge' 34 const_OBJ_PATH = '/org/goffi/SAT/bridge'
33 const_CORE_SUFFIX = ".core" 35 const_CORE_SUFFIX = ".core"
34 const_PLUGIN_SUFFIX = ".plugin" 36 const_PLUGIN_SUFFIX = ".plugin"
40 42
41 @param dbus_e (DBusException) 43 @param dbus_e (DBusException)
42 @return: BridgeException 44 @return: BridgeException
43 """ 45 """
44 name = dbus_e.get_dbus_name()[len(const_ERROR_PREFIX) + 1:] 46 name = dbus_e.get_dbus_name()[len(const_ERROR_PREFIX) + 1:]
45 return BridgeException(name, dbus_e.get_dbus_message()) 47 # XXX: dbus_e.args doesn't contain the original DBusException args, but we
48 # receive its serialized form in dbus_e.args[0]. From that we can rebuild
49 # the original arguments list thanks to ast.literal_eval (secure eval).
50 message = dbus_e.get_dbus_message() # similar to dbus_e.args[0]
51 try:
52 message, condition = ast.literal_eval(message)
53 except (SyntaxError, ValueError, TypeError):
54 condition = ''
55 return BridgeException(name, message, condition)
46 56
47 57
48 class DBusBridgeFrontend(BridgeFrontend): 58 class DBusBridgeFrontend(BridgeFrontend):
49 def __init__(self): 59 def __init__(self):
50 try: 60 try: