mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-16 03:48:04 +02:00
2005-11-14 Robert McQueen <robot101@debian.org>
* python/decorators.py, python/service.py: Add a new argument to the dbus.service.method decorator called sender_keyword, which if set, specifies the name of an argument which will be provided the bus name of the method caller. * test/python/test-client.py, test/python/test-service.py: Add a method and test to check the sender_keyword functionality.
This commit is contained in:
parent
45ef0fbc4f
commit
7b9236f2ae
5 changed files with 28 additions and 1 deletions
10
ChangeLog
10
ChangeLog
|
|
@ -1,3 +1,13 @@
|
|||
2005-11-14 Robert McQueen <robot101@debian.org>
|
||||
|
||||
* python/decorators.py, python/service.py: Add a new argument to the
|
||||
dbus.service.method decorator called sender_keyword, which if set,
|
||||
specifies the name of an argument which will be provided the bus
|
||||
name of the method caller.
|
||||
|
||||
* test/python/test-client.py, test/python/test-service.py: Add a
|
||||
method and test to check the sender_keyword functionality.
|
||||
|
||||
2005-11-07 John (J5) Palmieri <johnp@redhat.com>
|
||||
|
||||
* bus/driver.c (bus_driver_handle_reload_config): Make sure we send an
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import _util
|
|||
import inspect
|
||||
import dbus_bindings
|
||||
|
||||
def method(dbus_interface, in_signature=None, out_signature=None, async_callbacks=None):
|
||||
def method(dbus_interface, in_signature=None, out_signature=None, async_callbacks=None, sender_keyword=None):
|
||||
_util._validate_interface_or_name(dbus_interface)
|
||||
|
||||
def decorator(func):
|
||||
|
|
@ -17,6 +17,9 @@ def method(dbus_interface, in_signature=None, out_signature=None, async_callback
|
|||
args.remove(async_callbacks[0])
|
||||
args.remove(async_callbacks[1])
|
||||
|
||||
if sender_keyword:
|
||||
args.remove(sender_keyword)
|
||||
|
||||
if in_signature:
|
||||
in_sig = tuple(dbus_bindings.Signature(in_signature))
|
||||
|
||||
|
|
@ -30,6 +33,7 @@ def method(dbus_interface, in_signature=None, out_signature=None, async_callback
|
|||
func._dbus_interface = dbus_interface
|
||||
func._dbus_in_signature = in_signature
|
||||
func._dbus_out_signature = out_signature
|
||||
func._dbus_sender_keyword = sender_keyword
|
||||
func._dbus_args = args
|
||||
return func
|
||||
|
||||
|
|
|
|||
|
|
@ -294,6 +294,10 @@ class Object(Interface):
|
|||
keywords[return_callback] = lambda *retval: _method_reply_return(connection, message, method_name, signature, *retval)
|
||||
keywords[error_callback] = lambda exception: _method_reply_error(connection, message, exception)
|
||||
|
||||
# include the sender if desired
|
||||
if parent_method._dbus_sender_keyword:
|
||||
keywords[parent_method._dbus_sender_keyword] = message.get_sender()
|
||||
|
||||
# call method
|
||||
retval = candidate_method(self, *args, **keywords)
|
||||
|
||||
|
|
|
|||
|
|
@ -218,6 +218,11 @@ class TestDBusBindings(unittest.TestCase):
|
|||
self.assert_(private_type != private_func, '%s should not equal %s' % (private_type, private_func))
|
||||
self.assert_(private_func != private_cls, '%s should not equal %s' % (private_func, private_cls))
|
||||
|
||||
def testSenderName(self):
|
||||
print '\n******** Testing sender name keyword ********'
|
||||
myself = self.iface.WhoAmI()
|
||||
print "I am", myself
|
||||
|
||||
def testBusNameCreation(self):
|
||||
print '\n******** Testing BusName creation ********'
|
||||
test = [('org.freedesktop.DBus.Python.TestName', True),
|
||||
|
|
|
|||
|
|
@ -130,6 +130,10 @@ class TestObject(dbus.service.Object, TestInterface):
|
|||
except Exception, e:
|
||||
error_cb(e)
|
||||
|
||||
@dbus.service.method('org.freedesktop.DBus.TestSuiteInterface', in_signature='', out_signature='s', sender_keyword='sender')
|
||||
def WhoAmI(self, sender):
|
||||
return sender
|
||||
|
||||
session_bus = dbus.SessionBus()
|
||||
name = dbus.service.BusName("org.freedesktop.DBus.TestSuitePythonService", bus=session_bus)
|
||||
object = TestObject(name)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue