def __init__(self, filename="", str=""): try: # print str self._filename = filename if len(filename) > 0: et = xml.etree.ElementTree.parse(self.path) root = et.getroot() elif len(str) > 0: root = xml.etree.ElementTree.fromstring(str) else: root = xml.etree.ElementTree.fromstring(default_rtcprofile) self.node = root self.attrib = root.attrib self.children = [] [uri, tag] = normalize(root.tag) for basicInfo in root.findall('{%s}BasicInfo' % uri): self.name = basicInfo.attrib['{%s}name' % uri] self.category = basicInfo.attrib['{%s}category' % uri] self.basicInfo = Node(basicInfo) docs = basicInfo.findall('{%s}Doc' % get_long_ns('rtcDoc')) if len(docs) != 0: self.basicInfo.doc = Doc(docs[0]) else: self.basicInfo.doc = Doc(default_basicInfo_doc_str) self.basicInfo.children.append(self.basicInfo.doc) self.children.append(self.basicInfo) for language in root.findall('{%s}Language' % uri): self.language = Node( language) #language.attrib['{%s}kind' % uri] #docs = language.findall('{%s}Doc' % get_long_ns('rtcDoc')) #if len(docs) != 0: # self.language.doc = Doc(docs[0]) #else: # self.language.doc = Doc() #self.language.children.append(self.language.doc) self.children.append(self.language) for action in root.findall('{%s}Actions' % uri): self.actions = Actions(action) self.children.append(self.actions) self.dataports = [] for dport in root.findall('{%s}DataPorts' % uri): dp = DataPort(dport) self.dataports.append(dp) #Node(dport)) self.children.append(dp) #Node(dport)) #self.dataports.append(DataPort(dport.attrib['{%s}name' % uri], # dport.attrib['{%s}type' % uri], # dport.attrib['{%s}portType' % uri])) self.serviceports = [] for sport in root.findall('{%s}ServicePorts' % uri): sp = ServicePort(sport) self.serviceports.append(sp) self.children.append(sp) self.configurationSet = None # self.children.append(self.configurationSet) if len(root.findall('{%s}ConfigurationSet' % uri)) > 1: raise InvalidRTCProfileError( filename, 'Multiple ConfigurationSet Node.') for cset in root.findall('{%s}ConfigurationSet' % uri): cs = ConfigurationSet(cset) self.configurationSet = cs self.children.append(cs) break except Exception, e: traceback.print_exc() raise InvalidRTCProfileError(filename, 'Parsing Error')