[z3-checkins] r44548 - z3/deliverance/trunk/deliverance

ianb at codespeak.net ianb at codespeak.net
Tue Jun 26 18:59:30 CEST 2007


Author: ianb
Date: Tue Jun 26 18:59:28 2007
New Revision: 44548

Modified:
   z3/deliverance/trunk/deliverance/interpreter.py
   z3/deliverance/trunk/deliverance/utils.py
Log:
Improve the error message when you try to use attach_text_to_previous and there is no parent.  Also avoid calling that function when there is no text to attach (which hopefully will keep this case from happening)

Modified: z3/deliverance/trunk/deliverance/interpreter.py
==============================================================================
--- z3/deliverance/trunk/deliverance/interpreter.py	(original)
+++ z3/deliverance/trunk/deliverance/interpreter.py	Tue Jun 26 18:59:28 2007
@@ -445,7 +445,8 @@
         for el in els:
             if isinstance(el, basestring):
                 continue
-            self.attach_text_to_previous(el, el.tail)
+            if el.tail:
+                self.attach_text_to_previous(el, el.tail)
             el.getparent().remove(el)
             removed += 1
         return removed

Modified: z3/deliverance/trunk/deliverance/utils.py
==============================================================================
--- z3/deliverance/trunk/deliverance/utils.py	(original)
+++ z3/deliverance/trunk/deliverance/utils.py	Tue Jun 26 18:59:28 2007
@@ -284,12 +284,15 @@
     def attach_text_to_previous(self,el,text):
         """
         attaches the text given to the nearest previous node to el, 
-        ie its preceding sibling or parent         
+        ie its preceding sibling or parent
         """
         if text is None:
             return 
 
-        el_i = el.getparent().index(el)
+        parent = el.getparent()
+        assert parent is not None, (
+            "Element %r has no parent" % el)
+        el_i = parent.index(el)
         if el_i > 0:
             sib_el = el.getparent()[el_i - 1]
             if sib_el.tail:


More information about the z3-checkins mailing list