Modernization: Use string methods, use str instead of

types.StringType, inherit from list instead of
                UserList.
This commit is contained in:
Fred Drake 2002-10-16 16:00:42 +00:00
parent 071972e426
commit df85f0b09f

View file

@ -19,14 +19,10 @@ import errno
import getopt import getopt
import os import os
import re import re
import string
import sys import sys
import UserList
import xml.sax import xml.sax
import xml.sax.saxutils import xml.sax.saxutils
from types import ListType, StringType, TupleType
from esistools import encode from esistools import encode
@ -74,29 +70,30 @@ def popping(name, point, depth):
dbgmsg("popping </%s> at %s" % (name, point)) dbgmsg("popping </%s> at %s" % (name, point))
class _Stack(UserList.UserList): class _Stack(list):
def append(self, entry): def append(self, entry):
if type(entry) is not StringType: if not isinstance(entry, str):
raise LaTeXFormatError("cannot push non-string on stack: " raise LaTeXFormatError("cannot push non-string on stack: "
+ `entry`) + `entry`)
#dbgmsg("%s<%s>" % (" "*len(self.data), entry)) #dbgmsg("%s<%s>" % (" "*len(self.data), entry))
self.data.append(entry) list.append(self, entry)
def pop(self, index=-1): def pop(self, index=-1):
entry = self.data[index] entry = self[index]
del self.data[index] del self[index]
#dbgmsg("%s</%s>" % (" "*len(self.data), entry)) #dbgmsg("%s</%s>" % (" " * len(self), entry))
def __delitem__(self, index): def __delitem__(self, index):
entry = self.data[index] entry = self[index]
del self.data[index] list.__delitem__(self, index)
#dbgmsg("%s</%s>" % (" "*len(self.data), entry)) #dbgmsg("%s</%s>" % (" " * len(self), entry))
def new_stack(): def new_stack():
if DEBUG: if DEBUG:
return _Stack() return _Stack()
return [] else:
return []
class Conversion: class Conversion:
@ -106,7 +103,7 @@ class Conversion:
self.table = table self.table = table
L = [s.rstrip() for s in ifp.readlines()] L = [s.rstrip() for s in ifp.readlines()]
L.append("") L.append("")
self.line = string.join(L, "\n") self.line = "\n".join(L)
self.preamble = 1 self.preamble = 1
def convert(self): def convert(self):
@ -340,7 +337,7 @@ class Conversion:
break break
if stack: if stack:
raise LaTeXFormatError("elements remain on stack: " raise LaTeXFormatError("elements remain on stack: "
+ string.join(stack, ", ")) + ", ".join(stack))
# otherwise we just ran out of input here... # otherwise we just ran out of input here...
# This is a really limited table of combinations, but it will have # This is a really limited table of combinations, but it will have
@ -546,7 +543,7 @@ def main():
opts, args = getopt.getopt(sys.argv[1:], "D", ["debug"]) opts, args = getopt.getopt(sys.argv[1:], "D", ["debug"])
for opt, arg in opts: for opt, arg in opts:
if opt in ("-D", "--debug"): if opt in ("-D", "--debug"):
DEBUG = DEBUG + 1 DEBUG += 1
if len(args) == 0: if len(args) == 0:
ifp = sys.stdin ifp = sys.stdin
ofp = sys.stdout ofp = sys.stdout