def endElement(self, name): name = unicode(name) current = self.pop() if name != current.qname(): raise Exception("malformed document") if current.charbuffer: current.text = Text(u"".join(current.charbuffer)) del current.charbuffer if current: current.trim()
def endElement(self, name): name = str(name) current = self.top() if len(current.charbuffer): current.text = Text(''.join(current.charbuffer)) del current.charbuffer if len(current): current.trim() if name == current.qname(): self.pop() else: raise Exception('malformed document')
def getValue(self, default=Text("")): """ Get the attributes value with optional default. @param default: An optional value to return when the attribute's value has not been set. @type default: basestring @return: The attribute's value, or I{default}. @rtype: L{Text} """ return self.value or default
def postprocess(self, content): """ Perform final processing of the resulting data structure as follows: - Mixed values (children and text) will have a result of the I{content.node}. - Semi-simple values (attributes, no-children and text) will have a result of a property object. - Simple values (no-attributes, no-children with text nodes) will have a string result equal to the value of the content.node.getText(). @param content: The current content being unmarshalled. @type content: L{Content} @return: The post-processed result. @rtype: I{any} """ node = content.node if len(node.children) and node.hasText(): return node attributes = AttrList(node.attributes) if ( attributes.rlen() and not len(node.children) and node.hasText() ): p = Factory.property(node.name, node.getText()) return merge(content.data, p) if len(content.data): return content.data lang = attributes.lang() if content.node.isnil(): return None if not len(node.children) and content.text is None: if self.nillable(content): return None else: return Text('', lang=lang) if isinstance(content.text, basestring): return Text(content.text, lang=lang) else: return content.text
def getValue(self, default=Text('')): """ Get the attributes value with optional default. @param default: An optional value to be return when the attribute's has not been set. @type default: basestring @return: The attribute's value, or I{default} @rtype: L{Text} """ if self.hasText(): return self.value else: return default
def setValue(self, value): """ Set the attributes value @param value: The new value (may be None) @type value: basestring @return: self @rtype: L{Attribute} """ if isinstance(value, Text): self.value = value else: self.value = Text(value) return self
def setText(self, value): """ Set the element's L{Text} content. @param value: The element's text value. @type value: basestring @return: self @rtype: I{Element} """ if isinstance(value, Text): self.text = value else: self.text = Text(value) return self