def parse_hints(self, h) -> dict: hints = {} for x in ("action-icons", "category", "desktop-entry", "resident", "transient", "x", "y", "urgency"): v = h.get(x) if v is not None: hints[x] = native_to_dbus(v) image_data = h.get("image-data") if image_data and bytestostr(image_data[0]) == "png": try: from xpra.codecs.pillow.decoder import open_only img_data = image_data[3] img = open_only(img_data, ("png", )) w, h = img.size channels = len(img.mode) rowstride = w * channels has_alpha = img.mode == "RGBA" pixel_data = bytearray(img.tobytes("raw", img.mode)) log.info("pixel_data=%s", type(pixel_data)) args = w, h, rowstride, has_alpha, 8, channels, pixel_data hints["image-data"] = tuple(native_to_dbus(x) for x in args) #hints["image-data"] = args except Exception as e: log("parse_hints(%s) error on image-data=%s", h, image_data, exc_info=True) log.error("Error parsing notification image:") log.error(" %s", e) log("parse_hints(%s)=%s", h, hints) #return dbus.types.Dictionary(hints, signature="sv") return hints
def gotinfo(proto=None, info={}): sub = info.get(subsystem) try: v = dbus.types.Dictionary((str(k), native_to_dbus(v)) for k, v in sub.items()) log("native_to_dbus(..)=%s", v) callback(v) except Exception as e: log("GetInfo:gotinfo", exc_info=True) errback(str(e))
def gotinfo(proto=None, info={}): try: v = dbus.types.Dictionary((str(k), native_to_dbus(v)) for k, v in info.items()) # v = native_to_dbus(info) log("native_to_dbus(..)=%s", v) callback(v) except Exception as e: log("GetAllInfo:gotinfo", exc_info=True) errback(str(e))
def gotinfo(_proto, info): sub = info.get(subsystem) try: v = dbus.types.Dictionary((str(k), native_to_dbus(v)) for k,v in sub.items()) log("native_to_dbus(..)=%s", v) callback(v) except Exception as e: # pragma: no cover log("GetInfo:gotinfo", exc_info=True) errback(str(e))
def gotinfo(_proto, info): try: v = dbus.types.Dictionary((str(k), native_to_dbus(v)) for k,v in info.items()) #v = native_to_dbus(info) log("native_to_dbus(..)=%s", v) callback(v) except Exception as e: # pragma: no cover log("GetAllInfo:gotinfo", exc_info=True) errback(str(e))
def GetInfo(self): i = self.server.get_info(None) self.log(".GetInfo()=%s", i) try: v = dbus.types.Dictionary((str(k), native_to_dbus(v)) for k,v in i.items()) log("native_to_dbus(..)=%s", v) except Exception: log("GetInfo:gotinfo", exc_info=True) v = dbus.types.Dictionary({}) return v
def test_unhandled_types(self): from xpra.dbus.helper import dbus_to_native, native_to_dbus o = AdHocStruct() r = dbus_to_native(o) assert r == o and type(r) == type( o), "%s (%s) got converted to %s (%s)" % (o, type(o), r, type(r)) r = native_to_dbus(o) #we don't know what else to do, #so we convert to a string: assert r == str(o)
def GetInfo(self): #full info is available by calling get_info() i = self.server.get_minimal_server_info() self.log(".GetInfo()=%s", i) try: v = dbus.types.Dictionary( (str(k), native_to_dbus(v)) for k, v in i.items()) log("native_to_dbus(..)=%s", v) except Exception: log("GetInfo:gotinfo", exc_info=True) v = dbus.types.Dictionary({}) return v
def test_standard_types(self): from xpra.dbus.helper import dbus_to_native, native_to_dbus for v in ( None, 1, 10, {}, { 1: 2, 3: 4 }, { True: 1, False: 0 }, { 1.5: 1, 2.5: 10 }, { "a": 1, "b": 2 }, "foo", 1.5, 5.0, [4, 5, 6], [True, False, True], [1.1, 1.2, 1.3], ["a", "b", "c"], #(1, 2, 3), #[1, "a", 2.5], [], ): dbus_value = native_to_dbus(v) assert v is None or dbus_value is not None, "native_to_dbus(%s) is None!" % ( v, ) assert v is None or type(dbus_value) != type( v), "native_to_dbus(%s) is the same type: %s" % (v, type(v)) r = dbus_to_native(dbus_value) assert v is None or r is not None, "dbus_to_native(%s) is None!" % ( r, ) assert r == v, "value=%s (%s), got back %s (%s)" % (v, type(v), r, type(r))