diff options
author | Will Thompson <will@willthompson.co.uk> | 2018-10-23 11:23:38 +0100 |
---|---|---|
committer | Will Thompson <will@willthompson.co.uk> | 2018-10-23 11:23:38 +0100 |
commit | d5540997ab08fbb5cdd33ca2ce5199bcfb28b6ce (patch) | |
tree | 01ee3d154ff7838dbd6c72e25735f3a71570c4ca | |
parent | d642a08d4f9e98b88bfe54ebb32af3a143c46011 (diff) | |
download | d-feet-wjt/pretty-print-byte-strings.tar.gz |
introspection: format property values with g_variant_print()wjt/pretty-print-byte-strings
The main case where this helps is byte strings. GVariant has a special
case for values of type 'ay' which end with a NUL byte and otherwise
contain only printable ASCII characters: it prints them in the form
b'asciistring'. UDisks and Flatpak (among others) use bytestrings of
this form extensively for file paths, which are not guaranteed to be
UTF-8 so cannot be represented as D-Bus type 's'.
This does have the downside that b'foo' is also valid Python but means
something different:
In [2]: GLib.Variant('ay', b'abc')
Out[2]: GLib.Variant('ay', [0x61, 0x62, 0x63])
In [3]: GLib.Variant('ay', b'abc\0')
Out[3]: GLib.Variant('ay', b'abc')
-rw-r--r-- | src/dfeet/introspection.py | 2 | ||||
-rw-r--r-- | src/dfeet/introspection_helper.py | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/dfeet/introspection.py b/src/dfeet/introspection.py index 3554866..be04fb6 100644 --- a/src/dfeet/introspection.py +++ b/src/dfeet/introspection.py @@ -115,7 +115,7 @@ class AddressInfo(): -1, None) # update the object value so markup string is calculated correct - obj.value = result[0] + obj.value = result.get_child_value(0).get_child_value(0) # set new markup string model[iter_][0] = obj.markup_str else: diff --git a/src/dfeet/introspection_helper.py b/src/dfeet/introspection_helper.py index 74789f5..7dddb0e 100644 --- a/src/dfeet/introspection_helper.py +++ b/src/dfeet/introspection_helper.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from gi.repository import GObject, Gio +from gi.repository import GLib, GObject, Gio from dfeet import dbus_utils @@ -87,7 +87,7 @@ class DBusProperty(DBusInterface): args_signature_markup(sig), args_name_markup(self.property_info.name), " / ".join(readwrite)) if self.value is not None: - s += " = %s" % (self.value,) + s += " = %s" % (GLib.markup_escape_text(self.value.print_(False)),) return s @property |