diff -r f80d5faa60ee Doc/library/xml.sax.rst --- a/Doc/library/xml.sax.rst Fri Apr 03 11:09:08 2015 +0200 +++ b/Doc/library/xml.sax.rst Fri Apr 03 12:25:06 2015 +0300 @@ -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. + parameter. *string* must be a :class:`str` instance or a + :term:`bytes-like object`. + + .. versionchanged:: 3.5 + Added support of :class:`str` instances. 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 diff -r f80d5faa60ee Lib/test/test_nntplib.py --- a/Lib/test/test_nntplib.py Fri Apr 03 11:09:08 2015 +0200 +++ b/Lib/test/test_nntplib.py Fri Apr 03 12:25:06 2015 +0300 @@ -1509,15 +1509,15 @@ class MockSocketTests(unittest.TestCase) Handler, nntplib.NNTPPermanentError, authinfo_response, login, password) -if ssl is not None: - class MockSslTests(MockSocketTests): - class nntp_class(nntplib.NNTP_SSL): - def __init__(self, *pos, **kw): - class bypass_context: - """Bypass encryption and actual SSL module""" - def wrap_socket(sock, **args): - return sock - return super().__init__(*pos, ssl_context=bypass_context, **kw) +class bypass_context: + """Bypass encryption and actual SSL module""" + def wrap_socket(sock, **args): + return sock + +@unittest.skipUnless(ssl, 'requires SSL support') +class MockSslTests(MockSocketTests): + def nntp_class(self, *pos, **kw): + return nntplib.NNTP_SSL(*pos, ssl_context=bypass_context, **kw) if __name__ == "__main__": diff -r f80d5faa60ee Lib/test/test_sax.py --- a/Lib/test/test_sax.py Fri Apr 03 11:09:08 2015 +0200 +++ b/Lib/test/test_sax.py Fri Apr 03 12:25:06 2015 +0300 @@ -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', + 'utf-16', 'utf-16le', 'utf-16be') + for encoding in encodings: + self.check_parseString(xml_str(self.data, encoding)) + self.check_parseString(self.data) + def test_parseString_bytes(self): # UTF-8 is default encoding, US-ASCII is compatible with UTF-8, # UTF-16 is autodetected diff -r f80d5faa60ee Lib/xml/sax/__init__.py --- a/Lib/xml/sax/__init__.py Fri Apr 03 11:09:08 2015 +0200 +++ b/Lib/xml/sax/__init__.py Fri Apr 03 12:25:06 2015 +0300 @@ -33,8 +33,7 @@ def parse(source, handler, 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, errorHa 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 diff -r f80d5faa60ee Misc/NEWS --- a/Misc/NEWS Fri Apr 03 11:09:08 2015 +0200 +++ b/Misc/NEWS Fri Apr 03 12:25:06 2015 +0300 @@ -16,6 +16,8 @@ Core and Builtins Library ------- +- Issue #10590: xml.sax.parseString() now supports string argument. + - Issue #2175: SAX parsers now support a character stream of InputSource object. - Issue #16840: Tkinter now supports 64-bit integers added in Tcl 8.4 and