Exemple #1
0
 def __init__(self, config_id, type_ver):
     """
     Instances of this component are created from a service
     description that is selected by the given type and version.        
     The service description is looked up in a directory
     where it is stored as a file named ``type_ver.xml``.
     
     :param type: the service type
     :param ver: the service version
     """
     self._type, self._ver = type_ver.split(":", 1)
     self._path = "/%s_%s" % (self._type, self._ver)
     self.channel = ScopedChannel("upnp-web", self._path)
     # Now call super as only now the channel is known and this classes
     # handlers will be registered properly
     super(UPnPService, self).__init__();
     sfile = open(os.path.join(self._service_dir, 
                               "%s_%s.xml" % (self._type, self._ver)))
     sd = ElementTree.parse(sfile).getroot()
     sd.set("configId", str(config_id))
     # Some Android clients have problems with white spaces
     for el in sd.getiterator():
         if el.text:
             el.text = el.text.strip()
         if el.tail:
             el.tail = el.tail.strip()
     set_ns_prefixes(sd, { "": UPNP_SERVICE_SCHEMA })
     self._description = ElementTree.tostring(sd)
Exemple #2
0
 def __init__(self, config_id, type_ver):
     """
     Instances of this component are created from a service
     description that is selected by the given type and version.        
     The service description is looked up in a directory
     where it is stored as a file named ``type_ver.xml``.
     
     :param type: the service type
     :param ver: the service version
     """
     self._type, self._ver = type_ver.split(":", 1)
     self._path = "/%s_%s" % (self._type, self._ver)
     self.channel = ScopedChannel("upnp-web", self._path)
     # Now call super as only now the channel is known and this classes
     # handlers will be registered properly
     super(UPnPService, self).__init__()
     sfile = open(
         os.path.join(self._service_dir,
                      "%s_%s.xml" % (self._type, self._ver)))
     sd = ElementTree.parse(sfile).getroot()
     sd.set("configId", str(config_id))
     # Some Android clients have problems with white spaces
     for el in sd.getiterator():
         if el.text:
             el.text = el.text.strip()
         if el.tail:
             el.tail = el.tail.strip()
     set_ns_prefixes(sd, {"": UPNP_SERVICE_SCHEMA})
     self._description = ElementTree.tostring(sd)
Exemple #3
0
 def LastChange(self):
     root = Element(QName(self._event_ns, "Event"))
     inst = SubElement(root, QName(self._event_ns, "InstanceID"), 
                                   { "val": "0" })
     for name, value in self._changes.items():
         SubElement(inst, QName(self._event_ns, name), { "val": value })
     misc.set_ns_prefixes(root, { "": self._event_ns })
     return ElementTree.tostring(root, encoding="utf-8").decode("utf-8")
Exemple #4
0
 def __init__(self, channel, adapter, config_id, props, service_insts):
     super(UPnPDeviceController, self).__init__(channel=channel);
     # Generate a device description for the device
     desc = getattr(self, props.desc_gen)\
         (adapter, config_id, props, service_insts)
     misc.set_ns_prefixes(desc, { "": SSDP_DEVICE_SCHEMA })
     self.description = u"<?xml version='1.0' encoding='utf-8'?>" \
         + ElementTree.tostring(desc, encoding="utf-8").decode("utf-8")
Exemple #5
0
 def LastChange(self):
     root = Element(QName(self._event_ns, "Event"))
     inst = SubElement(root, QName(self._event_ns, "InstanceID"),
                       {"val": "0"})
     for name, value in self._changes.items():
         SubElement(inst, QName(self._event_ns, name), {"val": value})
     misc.set_ns_prefixes(root, {"": self._event_ns})
     return ElementTree.tostring(root, encoding="utf-8").decode("utf-8")
Exemple #6
0
 def LastChange(self):
     root = Element(QName(self._event_ns, "Event"))
     inst = SubElement(root, QName(self._event_ns, "InstanceID"), {"val": "0"})
     for name, value in self._changes.items():
         SubElement(inst, QName(self._event_ns, name), {"val": value})
     misc.set_ns_prefixes(root, {"": self._event_ns})
     writer = StringIO()
     ElementTree(root).write(writer, encoding="utf-8")
     return writer.getvalue()
Exemple #7
0
 def __init__(self, channel, adapter, config_id, props, service_insts):
     super(UPnPDeviceController, self).__init__(channel=channel);
     # Generate a device description for the device
     desc = getattr(self, props.desc_gen)\
         (adapter, config_id, props, service_insts)
     misc.set_ns_prefixes(desc, { "": SSDP_DEVICE_SCHEMA })
     writer = StringIO()
     writer.write("<?xml version='1.0' encoding='utf-8'?>")
     ElementTree(desc).write(writer, encoding="utf-8")
     self.description = writer.getvalue()
Exemple #8
0
 def LastChange(self):
     root = Element(QName(self._event_ns, "Event"))
     inst = SubElement(root, QName(self._event_ns, "InstanceID"),
                       {"val": "0"})
     for name, value in self._changes.items():
         SubElement(inst, QName(self._event_ns, name), {"val": value})
     misc.set_ns_prefixes(root, {"": self._event_ns})
     writer = StringIO()
     ElementTree(root).write(writer, encoding="utf-8")
     return writer.getvalue()
Exemple #9
0
 def __init__(self, channel, adapter, config_id, props, service_insts):
     super(UPnPDeviceController, self).__init__(channel=channel);
     # Generate a device description for the device
     desc = getattr(self, props.desc_gen)\
         (adapter, config_id, props, service_insts)
     misc.set_ns_prefixes(desc, { "": SSDP_DEVICE_SCHEMA })
     writer = StringIO()
     writer.write("<?xml version='1.0' encoding='utf-8'?>")
     ElementTree(desc).write(writer, encoding="utf-8")
     self.description = writer.getvalue()
Exemple #10
0
 def _on_notification(self, state_vars):
     root = Element(QName(UPNP_EVENT_NS, "propertyset"))
     for name, value in state_vars.items():
         prop = SubElement(root, QName(UPNP_EVENT_NS, "property"))
         val = SubElement(prop, QName(UPNP_EVENT_NS, name))
         if isinstance(value, bool):
             val.text = "1" if value else "0"
         else:
             val.text = unicode(value)
     misc.set_ns_prefixes(root, { "": UPNP_EVENT_NS })
     # Keep body as str for safe request handling
     body = "<?xml version='1.0' encoding='utf-8'?>" \
         + ElementTree.tostring(root, encoding="utf-8")
     self.fire(log(logging.DEBUG, "Notifying " 
                   + self._callbacks[self._used_callback]
                   + " about " + str(state_vars)), "logger")
     self.fire(request("NOTIFY", self._callbacks[self._used_callback], body,
                       { "CONTENT-TYPE": "text/xml; charset=\"utf-8\"",
                         "NT": "upnp:event",
                         "NTS": "upnp:propchange",
                         "SID": self.sid,
                         "SEQ": self._seq }))
     self._seq += 1