diff options
author | Robert McQueen <robot101@debian.org> | 2005-11-04 12:18:00 +0000 |
---|---|---|
committer | Robert McQueen <robot101@debian.org> | 2005-11-04 12:18:00 +0000 |
commit | ac36149533cdf3131dec3f43a7e9ea1ee11937f5 (patch) | |
tree | cc5a2cf3836d43ab52959d3b95b1fee04dbf510d /python/decorators.py | |
parent | e20c311b131246019ade0c964596a7fda758de68 (diff) |
2005-11-04 Robert McQueen <robot101@debian.org>
* python/dbus_bindings.pyx, test/python/test-client.py: Fix
marshalling of boolean values. Add some booleans to the values in
the test client.
* python/decorators.py, python/service.py: Add an 'async_callbacks'
argument to the dbus.service.method decorator, which allows you to
name arguments to take two callback functions for replying with
return values or an exception.
* test/python/test-client.py, test/python/test-service.py: Add test
case using asynchronous method reply functions, both return values and
errors, and from within both the function itself and from a mainloop
callback.
* python/decorators.py, python/service.py: Perform checking that the
number of method/signal arguments matches the number of types in the
signature at class loading time, not when you first introspect the
class.
* python/service.py: Remove debug print left by the last commit.
Diffstat (limited to 'python/decorators.py')
-rw-r--r-- | python/decorators.py | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/python/decorators.py b/python/decorators.py index 8b553736..3973f3e4 100644 --- a/python/decorators.py +++ b/python/decorators.py @@ -2,16 +2,35 @@ import _util import inspect import dbus_bindings -def method(dbus_interface, in_signature=None, out_signature=None): +def method(dbus_interface, in_signature=None, out_signature=None, async_callbacks=None): _util._validate_interface_or_name(dbus_interface) def decorator(func): + args = inspect.getargspec(func)[0] + args.pop(0) + + if async_callbacks: + if type(async_callbacks) != tuple: + raise TypeError('async_callbacks must be a tuple of (keyword for return callback, keyword for error callback)') + if len(async_callbacks) != 2: + raise ValueError('async_callbacks must be a tuple of (keyword for return callback, keyword for error callback)') + args.remove(async_callbacks[0]) + args.remove(async_callbacks[1]) + + if in_signature: + in_sig = tuple(dbus_bindings.Signature(in_signature)) + + if len(in_sig) > len(args): + raise ValueError, 'input signature is longer than the number of arguments taken' + elif len(in_sig) < len(args): + raise ValueError, 'input signature is shorter than the number of arguments taken' + func._dbus_is_method = True + func._dbus_async_callbacks = async_callbacks 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) + func._dbus_args = args return func return decorator @@ -29,13 +48,23 @@ def signal(dbus_interface, signature=None): self._connection.send(message) + args = inspect.getargspec(func)[0] + args.pop(0) + + if signature: + sig = tuple(dbus_bindings.Signature(func._dbus_signature)) + + if len(sig) > len(args): + raise ValueError, 'signal signature is longer than the number of arguments provided' + elif len(sig) < len(args): + raise ValueError, 'signal signature is shorter than the number of arguments provided' + emit_signal.__name__ = func.__name__ emit_signal.__doc__ = func.__doc__ emit_signal._dbus_is_signal = True emit_signal._dbus_interface = dbus_interface emit_signal._dbus_signature = signature - emit_signal._dbus_args = inspect.getargspec(func)[0] - emit_signal._dbus_args.pop(0) + emit_signal._dbus_args = args return emit_signal return decorator |