Commit 33d2b84b authored by Fred Drake's avatar Fred Drake

CharacterData methods: Update self.length on changes instead of extended

    the __getattr__() handler.

Text.splitText():  Update the length and nodeValue attributes.
parent 87432f42
...@@ -619,10 +619,7 @@ class CharacterData(Node): ...@@ -619,10 +619,7 @@ class CharacterData(Node):
raise TypeError, "node contents must be a string" raise TypeError, "node contents must be a string"
Node.__init__(self) Node.__init__(self)
self.data = self.nodeValue = data self.data = self.nodeValue = data
self.length = len(data)
def __getattr__(self, name):
if name == "length":
return len(self.data)
def __repr__(self): def __repr__(self):
if len(self.data) > 10: if len(self.data) > 10:
...@@ -644,6 +641,7 @@ class CharacterData(Node): ...@@ -644,6 +641,7 @@ class CharacterData(Node):
def appendData(self, arg): def appendData(self, arg):
self.data = self.data + arg self.data = self.data + arg
self.nodeValue = self.data self.nodeValue = self.data
self.length = len(self.data)
def insertData(self, offset, arg): def insertData(self, offset, arg):
if offset < 0: if offset < 0:
...@@ -654,6 +652,7 @@ class CharacterData(Node): ...@@ -654,6 +652,7 @@ class CharacterData(Node):
self.data = "%s%s%s" % ( self.data = "%s%s%s" % (
self.data[:offset], arg, self.data[offset:]) self.data[:offset], arg, self.data[offset:])
self.nodeValue = self.data self.nodeValue = self.data
self.length = len(self.data)
def deleteData(self, offset, count): def deleteData(self, offset, count):
if offset < 0: if offset < 0:
...@@ -665,6 +664,7 @@ class CharacterData(Node): ...@@ -665,6 +664,7 @@ class CharacterData(Node):
if count: if count:
self.data = self.data[:offset] + self.data[offset+count:] self.data = self.data[:offset] + self.data[offset+count:]
self.nodeValue = self.data self.nodeValue = self.data
self.length = len(self.data)
def replaceData(self, offset, count, arg): def replaceData(self, offset, count, arg):
if offset < 0: if offset < 0:
...@@ -677,6 +677,7 @@ class CharacterData(Node): ...@@ -677,6 +677,7 @@ class CharacterData(Node):
self.data = "%s%s%s" % ( self.data = "%s%s%s" % (
self.data[:offset], arg, self.data[offset+count:]) self.data[:offset], arg, self.data[offset+count:])
self.nodeValue = self.data self.nodeValue = self.data
self.length = len(self.data)
class Text(CharacterData): class Text(CharacterData):
nodeType = Node.TEXT_NODE nodeType = Node.TEXT_NODE
...@@ -695,6 +696,8 @@ class Text(CharacterData): ...@@ -695,6 +696,8 @@ class Text(CharacterData):
else: else:
self.parentNode.insertBefore(newText, next) self.parentNode.insertBefore(newText, next)
self.data = self.data[:offset] self.data = self.data[:offset]
self.nodeValue = self.data
self.length = len(self.data)
return newText return newText
def writexml(self, writer, indent="", addindent="", newl=""): def writexml(self, writer, indent="", addindent="", newl=""):
......
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