Note that there are some explanatory texts on larger screens.

plurals
  1. POdbus Variant: How to preserve boolean datatype in Python?
    text
    copied!<p>I've been experimenting with dbus lately. But I can't seem to get my dbus Service to guess the correct datatypes for boolean values. Consider the following example:</p> <pre><code>import gtk import dbus import dbus.service from dbus.mainloop.glib import DBusGMainLoop class Service(dbus.service.Object): def __init__(self): bus_name = dbus.service.BusName("org.foo.bar", bus = dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, "/org/foo/bar") @dbus.service.method("org.foo.bar", in_signature = "a{sa{sv}}", out_signature = "a{sa{sv}}") def perform(self, data): return data if __name__ == "__main__": DBusGMainLoop(set_as_default = True) s = Service() gtk.main() </code></pre> <p>This piece of code creates a dbus service that provides the perform method which accepts one parameter that is a dictionary which maps from strings to other dictionaries, which in turn map strings to variants. I have chosen this format because of the format my dictionaries are in:</p> <pre><code>{ "key1": { "type": ("tuple", "value") }, "key2": { "name": "John Doe", "gender": "male", "age": 23 }, "test": { "true-property": True, "false-property": False } } </code></pre> <p>When I pass this dictionary through my service, the boolean values are converted to integers. In my eyes, the check should not be that difficult. Consider this (<code>value</code> is the variable to be converted to a dbus type):</p> <pre><code>if isinstance(value, bool): return dbus.Boolean(value) </code></pre> <p>If this check is done before checking for <code>isinstance(value, int)</code> then there would be no problem. Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload