[ python-Bugs-923697 ] SAX2 'property_encoding' feature not supported

SourceForge.net noreply at sourceforge.net
Fri Mar 26 01:42:10 EST 2004


Bugs item #923697, was opened at 2004-03-26 06:39
Message generated for change (Settings changed) made by josephw
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=923697&group_id=5470

Category: XML
Group: None
Status: Open
Resolution: None
>Priority: 4
Submitted By: Joseph Walton (josephw)
Assigned to: Nobody/Anonymous (nobody)
Summary: SAX2 'property_encoding' feature not supported

Initial Comment:
I need to parse a byte stream as an XML document and,
afterwards, access the same document as a Unicode
string. I would prefer to rely on the parser's
charset-determining logic, and the 'property_encoding'
feature
("http://www.python.org/sax/properties/encoding") seems
to offer exactly this information.

However, the default Expat parser doesn't support this
feature.

---
from xml.sax import make_parser, handler
from xml.sax.xmlreader import InputSource
from sys import stdin

p = make_parser()

# Should not fail. Should it return None, or UTF-8?
assert(p.getProperty(handler.property_encoding) == None)

source = InputSource()
source.setByteStream(stdin)

p.parse(source)

# Should now be the name of the actual encoding used
assert(p.getProperty(handler.property_encoding) != None)
---

This raises SAXNotRecognizedException.

Is there another SAX parser I could use instead?

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=923697&group_id=5470



More information about the Python-bugs-list mailing list