Pick up the "encode" function from esistools instead of defining our own

(broken) version.

Remove Conversion.err_write() -- use dbgmsg() consistently.
This commit is contained in:
Fred Drake 2001-03-23 16:53:34 +00:00
parent a9d0450f72
commit 2262a80fb3
1 changed files with 9 additions and 15 deletions

View File

@ -32,6 +32,9 @@ except ImportError:
from xmllib import XMLParser from xmllib import XMLParser
from esistools import encode
DEBUG = 0 DEBUG = 0
@ -47,10 +50,6 @@ class LaTeXStackError(LaTeXFormatError):
self.stack = stack[:] self.stack = stack[:]
LaTeXFormatError.__init__(self, msg) LaTeXFormatError.__init__(self, msg)
def encode(s):
s = xml.sax.saxutils.escape(s)
return s.replace("\n", "\\n\n-")
_begin_env_rx = re.compile(r"[\\]begin{([^}]*)}") _begin_env_rx = re.compile(r"[\\]begin{([^}]*)}")
_end_env_rx = re.compile(r"[\\]end{([^}]*)}") _end_env_rx = re.compile(r"[\\]end{([^}]*)}")
@ -85,18 +84,18 @@ class _Stack(UserList.UserList):
if type(entry) is not StringType: if type(entry) is not StringType:
raise LaTeXFormatError("cannot push non-string on stack: " raise LaTeXFormatError("cannot push non-string on stack: "
+ `entry`) + `entry`)
sys.stderr.write("%s<%s>\n" % (" "*len(self.data), entry)) #dbgmsg("%s<%s>" % (" "*len(self.data), entry))
self.data.append(entry) self.data.append(entry)
def pop(self, index=-1): def pop(self, index=-1):
entry = self.data[index] entry = self.data[index]
del self.data[index] del self.data[index]
sys.stderr.write("%s</%s>\n" % (" "*len(self.data), entry)) #dbgmsg("%s</%s>" % (" "*len(self.data), entry))
def __delitem__(self, index): def __delitem__(self, index):
entry = self.data[index] entry = self.data[index]
del self.data[index] del self.data[index]
sys.stderr.write("%s</%s>\n" % (" "*len(self.data), entry)) #dbgmsg("%s</%s>" % (" "*len(self.data), entry))
def new_stack(): def new_stack():
@ -113,10 +112,6 @@ class Conversion:
self.line = string.join(map(string.rstrip, ifp.readlines()), "\n") self.line = string.join(map(string.rstrip, ifp.readlines()), "\n")
self.preamble = 1 self.preamble = 1
def err_write(self, msg):
if DEBUG:
sys.stderr.write(str(msg) + "\n")
def convert(self): def convert(self):
self.subconvert() self.subconvert()
@ -271,7 +266,7 @@ class Conversion:
opened = 1 opened = 1
stack.append(entry.name) stack.append(entry.name)
self.write("(%s\n" % entry.outputname) self.write("(%s\n" % entry.outputname)
self.err_write("--- text: %s\n" % `pentry.text`) #dbgmsg("--- text: %s" % `pentry.text`)
self.write("-%s\n" % encode(pentry.text)) self.write("-%s\n" % encode(pentry.text))
elif pentry.type == "entityref": elif pentry.type == "entityref":
self.write("&%s\n" % pentry.name) self.write("&%s\n" % pentry.name)
@ -290,7 +285,7 @@ class Conversion:
# end of macro or group # end of macro or group
macroname = stack[-1] macroname = stack[-1]
if macroname: if macroname:
conversion = self.table.get(macroname) conversion = self.table[macroname]
if conversion.outputname: if conversion.outputname:
# otherwise, it was just a bare group # otherwise, it was just a bare group
self.write(")%s\n" % conversion.outputname) self.write(")%s\n" % conversion.outputname)
@ -373,8 +368,7 @@ class Conversion:
def get_entry(self, name): def get_entry(self, name):
entry = self.table.get(name) entry = self.table.get(name)
if entry is None: if entry is None:
self.err_write("get_entry(%s) failing; building default entry!" dbgmsg("get_entry(%s) failing; building default entry!" % `name`)
% `name`)
# not defined; build a default entry: # not defined; build a default entry:
entry = TableEntry(name) entry = TableEntry(name)
entry.has_content = 1 entry.has_content = 1