[XML-SIG] Error using xml.sax.{xmlreader,expatreader}

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Mon, 27 Nov 2000 10:44:16 +0100


> Attached is a small program which demonstrates this.  Am I doing something
> wrong or is there a bug in the library?

This is a bug in your code:

> 	def characters(self, ch, start, length):

In SAX2, the characters method only has a single argument (besides self),
so it should be

        def characters(self, chars):
 		if not self.in_field:
 			raise DataError("characters outside a field: %s" % `chars`)
 		self.chars.append(chars)

There is a problem with the traceback, though - since characters is
called from C code, and since that call happens to fail, the topmost
Python stack frame is the one where expatreader calls into the C code.

Any hints for improving the error reporting are
appreciated. Delegating the calls from pyexpat to a method in
expatreader first is not acceptable, though, due to the expected
overhead of an additional call in the normal case.

Regards,
Martin