[XML-SIG] Better pyexpat backtraces

Ken MacLeod ken@bitsko.slc.ut.us
26 Dec 2000 17:10:38 -0600


"Martin v. Loewis" <martin@loewis.home.cs.tu-berlin.de> writes:

> Since a number of people have run into the trap of thinking that Parse
> is called with a bad argument number, I just checked-in a patch to
> pyexpat that adds an artificial frame object on the stack. With that,
> if you pass a DocumentHandler in place of a ContentHandler, you now
> get a back-trace that reads
> 
> Traceback (most recent call last):
>   File "a.py", line 48, in ?
>     parser.parse( comic_xml )
>   File "/usr/local/lib/python2.0/site-packages/_xmlplus/sax/expatreader.py", line 43, in parse
>     xmlreader.IncrementalParser.parse(self, source)
>   File "/usr/local/lib/python2.0/site-packages/_xmlplus/sax/xmlreader.py", line 120, in parse
>     self.feed(buffer)
>   File "/usr/local/lib/python2.0/site-packages/_xmlplus/sax/expatreader.py", line 87, in feed
>     self._parser.Parse(data, isFinal)
>   File "pyexpat.c", line 370, in CharacterData
> TypeError: not enough arguments to characters(); expected 4, got 2
> 
> Normally, you would not get a stack frame that points to pyexpat.c;
> please let me know what you think.
> 
> The "to characters()" part is not my doing; that is a Python 2.1
> feature.

But that is correct and the intended error message, right?  Passing a
DocumentHandler to a SAX2 parser will result in characters() being
called with "only" two arguments when a SAX1 handler expects four.

Just checking what you meant there.

  -- Ken