From 61de087f0f838f5b69592827d3d592c06aa9b655 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 2 Apr 2015 21:00:13 +0300 Subject: Issue #2175: SAX parsers now support a character stream of InputSource object. --- Lib/xml/sax/saxutils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Lib/xml/sax/saxutils.py') diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py index 1d3d0ecc5f..a69c7f7621 100644 --- a/Lib/xml/sax/saxutils.py +++ b/Lib/xml/sax/saxutils.py @@ -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) -- cgit v1.2.1