From 20bcbaf21f4e94c48d6348a4ba8013d20f9e4d36 Mon Sep 17 00:00:00 2001 From: Robert McQueen Date: Sat, 29 Oct 2005 19:13:17 +0000 Subject: 2005-10-29 Robert McQueen * python/decorators.py: Add optional arguments to the method and signal decorators to allow you to specify the signature of arguments and return values. Preserve the doc strings of signal functions in the decorated version, for pydoc and friends. * python/dbus_bindings.pyx, python/proxies.py: Replace the parse_signature_block function with an iterable dbus.Signature() type. Fix a bug in MessageIter.append_strict where you could append anything by claiming it was a string. * python/service.py: Use the out_signature decoration on methods to marshal return values, meaning you no longer require dbus.Array() or dbus.Dictionary() to indicate the type when returning empty arrays or dictionaries. Fix a bug where exceptions which are defined in __main__ are not turned into error replies. * test/python/test-client.py, test/python/test-service.py: Add test for correct marshalling of return values according to out_signature. Fix a bug in the async call test where the error_handler is missing a self argument. --- python/decorators.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'python/decorators.py') diff --git a/python/decorators.py b/python/decorators.py index b94babc4..8b553736 100644 --- a/python/decorators.py +++ b/python/decorators.py @@ -1,20 +1,22 @@ -import _util +import _util import inspect import dbus_bindings -def method(dbus_interface): +def method(dbus_interface, in_signature=None, out_signature=None): _util._validate_interface_or_name(dbus_interface) def decorator(func): func._dbus_is_method = True func._dbus_interface = dbus_interface + func._dbus_in_signature = in_signature + func._dbus_out_signature = out_signature func._dbus_args = inspect.getargspec(func)[0] func._dbus_args.pop(0) return func return decorator -def signal(dbus_interface): +def signal(dbus_interface, signature=None): _util._validate_interface_or_name(dbus_interface) def decorator(func): def emit_signal(self, *args, **keywords): @@ -27,9 +29,11 @@ def signal(dbus_interface): self._connection.send(message) + emit_signal.__name__ = func.__name__ + emit_signal.__doc__ = func.__doc__ emit_signal._dbus_is_signal = True emit_signal._dbus_interface = dbus_interface - emit_signal.__name__ = func.__name__ + emit_signal._dbus_signature = signature emit_signal._dbus_args = inspect.getargspec(func)[0] emit_signal._dbus_args.pop(0) return emit_signal -- cgit