dbus-python 0.80rc2 release candidate
simon.mcvittie at collabora.co.uk
Fri Dec 15 06:28:43 PST 2006
(Quoting more or less full context for dbus at l.fd.o's benefit)
On Fri, 15 Dec 2006 at 13:44:25 +0100, Luigi Paioro wrote:
> in_signature='is', out_signature=None)
> def setSomething(self, id, file = None):
> # DO SOMETHING
> Then, if I use such method without passing the optional parameter, e.g.:
> it raises an exception:
> TypeError: More items found in D-Bus signature than in Python arguments
> Well, I guess this is done for uniformity with the other languages that
> don't accept optional arguments. So I've tried to call such method with
> a None argument, e.g.:
> my_proxy.setSomething(25, None)
> but it raises this exception:
> TypeError: Expected a string or unicode object
> So I presume that I cannot pass None values... mmmhhh...
D-Bus interfaces are meant to be statically typed; as you say, this is for
compatibility with statically typed languages like C. The calling
conventions are more restrictive than Python's. It's impossible to
provide a meaningful signature for a function with a variable number
of arguments - the D-Bus signature syntax just doesn't support it.
At the moment the default values on parameters are only used if other
Python code in the service process calls setSomething() directly as a
Python method, without going through D-Bus at all. D-Bus doesn't really
have that concept - I suppose it might be possible to add it, but not in
a very interoperable way.
It's possible to fake a function with variable arguments by omitting the
signature - this would mean the introspection XML made no mention of the
signature. A (recent) dbus-python client would then be able to call the
function with any arguments, and dbus-python would guess (from the
arguments given) what signature it should be using for that call. This
is a bad idea though.
A better way would be to define file == '' to have whatever special
"there is no file" behaviour you want, and just have D-Bus callers
explictly pass in '' if there is no file. You can't send None over D-Bus
at all - there is no concept of None or NULL in the wire protocol.
You can often define special null values, though (for instance the
Telepathy specification defines handles to be non-zero, specifically
so we can use handle == 0 as a special null value in various places).
(Related: I think you mean out_signature='' - None as a signature means
"unspecified", not "nothing". I should perhaps change the code so if
you specify one of in_signature, out_signature you always have to
specify the other.)
More information about the dbus