Пример #1
0
    def _send_error(self, env, start_response, error):

        envelope = ElementTree.Element(SQNS('Envelope'),
                                       {SQNS('encodingStyle'): SES})

        desc = ", ".join(filter(lambda p: p,
                                [error.description, error.detail]))
        err = ElementTree.Element(CNS('UPnPError'))
        err.extend([
            _TextElement(CNS('errorCode'), str(error.code)),
            _TextElement(CNS('errorDescription'), desc)
        ])
        detail = ElementTree.Element(SQNS('detail'))
        detail.append(err)

        fault = ElementTree.SubElement(
            ElementTree.SubElement(envelope, SQNS('Body')), SQNS('Fault'))
        fault.extend([
            _TextElement(SQNS('faultCode'), 'Client'),
            _TextElement(SQNS('faultString'), 'UPnPError'),
            detail,
        ])

        start_response(utils.status(500), [('Content-Type', 'text/xml')])
        return [utils.tostring(envelope, default_namespace=SQNS.ns)]
Пример #2
0
    def _GET_desc_xml(self, env, start_response):

        scpd = ElementTree.Element(SNS('scpd'))

        from upnpy import UPNP_VERSION
        ElementTree.SubElement(scpd, SNS('specVersion')).extend([
            _TextElement(SNS('major'),
                         str(UPNP_VERSION).split('.')[0]),
            _TextElement(SNS('minor'),
                         str(UPNP_VERSION).split('.')[1])
        ])

        cls = self.__class__
        ElementTree.SubElement(scpd, SNS('actionList')).extend([
            getattr(cls, n).desc(n) for n in dir(cls)
            if isinstance(getattr(cls, n), Action)
        ])

        ElementTree.SubElement(scpd, SNS('serviceStateTable')).extend([
            getattr(cls, n).desc(n) for n in dir(cls)
            if isinstance(getattr(cls, n), StateVariable)
        ])

        start_response(utils.status(200), [('Content-Type', 'text/xml')])
        return [utils.tostring(scpd, default_namespace=SNS.ns)]
Пример #3
0
 def on_payload(self, event):
     try:
         self.callback(
             'xmpp', 'payload', 'inbound', 'xmpp.payload',
             utils.tostring(event.xml,
                            namespace_map={},
                            cdata=('encoded', )))
     except:
         utils.dumpException('exception during on_payload')
Пример #4
0
    def _send_response(self, env, start_response, response):

        envelope = ElementTree.Element(SQNS('Envelope'),
                                       {SQNS('encodingStyle'): SES})

        ElementTree.SubElement(
            ElementTree.SubElement(envelope, SQNS('Body')),
            self._stns('%sResponse' % env['upnp.action'])).extend(
                [_TextElement(self._stns(k), v) for k, v in response.items()])
        start_response(utils.status(200), [('Content-Type', 'text/xml')])
        return [utils.tostring(envelope, default_namespace=SQNS.ns)]
Пример #5
0
    def GetACLData(self):

        acl = ElementTree.Element(DPNS('ACL'),
                                  {XSINS('schemaLocation'): DPLOC})

        print[str(i) for i in Identity.all()]
        ElementTree.SubElement(acl, DPNS('Identities')).extend(
            i.desc() for i in Identity.all())

        roles = ElementTree.SubElement(acl, DPNS('Roles'))
        for role in self._collect_roles(self._parent):
            ElementTree.SubElement(roles, DPNS('Role')).append(
                _TextElement(DPNS('Name'), role))

        return utils.tostring(acl, default_namespace=DPNS.ns)
Пример #6
0
    def _GET_desc_xml(self, env, start_response):

        dev = ElementTree.Element(DNS('device'))

        for a in self._ATTRS:
            dev.append(_TextElement(DNS(a), getattr(self, a)))

        if self.icons:
            ico = ElementTree.SubElement(dev, DNS('iconList'))
            #for i in self.icons

        if self.services:
            servs = ElementTree.SubElement(dev, DNS('serviceList'))
            for name, s in self.services.items():
                servs.append(s._short_desc())

        if self.devices:
            devs = ElementTree.SubElement(dev, DNS('deviceList'))
            for name, d in self.devices.items():
                devs.append(s._GET_desc_xml(env, start_response))

        if self._parent:
            return dev

        root = ElementTree.Element(DNS('root'))

        from upnpy import UPNP_VERSION
        ElementTree.SubElement(root, DNS('specVersion')).extend([
            _TextElement(DNS('major'),
                         str(UPNP_VERSION).split('.')[0]),
            _TextElement(DNS('minor'),
                         str(UPNP_VERSION).split('.')[1])
        ])

        root.append(dev)

        start_response(utils.status(200), [('Content-Type', 'text/xml')])
        return [utils.tostring(root, default_namespace=DNS.ns)]
Пример #7
0
    def _notification_message(self, keys=None):

        if keys is None:
            keys = []
            cls = self.__class__
            for k in dir(self):
                try:
                    if not isinstance(getattr(cls, k), StateVariable): continue
                    if getattr(self, k, None) is None: continue
                    keys.append(k)
                except AttributeError:
                    pass
        if not keys:
            return

        pset = ElementTree.Element(ENS('propertyset'))
        for k in keys:
            ElementTree.SubElement(
                ElementTree.SubElement(pset, ENS('property')),
                self._stns(k)).text = str(getattr(self, k))

        return utils.tostring(pset,
                              encoding='utf-8',
                              default_namespace=self._stns.ns)