def test_Struct(self):
     x = types.Struct(('',))
     self.assertEqual(x.variant_level, 0)
     self.assertEqual(x, ('',))
     x = types.Struct('abc', variant_level=42)
     self.assertEqual(x.variant_level, 42)
     self.assertEqual(x, ('a','b','c'))
示例#2
0
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