Issue #2175: SAX parsers now support a character stream of InputSource object.

This commit is contained in:
Serhiy Storchaka 2015-04-02 21:00:13 +03:00
parent 278ba2690c
commit 61de087f0f
7 changed files with 64 additions and 12 deletions

View file

@ -345,11 +345,14 @@ def prepare_input_source(source, base=""):
elif hasattr(source, "read"):
f = source
source = xmlreader.InputSource()
source.setByteStream(f)
if isinstance(f.read(0), str):
source.setCharacterStream(f)
else:
source.setByteStream(f)
if hasattr(f, "name") and isinstance(f.name, str):
source.setSystemId(f.name)
if source.getByteStream() is None:
if source.getCharacterStream() is None and source.getByteStream() is None:
sysid = source.getSystemId()
basehead = os.path.dirname(os.path.normpath(base))
sysidfilename = os.path.join(basehead, sysid)