def build_xml(self): root = etree.Element('scpd', nsmap={None: 'urn:schemas-upnp-org:service-1-0'}) e = etree.SubElement(root, 'specVersion') etree.SubElement(e, 'major').text = '1' etree.SubElement(e, 'minor').text = '0' e = etree.SubElement(root, 'actionList') for action in list(self.service_server._actions.values()): s = etree.SubElement(e, 'action') etree.SubElement(s, 'name').text = action.get_name() al = etree.SubElement(s, 'argumentList') for argument in action.get_arguments_list(): a = etree.SubElement(al, 'argument') etree.SubElement(a, 'name').text = argument.get_name() etree.SubElement(a, 'direction').text = argument.get_direction() etree.SubElement(a, 'relatedStateVariable' ).text = argument.get_state_variable() e = etree.SubElement(root, 'serviceStateTable') for var in list(self.service_server._variables[0].values()): s = etree.SubElement(e, 'stateVariable') if var.send_events: s.attrib['sendEvents'] = 'yes' else: s.attrib['sendEvents'] = 'no' etree.SubElement(s, 'name').text = var.name etree.SubElement(s, 'dataType').text = var.data_type if not var.has_vendor_values and len(var.allowed_values): v = etree.SubElement(s, 'allowedValueList') for value in var.allowed_values: etree.SubElement(v, 'allowedValue').text = value if var.allowed_value_range is not None and len( var.allowed_value_range) > 0: complete = True for name, value in list(var.allowed_value_range.items()): if value is None: complete = False if complete: avl = etree.SubElement(s, 'allowedValueRange') for name, value in list(var.allowed_value_range.items()): if value is not None: etree.SubElement(avl, name).text = str(value) return etree.tostring(root, encoding='utf-8', xml_declaration=True, pretty_print=True)
def build_xml(self): root = ET.Element('scpd') root.attrib['xmlns'] = 'urn:schemas-upnp-org:service-1-0' e = ET.SubElement(root, 'specVersion') ET.SubElement(e, 'major').text = '1' ET.SubElement(e, 'minor').text = '0' e = ET.SubElement(root, 'actionList') for action in self.service_server._actions.values(): s = ET.SubElement(e, 'action') ET.SubElement(s, 'name').text = action.get_name() al = ET.SubElement(s, 'argumentList') for argument in action.get_arguments_list(): a = ET.SubElement(al, 'argument') ET.SubElement(a, 'name').text = argument.get_name() ET.SubElement(a, 'direction').text = argument.get_direction() ET.SubElement(a, 'relatedStateVariable' ).text = argument.get_state_variable() e = ET.SubElement(root, 'serviceStateTable') for var in self.service_server._variables[0].values(): s = ET.SubElement(e, 'stateVariable') if var.send_events == True: s.attrib['sendEvents'] = 'yes' else: s.attrib['sendEvents'] = 'no' ET.SubElement(s, 'name').text = var.name ET.SubElement(s, 'dataType').text = var.data_type if (not var.has_vendor_values and len(var.allowed_values)): #if len(var.allowed_values): v = ET.SubElement(s, 'allowedValueList') for value in var.allowed_values: ET.SubElement(v, 'allowedValue').text = value if (var.allowed_value_range != None and len(var.allowed_value_range) > 0): complete = True for name, value in var.allowed_value_range.items(): if value == None: complete = False if complete == True: avl = ET.SubElement(s, 'allowedValueRange') for name, value in var.allowed_value_range.items(): if value != None: ET.SubElement(avl, name).text = str(value) return """<?xml version="1.0" encoding="utf-8"?>""" + ET.tostring( root, encoding='utf-8')
def __init__(self, server, control): root = ET.Element('scpd') root.attrib['xmlns']='urn:schemas-upnp-org:service-1-0' e = ET.SubElement(root, 'specVersion') ET.SubElement( e, 'major').text = '1' ET.SubElement( e, 'minor').text = '0' e = ET.SubElement( root, 'actionList') for action in server._actions.values(): s = ET.SubElement( e, 'action') ET.SubElement( s, 'name').text = action.get_name() al = ET.SubElement( s, 'argumentList') for argument in action.get_arguments_list(): a = ET.SubElement( al, 'argument') ET.SubElement( a, 'name').text = argument.get_name() ET.SubElement( a, 'direction').text = argument.get_direction() ET.SubElement( a, 'relatedStateVariable').text = argument.get_state_variable() e = ET.SubElement( root, 'serviceStateTable') for var in server._variables[0].values(): s = ET.SubElement( e, 'stateVariable') if var.send_events == True: s.attrib['sendEvents'] = 'yes' else: s.attrib['sendEvents'] = 'no' ET.SubElement( s, 'name').text = var.name ET.SubElement( s, 'dataType').text = var.data_type if(not var.has_vendor_values and len(var.allowed_values)): #if len(var.allowed_values): v = ET.SubElement( s, 'allowedValueList') for value in var.allowed_values: ET.SubElement( v, 'allowedValue').text = value if( var.allowed_value_range != None and len(var.allowed_value_range) > 0): complete = True for name,value in var.allowed_value_range.items(): if value == None: complete = False if complete == True: avl = ET.SubElement( s, 'allowedValueRange') for name,value in var.allowed_value_range.items(): if value != None: ET.SubElement( avl, name).text = str(value) self.xml = """<?xml version="1.0" encoding="utf-8"?>""" + ET.tostring( root, encoding='utf-8') static.Data.__init__(self, self.xml, 'text/xml')
def build_xml(self): root = etree.Element('scpd', nsmap={None: 'urn:schemas-upnp-org:service-1-0'}) e = etree.SubElement(root, 'specVersion') etree.SubElement(e, 'major').text = '1' etree.SubElement(e, 'minor').text = '0' e = etree.SubElement(root, 'actionList') for action in self.service_server._actions.values(): s = etree.SubElement(e, 'action') etree.SubElement(s, 'name').text = action.get_name() al = etree.SubElement(s, 'argumentList') for argument in action.get_arguments_list(): a = etree.SubElement(al, 'argument') etree.SubElement(a, 'name').text = argument.get_name() etree.SubElement(a, 'direction').text = argument.get_direction() etree.SubElement(a, 'relatedStateVariable').text = argument.get_state_variable() e = etree.SubElement(root, 'serviceStateTable') for var in self.service_server._variables[0].values(): s = etree.SubElement(e, 'stateVariable') if var.send_events: s.attrib['sendEvents'] = 'yes' else: s.attrib['sendEvents'] = 'no' etree.SubElement(s, 'name').text = var.name etree.SubElement(s, 'dataType').text = var.data_type if not var.has_vendor_values and len(var.allowed_values): v = etree.SubElement(s, 'allowedValueList') for value in var.allowed_values: etree.SubElement(v, 'allowedValue').text = value if var.allowed_value_range is not None and len(var.allowed_value_range) > 0: complete = True for name, value in var.allowed_value_range.items(): if value is None: complete = False if complete: avl = etree.SubElement(s, 'allowedValueRange') for name, value in var.allowed_value_range.items(): if value is not None: etree.SubElement(avl, name).text = str(value) return etree.tostring(root, encoding='utf-8', xml_declaration=True, pretty_print=True)