cpython: fca669149d8a (original) (raw)
Mercurial > cpython
changeset 95432:fca669149d8a
Issue #10590: xml.sax.parseString() now supports string argument. [#10590]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Sat, 04 Apr 2015 10:12:26 +0300 |
parents | 3eb3a6d45251 |
children | 9db237815042 |
files | Doc/library/xml.sax.rst Lib/test/test_sax.py Lib/xml/sax/__init__.py Misc/NEWS |
diffstat | 4 files changed, 19 insertions(+), 4 deletions(-)[+] [-] Doc/library/xml.sax.rst 6 Lib/test/test_sax.py 7 Lib/xml/sax/__init__.py 8 Misc/NEWS 2 |
line wrap: on
line diff
--- a/Doc/library/xml.sax.rst
+++ b/Doc/library/xml.sax.rst
@@ -47,7 +47,11 @@ The convenience functions are:
.. function:: parseString(string, handler, error_handler=handler.ErrorHandler())
Similar to :func:parse
, but parses from a buffer string received as a
- parameter. string must be a :class:
str
instance or a - :term:
bytes-like object
. + - .. versionchanged:: 3.5
Added support of :class:`str` instances.[](#l1.12)
A typical SAX application uses three kinds of objects: readers, handlers and input sources. "Reader" in this context is another term for parser, i.e. some
--- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -200,6 +200,13 @@ class ParseTest(unittest.TestCase): parseString(s, XMLGenerator(result, 'utf-8')) self.assertEqual(result.getvalue(), xml_str(self.data, 'utf-8'))
- def test_parseString_text(self):
encodings = ('us-ascii', 'iso-8859-1', 'utf-8',[](#l2.8)
'utf-16', 'utf-16le', 'utf-16be')[](#l2.9)
for encoding in encodings:[](#l2.10)
self.check_parseString(xml_str(self.data, encoding))[](#l2.11)
self.check_parseString(self.data)[](#l2.12)
+ def test_parseString_bytes(self): # UTF-8 is default encoding, US-ASCII is compatible with UTF-8, # UTF-16 is autodetected
--- a/Lib/xml/sax/init.py +++ b/Lib/xml/sax/init.py @@ -33,8 +33,7 @@ def parse(source, handler, errorHandler= parser.parse(source) def parseString(string, handler, errorHandler=ErrorHandler()):
- import io if errorHandler is None: errorHandler = ErrorHandler() parser = make_parser() @@ -42,7 +41,10 @@ def parseString(string, handler, errorHa parser.setErrorHandler(errorHandler) inpsrc = InputSource()
- if isinstance(string, str):
inpsrc.setCharacterStream(io.StringIO(string))[](#l3.19)
- else:
parser.parse(inpsrc)inpsrc.setByteStream(io.BytesIO(string))[](#l3.21)
this is the parser list used by the make_parser function if no
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -19,6 +19,8 @@ Core and Builtins Library ------- +- Issue #10590: xml.sax.parseString() now supports string argument. +