def fromElement(self, element): """ initializes Storage connection from element. First properties are read and then attributes in the element. Results to attributes precedence. """ from comoonics.ComProperties import Properties props=element.getElementsByTagName(Properties.TAGNAME) #log.debug("fromElement: %s, %u" %(element, len(props))) if len(props)>=1: self.properties=Properties(props[0]) for propertyname in self.properties.keys(): self.log.debug("fromElement: Setting attribute %s, %s" %(propertyname, self.properties[propertyname].getAttribute("value"))) setattr(self, propertyname, self.properties[propertyname].getAttribute("value")) for attribute in element.attributes: self.__dict__[attribute.name]=attribute.value
def _parseSection(self, section, sectionelement, validsubsections, parent=None, rootElement=False): _name=section if sectionelement.hasAttribute("name"): _name=sectionelement.getAttribute('name') _cursect={'__name__': _name, '__element__': sectionelement} if parent: if not rootElement: _cursect['__parent__']=parent _cursect['parent']=parent['__name__'] else: rootElement=False _add_tags=None if self.ADD_TAGS.has_key(sectionelement.nodeName): _add_tags=self.ADD_TAGS[sectionelement.nodeName] _section=None if validsubsections: _args=None for subsection in validsubsections: for _child in sectionelement.childNodes: if _child.nodeType == Node.ELEMENT_NODE and _child.nodeName == subsection: mylogger.debug("_parseSection(%s, %s): subsection, %s, %s" %(section, validsubsections, subsection, _child)) _section=self._parseSection(subsection, _child, validsubsections, _cursect, rootElement) self._subsection_prefixes[section]=subsection self._sections[self.formatSubsectionPair(section, _section['__name__'])]=_section if _add_tags and _child.nodeName in _add_tags: if hasattr(self, "_parse_"+_child.nodeName): func=getattr(self, "_parse_"+_child.nodeName) func(_cursect, _child) for _child in sectionelement.childNodes: if _child.nodeType == Node.ELEMENT_NODE and _child.nodeName == self.ARGS_TAGNAME: _cursect[self.ARGS_TAGNAME]=self.formatArgs(self._parseArgs(_child)) elif _child.nodeType == Node.ELEMENT_NODE and _child.nodeName == Properties.TAGNAME: _properties=Properties(_child) mylogger.debug("_parseSection(%s): properties: %s" %(section, _properties)) for (_name, _property) in _properties.items(): _cursect[_name]=_property.getValue() for i in range(sectionelement.attributes.length): _child=sectionelement.attributes.item(i) _cursect[_child.name]=_child.value mylogger.debug("_parseSection(%s, %s): %s->attribute: %s: %s" %(section, validsubsections, _cursect['__name__'], _child.name, _child.value)) return _cursect
def __init__(self, testMethod="runTest"): from comoonics import XmlTools super(test_Properties, self).__init__(testMethod) document = XmlTools.parseXMLString(xml_str) self.properties = Properties(document.documentElement, document)