예제 #1
0
    def dump(self):
        Logr.debug("xml tree dumped")
        scpd = et.Element('scpd', attrib={
            'xmlns': 'urn:schemas-upnp-org:service-1-0',
        })

        # specVersion
        specVersion = et.Element('specVersion')
        specVersion.append(make_element('major', str(self.version[0])))
        specVersion.append(make_element('minor', str(self.version[1])))
        scpd.append(specVersion)

        # actionList
        actionList = et.Element('actionList')
        for action_name, action_args in self.actions.items():
            action = et.Element('action')
            action.append(make_element('name', action_name))

            argumentList = et.Element('argumentList')
            for arg in action_args:
                argumentList.append(arg.dump())
            action.append(argumentList)

            actionList.append(action)
        scpd.append(actionList)

        # serviceStateTable
        serviceStateTable = et.Element('serviceStateTable')
        for stateVariable in self.stateVariables.values():
            serviceStateTable.append(stateVariable.dump())
        scpd.append(serviceStateTable)

        return scpd
예제 #2
0
파일: __init__.py 프로젝트: zanppa/PyUPnP
    def dump(self):
        Logr.debug("xml tree dumped")
        scpd = et.Element('scpd',
                          attrib={
                              'xmlns': 'urn:schemas-upnp-org:service-1-0',
                          })

        # specVersion
        specVersion = et.Element('specVersion')
        specVersion.append(make_element('major', str(self.version[0])))
        specVersion.append(make_element('minor', str(self.version[1])))
        scpd.append(specVersion)

        # actionList
        actionList = et.Element('actionList')
        for action_name, action_args in self.actions.items():
            action = et.Element('action')
            action.append(make_element('name', action_name))

            argumentList = et.Element('argumentList')
            for arg in action_args:
                argumentList.append(arg.dump())
            action.append(argumentList)

            actionList.append(action)
        scpd.append(actionList)

        # serviceStateTable
        serviceStateTable = et.Element('serviceStateTable')
        for stateVariable in self.stateVariables.values():
            serviceStateTable.append(stateVariable.dump())
        scpd.append(serviceStateTable)

        return scpd
예제 #3
0
파일: __init__.py 프로젝트: zanppa/PyUPnP
 def dump(self):
     argument = et.Element('argument')
     argument.append(make_element('name', self.name))
     argument.append(make_element('direction', self.direction))
     argument.append(
         make_element('relatedStateVariable', self.stateVariable))
     return argument
예제 #4
0
파일: device.py 프로젝트: AchillesA/PyUPnP
 def dump(self):
     icon = et.Element('icon')
     icon.append(make_element('mimetype', self.mimetype))
     icon.append(make_element('width', str(self.width)))
     icon.append(make_element('height', str(self.height)))
     icon.append(make_element('depth', str(self.depth)))
     icon.append(make_element('url', self.url))
     return icon
예제 #5
0
 def dump(self):
     icon = et.Element('icon')
     icon.append(make_element('mimetype', self.mimetype))
     icon.append(make_element('width', str(self.width)))
     icon.append(make_element('height', str(self.height)))
     icon.append(make_element('depth', str(self.depth)))
     icon.append(make_element('url', self.url))
     return icon
예제 #6
0
파일: __init__.py 프로젝트: zanppa/PyUPnP
    def dump(self):
        sendEventsStr = "no"
        if self.sendEvents:
            sendEventsStr = "yes"

        stateVariable = et.Element('stateVariable', sendEvents=sendEventsStr)

        stateVariable.append(make_element('name', self.name))
        stateVariable.append(make_element('dataType', self.dataType))

        if self.allowedValues:
            allowedValues = et.Element('allowedValueList')
            for value in self.allowedValues:
                allowedValues.append(make_element('allowedValue', value))
            stateVariable.append(allowedValues)

        return stateVariable
예제 #7
0
    def dump(self):
        sendEventsStr = "no"
        if self.sendEvents:
            sendEventsStr = "yes"

        stateVariable = et.Element('stateVariable', sendEvents=sendEventsStr)

        stateVariable.append(make_element('name', self.name))
        stateVariable.append(make_element('dataType', self.dataType))

        if self.allowedValues:
            allowedValues = et.Element('allowedValueList')
            for value in self.allowedValues:
                allowedValues.append(make_element('allowedValue', value))
            stateVariable.append(allowedValues)

        return stateVariable
예제 #8
0
    def dump(self):
        Logr.debug("xml tree dumped")
        root = et.Element('root', attrib={'configId': str(self.configID)})
        for prefix, namespace in self.namespaces.items():
            if prefix == '':
                prefix = 'xmlns'
            else:
                prefix = 'xmlns:' + prefix
            root.attrib[prefix] = namespace

        # specVersion
        specVersion = et.Element('specVersion')
        specVersion.append(make_element('major', str(self.version[0])))
        specVersion.append(make_element('minor', str(self.version[1])))
        root.append(specVersion)

        root.append(self.dump_device())
        return root
예제 #9
0
파일: device.py 프로젝트: AchillesA/PyUPnP
    def dump(self):
        Logr.debug("xml tree dumped")
        root = et.Element('root', attrib={
            'configId': str(self.configID)
        })
        for prefix, namespace in self.namespaces.items():
            if prefix == '':
                prefix = 'xmlns'
            else:
                prefix = 'xmlns:' + prefix
            root.attrib[prefix] = namespace

        # specVersion
        specVersion = et.Element('specVersion')
        specVersion.append(make_element('major', str(self.version[0])))
        specVersion.append(make_element('minor', str(self.version[1])))
        root.append(specVersion)

        root.append(self.dump_device())
        return root
예제 #10
0
    def __init__(self, address):
        Device.__init__(self)
        #super(Device, self).__init__()

        self.uuid = '2fac1234-31f8-11b4-a222-08002b34c003'

        self.tmApplicationServer = TmApplicationServer()
        self.tmNotificationServer = TmNotificationServer()
        self.tmClientProfile = TmClientProfile()

        self.services = [
            self.tmApplicationServer,
            self.tmNotificationServer,
            self.tmClientProfile,
        ]

        self.icons = [
            DeviceIcon('image/png', 48, 48, 24,
                       'http://{}:8000/icon.png'.format(address))
        ]

        self.namespaces[''] = 'urn:schemas-upnp-org:device-1-0'

        #self.extras['X_Signature'] = 'TODO'      # TODO: Which version?
        #self.extras['X_presentations'] = 'TODO'  # Version 1.2 and forwards

        # Build version info
        linkVersion = et.Element('X_mirrorLinkVersion')
        major = make_element('majorVersion', '1')
        minor = make_element('minorVersion', '0')
        linkVersion.append(major)
        linkVersion.append(minor)

        # TODO: Signature

        # List additional elements
        self.extraElements = [linkVersion]
예제 #11
0
    def notify(self, props):
        """

        :type props: EventProperty or list of EventProperty
        """
        if type(props) is not list:
            props = [props]

        if self.expired:
            return

        if self.check_expiration():
            Logr.info("(%s) subscription expired", self.sid)
            return

        # noinspection PyTypeChecker
        Logr.debug("(%s) notify(), %d props: %s", self.sid, len(props),
                   str(props))

        headers = {
            'NT': 'upnp:event',
            'NTS': 'upnp:propchange',
            'SID': self.sid,
            'SEQ': self.next_notify_key
        }

        _propertyset = et.Element(
            'e:propertyset',
            attrib={'xmlns:e': 'urn:schemas-upnp-org:event-1-0'})

        for prop in props:
            _property = et.Element('e:property')
            _property.append(make_element(prop.name, str(prop.value)))
            _propertyset.append(_property)

        data = '<?xml version="1.0"?>' + et.tostring(_propertyset)

        try:
            requests.request('NOTIFY',
                             self.callback,
                             headers=headers,
                             data=data)
        except requests.exceptions.ConnectionError:
            pass
        self._increment_notify_key()
예제 #12
0
파일: event.py 프로젝트: AchillesA/PyUPnP
    def notify(self, props):
        """

        :type props: EventProperty or list of EventProperty
        """
        if type(props) is not list:
            props = [props]

        if self.expired:
            return

        if self.check_expiration():
            Logr.info("(%s) subscription expired", self.sid)
            return

        # noinspection PyTypeChecker
        Logr.debug("(%s) notify(), %d props: %s", self.sid, len(props), str(props))

        headers = {
            'NT': 'upnp:event',
            'NTS': 'upnp:propchange',
            'SID': self.sid,
            'SEQ': self.next_notify_key
        }

        _propertyset = et.Element('e:propertyset', attrib={
            'xmlns:e': 'urn:schemas-upnp-org:event-1-0'
        })

        for prop in props:
            _property = et.Element('e:property')
            _property.append(make_element(prop.name, str(prop.value)))
            _propertyset.append(_property)

        data = '<?xml version="1.0"?>' + et.tostring(_propertyset)

        try:
            requests.request('NOTIFY', self.callback,
                             headers=headers, data=data)
        except requests.exceptions.ConnectionError:
            pass
        self._increment_notify_key()
예제 #13
0
    def dump_device(self):
        device = et.Element('device')

        for attr_name in [
                'deviceType', 'friendlyName', 'manufacturer',
                'manufacturerURL', 'modelDescription', 'modelName',
                'modelNumber', 'modelURL', 'serialNumber', 'UDN'
        ]:
            if hasattr(self, attr_name):
                val = getattr(self, attr_name)
                if val is not None:
                    device.append(make_element(attr_name, val))

        for name, val in self.extras.items():
            device.append(make_element(name, val))

        # iconList
        iconList = et.Element('iconList')
        for icon in self.icons:
            iconList.append(icon.dump())
        device.append(iconList)

        # serviceList
        serviceList = et.Element('serviceList')
        for service in self.services:
            _service = et.Element('service')
            _service.append(make_element('serviceType', service.serviceType))
            _service.append(make_element('serviceId', service.serviceId))
            _service.append(
                make_element('controlURL',
                             '/' + service.serviceId + '/control'))
            _service.append(
                make_element('eventSubURL',
                             '/' + service.serviceId + '/event'))
            _service.append(make_element('SCPDURL', '/' + service.serviceId))
            serviceList.append(_service)
        device.append(serviceList)

        return device
예제 #14
0
파일: device.py 프로젝트: AchillesA/PyUPnP
    def dump_device(self):
        device = et.Element('device')

        for attr_name in [
            'deviceType', 'friendlyName',
            'manufacturer', 'manufacturerURL',
            'modelDescription', 'modelName', 'modelNumber', 'modelURL', 'serialNumber',
            'UDN'
        ]:
            if hasattr(self, attr_name):
                val = getattr(self, attr_name)
                if val is not None:
                    device.append(make_element(attr_name, val))

        for name, val in self.extras.items():
            device.append(make_element(name, val))

        # iconList
        iconList = et.Element('iconList')
        for icon in self.icons:
            iconList.append(icon.dump())
        device.append(iconList)

        # serviceList
        serviceList = et.Element('serviceList')
        for service in self.services:
            _service = et.Element('service')
            _service.append(make_element('serviceType', service.serviceType))
            _service.append(make_element('serviceId', service.serviceId))
            _service.append(make_element('controlURL', '/' + service.serviceId + '/control'))
            _service.append(make_element('eventSubURL', '/' + service.serviceId + '/event'))
            _service.append(make_element('SCPDURL', '/' + service.serviceId))
            serviceList.append(_service)
        device.append(serviceList)

        return device
예제 #15
0
 def dump(self):
     argument = et.Element('argument')
     argument.append(make_element('name', self.name))
     argument.append(make_element('direction', self.direction))
     argument.append(make_element('relatedStateVariable', self.stateVariable))
     return argument