Example #1
0
 def service_found(self, interface, protocol, name, stype, domain, flags):
     log("service_found%s", (interface, protocol, name, stype, domain, flags))
     if flags & avahi.LOOKUP_RESULT_LOCAL:
         # local service, skip
         pass
     if self.mdns_found:
         self.mdns_found(dbus_to_native(interface), dbus_to_native(name))
     self.server.ResolveService(interface, protocol, name, stype,
             domain, avahi.PROTO_UNSPEC, dbus.UInt32(0),
             reply_handler=self.service_resolved, error_handler=self.resolve_error)
Example #2
0
	def service_found(self, interface, protocol, name, stype, domain, flags):
		log("service_found%s", (interface, protocol, name, stype, domain, flags))
		if flags & avahi.LOOKUP_RESULT_LOCAL:
			# local service, skip
			pass
		if self.mdns_found:
			self.mdns_found(dbus_to_native(interface), dbus_to_native(name))
		self.server.ResolveService(interface, protocol, name, stype,
				domain, avahi.PROTO_UNSPEC, dbus.UInt32(0),
				reply_handler=self.service_resolved, error_handler=self.resolve_error)
Example #3
0
 def service_removed(self, interface, protocol, name, stype, domain, flags):
     log("service_removed%s",
         (interface, protocol, name, stype, domain, flags))
     if self.mdns_remove:
         nargs = (dbus_to_native(x) for x in (interface, protocol, name,
                                              stype, domain, flags))
         self.mdns_remove(*nargs)
Example #4
0
 def parse_hints(self, dbus_hints):
     hints = {}
     h = dbus_to_native(dbus_hints)
     for x in ("image-data", "icon_data"):
         try:
             data = h.pop(x)
         except KeyError:
             pass
         else:
             v = parse_image_data(data)
             if v:
                 hints["image-data"] = v
                 break
     if "image-data" not in hints:
         try:
             image_path = h.pop("image-path")
         except KeyError:
             pass
         else:
             v = parse_image_path(image_path)
             if v:
                 hints["image-data"] = v
     for x in ("action-icons", "category", "desktop-entry", "resident",
               "transient", "x", "y", "urgency"):
         v = h.get(x)
         if v is not None:
             hints[x] = v
     log("parse_hints(%s)=%s", dbus_hints, hints)
     return hints
Example #5
0
 def test_struct(self):
     from xpra.dbus.helper import dbus_to_native
     import dbus
     thestring = "foo"
     struct = dbus.Struct((dbus.String(thestring), ), signature=None)
     v = dbus_to_native(struct)
     assert v and isinstance(v, list)
     assert v[0] == thestring
Example #6
0
 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)
Example #7
0
	def service_resolved(self, interface, protocol, name, stype, domain, host, x, address, port, text_array, v):
		log("AvahiListener.service_resolved%s", (interface, protocol, name, stype, domain, host, x, address, port, "..", v))
		if self.mdns_add:
			#parse text data:
			text = {}
			try:
				for text_line in text_array:
					line = ""
					for b in text_line:
						line += chr(b.real)
					parts = line.split("=", 1)
					if len(parts)==2:
						text[parts[0]] = parts[1]
				log(" text=%s", text)
			except Exception:
				log.error("failed to parse text record", exc_info=True)
			nargs = (dbus_to_native(x) for x in (interface, name, domain, host, address, port, text))
			self.mdns_add(*nargs)
Example #8
0
 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))
Example #9
0
 def service_resolved(self, interface, protocol, name, stype, domain, host, x, address, port, text_array, v):
     log("AvahiListener.service_resolved%s",
     (interface, protocol, name, stype, domain, host, x, address, port, "..", v))
     if self.mdns_add:
         #parse text data:
         text = {}
         try:
             for text_line in text_array:
                 line = ""
                 for b in text_line:
                     line += chr(b.real)
                 parts = line.split("=", 1)
                 if len(parts)==2:
                     text[parts[0]] = parts[1]
             log(" text=%s", text)
         except Exception:
             log.error("failed to parse text record", exc_info=True)
         nargs = (dbus_to_native(x) for x in (interface, protocol, name, stype, domain, host, address, port, text))
         self.mdns_add(*nargs)
Example #10
0
def n(*args):
    return dbus_to_native(*args)
Example #11
0
def n(*args):
    return dbus_to_native(*args)
Example #12
0
	def service_removed(self, interface, protocol, name, stype, domain, flags):
		log("service_removed%s", (interface, protocol, name, stype, domain, flags))
		if self.mdns_remove:
			nargs = (dbus_to_native(x) for x in (interface, protocol, name, stype, domain, flags))
			self.mdns_remove(*nargs)