diff options
author | Fred Drake <fdrake@acm.org> | 2001-11-30 19:30:03 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-11-30 19:30:03 (GMT) |
commit | 381832ead56dba0499d8e795a46e87bf375c43a3 (patch) | |
tree | 77dcdb98982aeaed746e38ae82f22c954715e8a4 /Doc/tools/sgmlconv | |
parent | 1e53fa7907ff162b0b0af54f711044a1c35c6d61 (diff) | |
download | cpython-381832ead56dba0499d8e795a46e87bf375c43a3.zip cpython-381832ead56dba0499d8e795a46e87bf375c43a3.tar.gz cpython-381832ead56dba0499d8e795a46e87bf375c43a3.tar.bz2 |
Drop xmllib in favor of SAX.
Diffstat (limited to 'Doc/tools/sgmlconv')
-rwxr-xr-x | Doc/tools/sgmlconv/latex2esis.py | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/Doc/tools/sgmlconv/latex2esis.py b/Doc/tools/sgmlconv/latex2esis.py index 28433c7..5bfc748 100755 --- a/Doc/tools/sgmlconv/latex2esis.py +++ b/Doc/tools/sgmlconv/latex2esis.py @@ -22,16 +22,11 @@ import re import string import sys import UserList +import xml.sax import xml.sax.saxutils from types import ListType, StringType, TupleType -try: - from xml.parsers.xmllib import XMLParser -except ImportError: - from xmllib import XMLParser - - from esistools import encode @@ -439,14 +434,11 @@ class Parameter: self.implied = 0 -class TableParser(XMLParser): - def __init__(self, table=None): - if table is None: - table = {} - self.__table = table - self.__current = None +class TableHandler(xml.sax.handler.ContentHandler): + def __init__(self): + self.__table = {} self.__buffer = '' - XMLParser.__init__(self) + self.__methods = {} def get_table(self): for entry in self.__table.values(): @@ -457,6 +449,27 @@ class TableParser(XMLParser): entry.has_content = 1 return self.__table + def startElement(self, tag, attrs): + try: + start, end = self.__methods[tag] + except KeyError: + start = getattr(self, "start_" + tag, None) + end = getattr(self, "end_" + tag, None) + self.__methods[tag] = (start, end) + if start: + start(attrs) + + def endElement(self, tag): + start, end = self.__methods[tag] + if end: + end() + + def endDocument(self): + self.__methods.clear() + + def characters(self, data): + self.__buffer += data + def start_environment(self, attrs): name = attrs["name"] self.__current = TableEntry(name, environment=1) @@ -517,15 +530,11 @@ class TableParser(XMLParser): p.text = self.__buffer self.__current.parameters.append(p) - def handle_data(self, data): - self.__buffer = self.__buffer + data - -def load_table(fp, table=None): - parser = TableParser(table=table) - parser.feed(fp.read()) - parser.close() - return parser.get_table() +def load_table(fp): + ch = TableHandler() + xml.sax.parse(fp, ch) + return ch.get_table() def main(): |