def test_guess_signature_dbus_types(self): aeq = self.assertEqual from _dbus_bindings import Message gs = Message.guess_signature aeq(gs(types.Dictionary({'a':'b'})), 'a{ss}') aeq(gs(types.Dictionary({'a':'b'}, signature='sv')), 'a{sv}') aeq(gs(types.Dictionary({}, signature='iu')), 'a{iu}') aeq(gs(types.Array([types.Int32(1)])), 'ai') aeq(gs(types.Array([types.Int32(1)], signature='u')), 'au')
def test_append_Variant(self): aeq = self.assertEqual from _dbus_bindings import SignalMessage s = SignalMessage('/', 'foo.bar', 'baz') s.append(types.Int32(1, variant_level=0), types.String('a', variant_level=42), types.Array([types.Byte(b'a', variant_level=1), types.UInt32(123, variant_level=1)], signature='v'), signature='vvv') aeq(s.get_signature(), 'vvv') args = s.get_args_list() aeq(args[0].__class__, types.Int32) aeq(args[0].variant_level, 1) aeq(args[1].__class__, types.String) aeq(args[1].variant_level, 42) aeq(args[2].__class__, types.Array) aeq(args[2].variant_level, 1) aeq(args[2].signature, 'v')
def _get_dbus_types(s: str) -> List[Type]: signature = Signature(s) out = [] for entry in signature: if entry in _DBUS_PRIMITIVES: if entry == "y": raise TypeError( "dbus.Byte cannot be instantiated with default value! " "Use ByteArray ('ay') or UInt16 ('q') instead." ) out.append(_DBUS_PRIMITIVES[entry]) # FIXME: DBus container types get instantiated here instead of in _instantiate. elif entry.startswith("("): defaults = _instantiate(_get_dbus_types(entry[1:-1])) out.append(dtype.Struct(defaults, signature=entry[1:-1])) elif entry.startswith("a{"): out.append(dtype.Dictionary(signature=entry[2:-1])) elif entry.startswith("a"): out.append(dtype.Array(signature=entry[1:])) return out
def test_Array(self): self.assertEqual(types.Array(['foo','bar']), ['foo','bar']) self.assertEqual(types.Array([], variant_level=2), []) self.assertEqual(types.Array([], variant_level=2).variant_level, 2)