]> granicus.if.org Git - python/commitdiff
Re-arrange things and remove some unused variables/imports to keep pychecker
authorFred Drake <fdrake@acm.org>
Fri, 26 Oct 2001 18:02:28 +0000 (18:02 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 26 Oct 2001 18:02:28 +0000 (18:02 +0000)
happy.  (This does not cover everything it complained about, though.)

Lib/markupbase.py
Lib/sgmllib.py

index 32237af9dd3c7749c3211a639a6253bb5de1285d..57d3ae4b3ce110276a8bd2153f7be04be3a34f84 100644 (file)
@@ -13,6 +13,15 @@ class ParserBase:
     """Parser base class which provides some common support methods used
     by the SGML/HTML and XHTML parsers."""
 
+    def __init__(self):
+        if self.__class__ is ParserBase:
+            raise RuntimeError(
+                "markupbase.ParserBase must be subclassed")
+
+    def error(self, message):
+        raise NotImplementedError(
+            "subclasses of ParserBase must override error()")
+
     def reset(self):
         self.lineno = 1
         self.offset = 0
@@ -46,7 +55,6 @@ class ParserBase:
         # deployed," this should only be the document type
         # declaration ("<!DOCTYPE html...>").
         rawdata = self.rawdata
-        import sys
         j = i + 2
         assert rawdata[i:j] == "<!", "unexpected call to parse_declaration"
         if rawdata[j:j+1] in ("-", ""):
@@ -162,12 +170,11 @@ class ParserBase:
 
     # Internal -- scan past <!ELEMENT declarations
     def _parse_doctype_element(self, i, declstartpos):
-        rawdata = self.rawdata
-        n = len(rawdata)
         name, j = self._scan_name(i, declstartpos)
         if j == -1:
             return -1
         # style content model; just skip until '>'
+        rawdata = self.rawdata
         if '>' in rawdata[j:]:
             return string.find(rawdata, ">", j) + 1
         return -1
@@ -304,3 +311,7 @@ class ParserBase:
         else:
             self.updatepos(declstartpos, i)
             self.error("expected name token")
+
+    # To be overridden -- handlers for unknown objects
+    def unknown_decl(self, data):
+        pass
index 2de7492c9a79adc7f265e1ce4d81a74635438e05..1db5423254c9a89674881babd9025f58660ac68a 100644 (file)
@@ -423,7 +423,6 @@ class SGMLParser(markupbase.ParserBase):
     def unknown_endtag(self, tag): pass
     def unknown_charref(self, ref): pass
     def unknown_entityref(self, ref): pass
-    def unknown_decl(self, data): pass
 
 
 class TestSGMLParser(SGMLParser):