Exemplo n.º 1
0
    def asEtreeSubNode(self, rootNode):
        _ns = Prefix.partialMap(Prefix.DPWS, Prefix.WSA)
        # reverse lookup( key is namespace, value is prefix)
        res = {}
        for k, v in _ns.items():
            res[v] = k
        for k, v in rootNode.nsmap.items():
            res[v] = k

        # must explicitely add namespaces of types to Host node, because list of qnames is not handled by lxml
        typesTexts = []
        if self.types:
            for qname in self.types:
                prefix = res.get(qname.namespace)
                if not prefix:
                    # create a random prefix
                    prefix = '_dpwsh{}'.format(len(_ns))
                    _ns[prefix] = qname.namespace
                typesTexts.append('{}:{}'.format(prefix, qname.localname))

        hostNode = etree_.SubElement(rootNode, dpwsTag('Host'))  #, nsmap=_ns)
        epRefNode = etree_.SubElement(
            hostNode, wsaTag('EndpointReference'))  #, nsmap=_ns)
        for epRef in self.endpointReferences:
            epRef.asEtreeSubNode(epRefNode)

        if typesTexts:
            typesNode = etree_.SubElement(
                hostNode, dpwsTag('Types'), nsmap=_ns
            )  # add also namespace prefixes that were locally generated
            typesText = ' '.join(typesTexts)
            typesNode.text = typesText
Exemplo n.º 2
0
 def asEtreeSubNode(self, rootNode):
     hostedNode = etree_.SubElement(rootNode, dpwsTag('Hosted'))
     epRefNode = etree_.SubElement(hostedNode, wsaTag('EndpointReference'))
     for epRef in self.endpointReferences:
         epRef.asEtreeSubNode(epRefNode)
     if self.types:
         typesText = ' '.join(
             [docNameFromQName(t, rootNode.nsmap) for t in self.types])
         typesNode = etree_.SubElement(hostedNode,
                                       dpwsTag('Types'))  #, nsmap=ns)
         typesNode.text = typesText
     serviceNode = etree_.SubElement(hostedNode,
                                     dpwsTag('ServiceId'))  #, nsmap=ns)
     serviceNode.text = self.serviceId
Exemplo n.º 3
0
 def asEtreeSubNode(self, rootNode):
     thisDevice = etree_.SubElement(rootNode,
                                    dpwsTag('ThisDevice'),
                                    nsmap=Prefix.partialMap(Prefix.DPWS))
     for lang, name in self.friendlyName.items():
         friendlyName = etree_.SubElement(thisDevice,
                                          dpwsTag('FriendlyName'))
         friendlyName.text = name
         friendlyName.set(_LANGUAGE_ATTR, lang)
     firmwareVersion = etree_.SubElement(thisDevice,
                                         dpwsTag('FirmwareVersion'))
     firmwareVersion.text = self.firmwareVersion
     serialNumber = etree_.SubElement(thisDevice, dpwsTag('SerialNumber'))
     serialNumber.text = self.serialNumber
Exemplo n.º 4
0
    def asEtreeSubNode(self, rootNode):
        thisModel = etree_.SubElement(rootNode,
                                      dpwsTag('ThisModel'),
                                      nsmap=Prefix.partialMap(Prefix.DPWS))
        for lang, name in self.manufacturer.items():
            manufacturer = etree_.SubElement(thisModel,
                                             dpwsTag('Manufacturer'))
            manufacturer.text = name
            if lang is not None:
                manufacturer.set(_LANGUAGE_ATTR, lang)

        manufacturerUrl = etree_.SubElement(thisModel,
                                            dpwsTag('ManufacturerUrl'))
        manufacturerUrl.text = self.manufacturerUrl

        for lang, name in self.modelName.items():
            manufacturer = etree_.SubElement(thisModel, dpwsTag('ModelName'))
            manufacturer.text = name
            if lang is not None:
                manufacturer.set(_LANGUAGE_ATTR, lang)

        modelNumber = etree_.SubElement(thisModel, dpwsTag('ModelNumber'))
        modelNumber.text = self.modelNumber
        modelUrl = etree_.SubElement(thisModel, dpwsTag('ModelUrl'))
        modelUrl.text = self.modelUrl
        presentationUrl = etree_.SubElement(thisModel,
                                            dpwsTag('PresentationUrl'))
        presentationUrl.text = self.presentationUrl