CVS: Products/ParsedXML/DOM - Core.py:1.137

Martijn Faassen <[email protected]> Tue, 4 Jun 2002 10:52:43 -0400
Newsgroups gmane.comp.web.zope.parsed-xml
Message-ID <[email protected]>
Update of /cvs-repository/Products/ParsedXML/DOM
In directory cvs.zope.org:/tmp/cvs-serv29671/DOM

Modified Files:
	Core.py 
Log Message:
Fix bug in insertBefore (if a removeChild happened, the element would 
be inserted in the wrong place before). Also remove attempts to update
_v_sibling_map in removeChild and insertBefore, as this was buggy.


=== Products/ParsedXML/DOM/Core.py 1.136 => 1.137 ===
 
         # delete the sibling map, it will be recreated next use        
-        if sibmap:
+        if self.__dict__.has_key('_v_sibling_map'):
             del self.__dict__['_v_sibling_map']
 
         # Notify our containing database object that we have changed
@@ -585,13 +585,15 @@
             self.__dict__['_children'] = children = []
         if newChild.isSameNode(refChild):
             return newChild
+        if newChild.parentNode:
+            newChild.parentNode.removeChild(newChild)
+        
         ref = _aq_base(refChild)
         try:
             i = children.index(ref)
         except ValueError:
             raise xml.dom.NotFoundErr()
-        if newChild.parentNode:
-            newChild.parentNode.removeChild(newChild)
+
         _reparent(newChild, self)
         new = _aq_base(newChild)
         if new.__dict__.has_key('_in_tree'):
@@ -600,11 +602,12 @@
         self._changed()
         sibmap = self._v_sibling_map
         if sibmap:
-            prev, next = sibmap[ref]
-            if prev:
-                sibmap[prev][1] = new
-            sibmap[new] = [prev, ref]
-            sibmap[ref][0] = new
+            del self.__dict__['_v_sibling_map']
+            #prev, next = sibmap[ref]
+            #if prev:
+            #    sibmap[prev][1] = new
+            #sibmap[new] = [prev, ref]
+            #sibmap[ref][0] = new
         return newChild
 
     def removeChild(self, oldChild):
@@ -620,12 +623,13 @@
             del children[i]
             sibmap = self._v_sibling_map
             if sibmap:
-                prev, next = sibmap[child]
-                if prev:
-                    sibmap[prev][1] = next
-                if next:
-                    sibmap[next][0] = prev
-                del sibmap[child]
+                del self.__dict__['_v_sibling_map']
+                #prev, next = sibmap[child]
+                #if prev:
+                #    sibmap[prev][1] = next
+                #if next:
+                #    sibmap[next][0] = prev
+                #del sibmap[child]
             self._changed()
         else:
             raise xml.dom.NotFoundErr()
@@ -1864,9 +1868,10 @@
             newText = newText.__of__(parent)
             sibmap = parent._v_sibling_map
             if sibmap:
-                prev, next = sibmap[_aq_base(self)]
-                if next is not None:
-                    next = next.__of__(parent)
+                del self.__dict__['_v_sibling_map']
+                #prev, next = sibmap[_aq_base(self)]
+                #if next is not None:
+                #    next = next.__of__(parent)
             else:
                 next = self.nextSibling
             if next is None: