[docs] Python 3.1.2 xml.sax doc error, or bug, or error by the operator...

Ryan, Thomas thomas.ryan at hp.com
Wed Nov 24 02:24:56 CET 2010


Thanks for your help.

http://docs.python.org/py3k/library/xml.sax.html

The description

	xml.sax.parse(filename_or_stream, handler, error_handler=handler.ErrorHandler())
	  Similar to parse, but parses from a buffer string received as a parameter.

seems incorrect, or misleading. Is the term "buffer"  significant? Only "string" is italicized.
I am not a Python expert, but here is my snippet that fails.
I did Google around but the examples I found were all python 2.x.


import xml.sax

class myHandler(xml.sax.ContentHandler) :
    pass

m = myHandler()

## both of the next two cals throw the same expression (consistency is not surprising, but was worth checking, I guess)
## I assume the handler parameter is OK

xml.sax.parseString("hello", m)
##xml.sax.parseString(b"<abc><\abc>".decode("utf8"),  m)

Traceback (most recent call last):
  File " xmlsad.py", line 10, in <module>
    xml.sax.parseString("hello", m)
  File "C:\Python31\lib\xml\sax\__init__.py", line 45, in parseString
    inpsrc.setByteStream(BytesIO(string))
TypeError: 'str' does not support the buffer interface


More information about the docs mailing list