[Python-bugs-list] [Bug #123695] xml.sax.handler.ContentHandler.characters() not SAX2

noreply@sourceforge.net noreply@sourceforge.net
Fri, 1 Dec 2000 11:35:00 -0800


Bug #123695, was updated on 2000-Nov-28 06:26
Here is a current snapshot of the bug.

Project: Python
Category: None
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Submitted by: Nobody
Assigned to : fdrake
Summary: xml.sax.handler.ContentHandler.characters() not SAX2

Details: It takes the wrong arguments and differs from the SAX specification.
I also submitted the following bug to the pyxml-sig bugtracker:

http://sourceforge.net/bugs/?func=detailbug&bug_id=123693&group_id=6473

	SAX2 API documentation says: 	http://www.megginson.com/SAX/Java/javadoc/org/xml/sax/ContentHandler.html#characters(char[], 

                     public void characters(char[] ch,int start, int length) 

                     PyXML-0.6.2/doc/xml-howto.txt says: 
                     def characters(self, ch) 
                     in line 770 

                     This corresponds to how the pyexpat implementation distributed with python 2.0 works, but is not following the SAX API as pyexpat in pyXML 0.6.2 does. 

                     It looks like a bug in python 2.0 and at least a documentation bug for pyxml 0.6.2. 


See the following example program, which should work.

import xml.sax
import xml.sax.handler


class processTask(xml.sax.handler.ContentHandler):
    def startElement(self, name, attrs):
        print "startElement: %s=" % (name),
        print repr(attrs)

# SAX compliant
    def characters(self, ch, start, length):
        print "characters=%s" %(ch[start:start+length])

# works with python 2.0, but is not SAX compliant
#    def characters(self, ch):
#        print "characters=%s" %(ch)
#
    def endElement(self, name): 
        print "endElement: %s=" % (name)


dh = processTask()
string="""<?xml version="1.0"?>
     <parent id="top"><child1 name="paul">Text goes here</child1>
     <child2 name="fred">More text</child2>
     </parent>"""
xml.sax.parseString(string,dh)

but instead is bombs:
startElement: parent= <xml.sax.xmlreader.AttributesImpl instance at 0x813b0e4>
startElement: child1= <xml.sax.xmlreader.AttributesImpl instance at 0x813b0e4>
Traceback (most recent call last):
  File "xmltest2.py", line 27, in ?
    xml.sax.parseString(string,dh)
  File "/usr/src/packages/python/install//lib/python2.0/xml/sax/__init__.py", line 49, in parseString
    parser.parse(inpsrc)
  File "/usr/src/packages/python/install//lib/python2.0/xml/sax/expatreader.py", line 42, in parse
    xmlreader.IncrementalParser.parse(self, source)            
  File "/usr/src/packages/python/install//lib/python2.0/xml/sax/xmlreader.py", line 120, in parse
    self.feed(buffer)
  File "/usr/src/packages/python/install//lib/python2.0/xml/sax/expatreader.py", line 81, in feed
    self._parser.Parse(data, isFinal)
TypeError: not enough arguments; expected 4, got 2


Regards,
	Bernhard Reiter <bernhard@intevation.de>

Follow-Ups:

Date: 2000-Dec-01 11:35
By: loewis

Comment:
There is no error in either the documentation or the implementation; see the discussion of the PyXML report for details.

The deviation from the Java SAX ContentHandler interface is intentional, see

http://www.python.org/pipermail/xml-sig/2000-November/005510.html

for details.

Regards,
Martin

-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=123695&group_id=5470