diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 07:12:26 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 07:12:26 (GMT) |
commit | 778db289b5a1968c67db195572f2384489cca20c (patch) | |
tree | bfff3b855d5beeda067bfe7e19d499158c4593d2 /Lib/xml | |
parent | f8aa133cce70472ec7baa21c8b073891101dce15 (diff) | |
download | cpython-778db289b5a1968c67db195572f2384489cca20c.zip cpython-778db289b5a1968c67db195572f2384489cca20c.tar.gz cpython-778db289b5a1968c67db195572f2384489cca20c.tar.bz2 |
Issue #10590: xml.sax.parseString() now supports string argument.
Diffstat (limited to 'Lib/xml')
-rw-r--r-- | Lib/xml/sax/__init__.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py index b161b1f..ef67ae6 100644 --- a/Lib/xml/sax/__init__.py +++ b/Lib/xml/sax/__init__.py @@ -33,8 +33,7 @@ def parse(source, handler, errorHandler=ErrorHandler()): parser.parse(source) def parseString(string, handler, errorHandler=ErrorHandler()): - from io import BytesIO - + import io if errorHandler is None: errorHandler = ErrorHandler() parser = make_parser() @@ -42,7 +41,10 @@ def parseString(string, handler, errorHandler=ErrorHandler()): parser.setErrorHandler(errorHandler) inpsrc = InputSource() - inpsrc.setByteStream(BytesIO(string)) + if isinstance(string, str): + inpsrc.setCharacterStream(io.StringIO(string)) + else: + inpsrc.setByteStream(io.BytesIO(string)) parser.parse(inpsrc) # this is the parser list used by the make_parser function if no |