[d-feet/wjt/pretty-print-byte-strings: 2/2] introspection: format property values with g_variant_print()



commit d5540997ab08fbb5cdd33ca2ce5199bcfb28b6ce
Author: Will Thompson <will willthompson co uk>
Date:   Tue Oct 23 11:23:38 2018 +0100

    introspection: format property values with g_variant_print()
    
    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')

 src/dfeet/introspection.py        | 2 +-
 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]