mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-25 08:10:07 +01:00
* 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.
79 lines
2.4 KiB
Python
Executable file
79 lines
2.4 KiB
Python
Executable file
#!/usr/bin/env python
|
|
import sys
|
|
import os
|
|
|
|
builddir = os.environ["DBUS_TOP_BUILDDIR"]
|
|
pydir = builddir + "/python"
|
|
|
|
sys.path.insert(0, pydir)
|
|
sys.path.insert(0, pydir + '/.libs')
|
|
|
|
import dbus
|
|
|
|
if not dbus.__file__.startswith(pydir):
|
|
raise Exception("DBus modules are not being picked up from the package")
|
|
|
|
import dbus.service
|
|
import dbus.glib
|
|
import gobject
|
|
import random
|
|
|
|
class TestObject(dbus.service.Object):
|
|
def __init__(self, bus_name, object_path="/org/freedesktop/DBus/TestSuitePythonObject"):
|
|
dbus.service.Object.__init__(self, bus_name, object_path)
|
|
|
|
""" Echo whatever is sent
|
|
"""
|
|
@dbus.service.method("org.freedesktop.DBus.TestSuiteInterface")
|
|
def Echo(self, arg):
|
|
return arg
|
|
|
|
@dbus.service.method("org.freedesktop.DBus.TestSuiteInterface")
|
|
def GetComplexArray(self):
|
|
ret = []
|
|
for i in range(0,100):
|
|
ret.append((random.randint(0,100), random.randint(0,100), str(random.randint(0,100))))
|
|
|
|
return dbus.Array(ret, signature="(uus)")
|
|
|
|
def returnValue(self, test):
|
|
if test == 0:
|
|
return ""
|
|
elif test == 1:
|
|
return "",""
|
|
elif test == 2:
|
|
return "","",""
|
|
elif test == 3:
|
|
return []
|
|
elif test == 4:
|
|
return {}
|
|
elif test == 5:
|
|
return ["",""]
|
|
elif test == 6:
|
|
return ["","",""]
|
|
|
|
@dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='s')
|
|
def ReturnOneString(self, test):
|
|
return self.returnValue(test)
|
|
|
|
@dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='ss')
|
|
def ReturnTwoStrings(self, test):
|
|
return self.returnValue(test)
|
|
|
|
@dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='(ss)')
|
|
def ReturnStruct(self, test):
|
|
return self.returnValue(test)
|
|
|
|
@dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='as')
|
|
def ReturnArray(self, test):
|
|
return self.returnValue(test)
|
|
|
|
@dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='a{ss}')
|
|
def ReturnDict(self, test):
|
|
return self.returnValue(test)
|
|
|
|
session_bus = dbus.SessionBus()
|
|
name = dbus.service.BusName("org.freedesktop.DBus.TestSuitePythonService", bus=session_bus)
|
|
object = TestObject(name)
|
|
loop = gobject.MainLoop()
|
|
loop.run()
|