diff options
author | Seth Nickell <seth@gnome.org> | 2003-09-25 08:46:39 +0000 |
---|---|---|
committer | Seth Nickell <seth@gnome.org> | 2003-09-25 08:46:39 +0000 |
commit | dcc037cc1f008eae9f6a35aca5b1935459e44647 (patch) | |
tree | ab2087886c9a851fa3b77c9652303823bd0a6f07 /python/dbus.py | |
parent | 6f5fc71b10ab910612b7af767308f52bb8266b1e (diff) |
2003-09-25 Seth Nickell <seth@gnome.org>
* python/dbus.py:
* python/dbus_bindings.pyx.in:
Handle return values.
* python/examples/example-client.py:
* python/examples/example-service.py:
Pass back return values from the service to the client.
Diffstat (limited to 'python/dbus.py')
-rw-r--r-- | python/dbus.py | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/python/dbus.py b/python/dbus.py index 55e5944a..d09b3fec 100644 --- a/python/dbus.py +++ b/python/dbus.py @@ -105,25 +105,20 @@ class RemoteMethod: self._method_name = method_name def __call__(self, *args): - print ("Going to call object(%s).interface(%s).method(%s)" - % (self._object_path, self._interface, self._method_name)) - message = dbus_bindings.MethodCall(self._object_path, self._interface, self._method_name) message.set_destination(self._service_name) # Add the arguments to the function iter = message.get_iter() for arg in args: - print ("Adding arg %s" % (arg)) - print ("Append success is %d" % (iter.append(arg))) - print ("Args now %s" % (message.get_args_list())) + iter.append(arg) reply_message = self._connection.send_with_reply_and_block(message, 5000) args_tuple = reply_message.get_args_list() - if (len(args_tuple) == 0): + if len(args_tuple) == 0: return - elif (len(args_tuple) == 1): + elif len(args_tuple) == 1: return args_tuple[0] else: return args_tuple @@ -174,20 +169,30 @@ class Object: target_method = self._method_name_to_method[target_method_name] args = message.get_args_list() - retval = target_method(*args) - - reply = dbus_bindings.MethodReturn(message) - if retval != None: - reply.append(retval) + try: + retval = target_method(*args) + except Exception, e: + if e.__module__ == '__main__': + error_name = e.__class__ + else: + error_name = e.__module__ + '.' + str(e.__class__) + error_contents = str(e) + reply = dbus_bindings.Error(message, error_name, error_contents) + else: + reply = dbus_bindings.MethodReturn(message) + if retval != None: + iter = reply.get_iter() + iter.append(retval) + self._connection.send(reply) def _build_method_dictionary(self, methods): - dictionary = {} + method_dict = {} for method in methods: - if dictionionary.has_key(method.__name__): - print ('WARNING: registering DBus Object methods, already have a method named %s' % (method.__name__) - dictionary[method.__name__] = method - return dictionary + if method_dict.has_key(method.__name__): + print ('WARNING: registering DBus Object methods, already have a method named %s' % (method.__name__)) + method_dict[method.__name__] = method + return method_dict class RemoteService: """A remote service providing objects. |