mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Added back the InputSource class (patch 101630).
This commit is contained in:
parent
b7536d5860
commit
523b0a6ec8
4 changed files with 138 additions and 31 deletions
|
|
@ -21,16 +21,17 @@ expatreader -- Driver that allows use of the Expat parser with the
|
|||
|
||||
"""
|
||||
|
||||
from xmlreader import InputSource
|
||||
from handler import ContentHandler, ErrorHandler
|
||||
from _exceptions import SAXException, SAXNotRecognizedException, \
|
||||
SAXParseException, SAXNotSupportedException
|
||||
|
||||
|
||||
def parse(filename_or_stream, handler, errorHandler=ErrorHandler()):
|
||||
def parse(source, handler, errorHandler=ErrorHandler()):
|
||||
parser = ExpatParser()
|
||||
parser.setContentHandler(handler)
|
||||
parser.setErrorHandler(errorHandler)
|
||||
parser.parse(filename_or_stream)
|
||||
parser.parse(source)
|
||||
|
||||
def parseString(string, handler, errorHandler=ErrorHandler()):
|
||||
try:
|
||||
|
|
@ -43,7 +44,10 @@ def parseString(string, handler, errorHandler=ErrorHandler()):
|
|||
parser = ExpatParser()
|
||||
parser.setContentHandler(handler)
|
||||
parser.setErrorHandler(errorHandler)
|
||||
parser.parse(StringIO(string))
|
||||
|
||||
inpsrc = InputSource()
|
||||
inpsrc.setByteStream(StringIO(string))
|
||||
parser.parse(inpsrc)
|
||||
|
||||
# this is the parser list used by the make_parser function if no
|
||||
# alternatives are given as parameters to the function
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue