Commit 575712ea authored by Fred Drake's avatar Fred Drake

Tighten up the new NodeList implementation.

Clean up a little; do not create an alias that is only used once, or store
attributes with constant values in an instance.
parent 88a56857
...@@ -30,36 +30,36 @@ except AttributeError: ...@@ -30,36 +30,36 @@ except AttributeError:
del types del types
import xml.dom import xml.dom
_Node = xml.dom.Node
if list is type([]): if list is type([]):
class NodeList(list): class NodeList(list):
__dynamic__ = 0
def item(self, index): def item(self, index):
if 0 <= index < len(self): if 0 <= index < len(self):
return self[index] return self[index]
def __getattr__(self, name): length = property(lambda self: len(self),
if name == "length": doc="The number of nodes in the NodeList.")
return len(self)
raise AttributeError, name
else: else:
def NodeList(): def NodeList():
return [] return []
class Node(_Node): class Node(xml.dom.Node):
allnodes = {} allnodes = {}
_debug = 0 _debug = 0
_makeParentNodes = 1 _makeParentNodes = 1
debug = None debug = None
childNodeTypes = () childNodeTypes = ()
namespaceURI = None # this is non-null only for elements and attributes namespaceURI = None # this is non-null only for elements and attributes
parentNode = None
ownerDocument = None
def __init__(self): def __init__(self):
self.childNodes = NodeList() self.childNodes = NodeList()
self.parentNode = self.ownerDocument = None
if Node._debug: if Node._debug:
index = repr(id(self)) + repr(self.__class__) index = repr(id(self)) + repr(self.__class__)
Node.allnodes[index] = repr(self.__dict__) Node.allnodes[index] = repr(self.__dict__)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment