diff options
-rw-r--r-- | gi/overrides/GLib.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py index a383f583..83cbb7fb 100644 --- a/gi/overrides/GLib.py +++ b/gi/overrides/GLib.py @@ -153,6 +153,23 @@ class _VariantCreator(object): return builder.end() +LEAF_ACCESSORS = { + 'b': 'get_boolean', + 'y': 'get_byte', + 'n': 'get_int16', + 'q': 'get_uint16', + 'i': 'get_int32', + 'u': 'get_uint32', + 'x': 'get_int64', + 't': 'get_uint64', + 'h': 'get_handle', + 'd': 'get_double', + 's': 'get_string', + 'o': 'get_string', # object path + 'g': 'get_string', # signature +} + + class Variant(GLib.Variant): def __new__(cls, format_string, value): """Create a GVariant from a native Python object. @@ -220,28 +237,12 @@ class Variant(GLib.Variant): def unpack(self): """Decompose a GVariant into a native Python object.""" - LEAF_ACCESSORS = { - 'b': self.get_boolean, - 'y': self.get_byte, - 'n': self.get_int16, - 'q': self.get_uint16, - 'i': self.get_int32, - 'u': self.get_uint32, - 'x': self.get_int64, - 't': self.get_uint64, - 'h': self.get_handle, - 'd': self.get_double, - 's': self.get_string, - 'o': self.get_string, # object path - 'g': self.get_string, # signature - } - type_string = self.get_type_string() # simple values la = LEAF_ACCESSORS.get(type_string) if la: - return la() + return getattr(self, la)() # tuple if type_string.startswith('('): |