Issue #10590: xml.sax.parseString() now supports string argument.

This commit is contained in:
Serhiy Storchaka 2015-04-04 10:12:26 +03:00
parent f8aa133cce
commit 778db289b5
4 changed files with 19 additions and 4 deletions

View file

@ -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