[Zpt] CVS: Packages/TAL - HTMLTALParser.py:1.7

fred@digiciool.com fred@digiciool.com
Thu, 15 Mar 2001 12:38:17 -0500 (EST)


Update of /cvs-repository/Packages/TAL
In directory korak:/tmp/cvs-serv19701

Modified Files:
	HTMLTALParser.py 
Log Message:

Define a NestingError exception that gives a reasonable error message when
the open element stack does not contain the tag passed to finish_endtag().
The new message gives us the tag that was seen and the contents of the
tag stack at the time.



--- Updated File HTMLTALParser.py in package Packages/TAL --
--- HTMLTALParser.py	2001/03/15 17:14:26	1.6
+++ HTMLTALParser.py	2001/03/15 17:38:16	1.7
@@ -45,6 +45,18 @@
                                + CLOSING_BLOCK_LEVEL_HTML_TAGS)
 
 
+class NestingError(Exception):
+    """Exception raised when elements aren't properly nested."""
+
+    def __init__(self, tag, tagstack):
+        self.tag = tag
+        self.tagstack = tagstack[:]
+
+    def __str__(self):
+        return ("could not locate <%s> in tag stack:\n\t%s"
+                % (self.tag, self.tagstack))
+
+
 class HTMLTALParser(SGMLParser):
 
     # External API
@@ -153,7 +165,8 @@
     def finish_endtag(self, tag, implied=0):
         if tag in EMPTY_HTML_TAGS:
             return
-        assert tag in self.tagstack
+        if tag not in self.tagstack:
+            raise NestingError(tag, self.tagstack)
         while self.tagstack[-1] != tag:
             self.finish_endtag(self.tagstack[-1], implied=1)
         self.tagstack.pop()