Kaydet (Commit) 5445f078 authored tarafından Fred Drake's avatar Fred Drake

Re-arrange things and remove some unused variables/imports to keep pychecker

happy.  (This does not cover everything it complained about, though.)
üst c916f5a3
...@@ -13,6 +13,15 @@ class ParserBase: ...@@ -13,6 +13,15 @@ class ParserBase:
"""Parser base class which provides some common support methods used """Parser base class which provides some common support methods used
by the SGML/HTML and XHTML parsers.""" 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): def reset(self):
self.lineno = 1 self.lineno = 1
self.offset = 0 self.offset = 0
...@@ -46,7 +55,6 @@ class ParserBase: ...@@ -46,7 +55,6 @@ class ParserBase:
# deployed," this should only be the document type # deployed," this should only be the document type
# declaration ("<!DOCTYPE html...>"). # declaration ("<!DOCTYPE html...>").
rawdata = self.rawdata rawdata = self.rawdata
import sys
j = i + 2 j = i + 2
assert rawdata[i:j] == "<!", "unexpected call to parse_declaration" assert rawdata[i:j] == "<!", "unexpected call to parse_declaration"
if rawdata[j:j+1] in ("-", ""): if rawdata[j:j+1] in ("-", ""):
...@@ -162,12 +170,11 @@ class ParserBase: ...@@ -162,12 +170,11 @@ class ParserBase:
# Internal -- scan past <!ELEMENT declarations # Internal -- scan past <!ELEMENT declarations
def _parse_doctype_element(self, i, declstartpos): def _parse_doctype_element(self, i, declstartpos):
rawdata = self.rawdata
n = len(rawdata)
name, j = self._scan_name(i, declstartpos) name, j = self._scan_name(i, declstartpos)
if j == -1: if j == -1:
return -1 return -1
# style content model; just skip until '>' # style content model; just skip until '>'
rawdata = self.rawdata
if '>' in rawdata[j:]: if '>' in rawdata[j:]:
return string.find(rawdata, ">", j) + 1 return string.find(rawdata, ">", j) + 1
return -1 return -1
...@@ -304,3 +311,7 @@ class ParserBase: ...@@ -304,3 +311,7 @@ class ParserBase:
else: else:
self.updatepos(declstartpos, i) self.updatepos(declstartpos, i)
self.error("expected name token") self.error("expected name token")
# To be overridden -- handlers for unknown objects
def unknown_decl(self, data):
pass
...@@ -423,7 +423,6 @@ class SGMLParser(markupbase.ParserBase): ...@@ -423,7 +423,6 @@ class SGMLParser(markupbase.ParserBase):
def unknown_endtag(self, tag): pass def unknown_endtag(self, tag): pass
def unknown_charref(self, ref): pass def unknown_charref(self, ref): pass
def unknown_entityref(self, ref): pass def unknown_entityref(self, ref): pass
def unknown_decl(self, data): pass
class TestSGMLParser(SGMLParser): class TestSGMLParser(SGMLParser):
......
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