# HG changeset patch # User paulb # Date 1172618277 0 # Node ID 8cb9db849640f1605f5fe3873e390c0ec656a63d # Parent 5f127de2385a3cd65dd26480f49c88fa72da78ba [project @ 2007-02-27 23:17:57 by paulb] Fixed default implementation usage. Changed nodeValue to return None for various node types. diff -r 5f127de2385a -r 8cb9db849640 libxml2dom/__init__.py --- a/libxml2dom/__init__.py Tue Feb 27 23:17:30 2007 +0000 +++ b/libxml2dom/__init__.py Tue Feb 27 23:17:57 2007 +0000 @@ -166,9 +166,9 @@ PROCESSING_INSTRUCTION_NODE = xml.dom.Node.PROCESSING_INSTRUCTION_NODE TEXT_NODE = xml.dom.Node.TEXT_NODE - def __init__(self, node, impl, ownerDocument=None): + def __init__(self, node, impl=None, ownerDocument=None): self._node = node - self.impl = impl + self.impl = impl or default_impl self.ownerDocument = ownerDocument def as_native_node(self): @@ -190,6 +190,8 @@ return Node_namespaceURI(self._node) def _nodeValue(self): + if self.nodeType in null_value_node_types: + return None return Node_nodeValue(self._node) def _setNodeValue(self, value): @@ -470,13 +472,20 @@ self.entities = {} self.notations = {} +# Constants. + +null_value_node_types = [ + Node.DOCUMENT_NODE, Node.DOCUMENT_TYPE_NODE, Node.ELEMENT_NODE, + Node.ENTITY_NODE, Node.ENTITY_REFERENCE_NODE, Node.NOTATION_NODE + ] + # Utility functions. def createDocumentType(localName, publicId, systemId): - return impl.createDocumentType(localName, publicId, systemId) + return default_impl.createDocumentType(localName, publicId, systemId) def createDocument(namespaceURI, localName, doctype): - return impl.createDocument(namespaceURI, localName, doctype) + return default_impl.createDocument(namespaceURI, localName, doctype) def parse(stream_or_string, html=0, impl=None):