mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Issue #10590: xml.sax.parseString() now supports string argument.
This commit is contained in:
parent
f8aa133cce
commit
778db289b5
4 changed files with 19 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue