changeset: 93628:ce9881eecfb4 parent: 93626:aced2548345a parent: 93627:27ae1a476ef7 user: Serhiy Storchaka date: Thu Nov 27 22:14:30 2014 +0200 files: Misc/NEWS description: Issue #22915: SAX parser now supports files opened with file descriptor or bytes path. diff -r aced2548345a -r ce9881eecfb4 Lib/test/test_sax.py --- a/Lib/test/test_sax.py Thu Nov 27 19:45:31 2014 +0200 +++ b/Lib/test/test_sax.py Thu Nov 27 22:14:30 2014 +0200 @@ -648,6 +648,30 @@ self.assertEqual(result.getvalue(), xml_test_out) + def test_expat_binary_file_bytes_name(self): + fname = os.fsencode(TEST_XMLFILE) + parser = create_parser() + result = BytesIO() + xmlgen = XMLGenerator(result) + + parser.setContentHandler(xmlgen) + with open(fname, 'rb') as f: + parser.parse(f) + + self.assertEqual(result.getvalue(), xml_test_out) + + def test_expat_binary_file_int_name(self): + parser = create_parser() + result = BytesIO() + xmlgen = XMLGenerator(result) + + parser.setContentHandler(xmlgen) + with open(TEST_XMLFILE, 'rb') as f: + with open(f.fileno(), 'rb', closefd=False) as f2: + parser.parse(f2) + + self.assertEqual(result.getvalue(), xml_test_out) + # ===== DTDHandler support class TestDTDHandler: diff -r aced2548345a -r ce9881eecfb4 Lib/xml/sax/saxutils.py --- a/Lib/xml/sax/saxutils.py Thu Nov 27 19:45:31 2014 +0200 +++ b/Lib/xml/sax/saxutils.py Thu Nov 27 22:14:30 2014 +0200 @@ -346,7 +346,7 @@ f = source source = xmlreader.InputSource() source.setByteStream(f) - if hasattr(f, "name"): + if hasattr(f, "name") and isinstance(f.name, str): source.setSystemId(f.name) if source.getByteStream() is None: diff -r aced2548345a -r ce9881eecfb4 Misc/NEWS --- a/Misc/NEWS Thu Nov 27 19:45:31 2014 +0200 +++ b/Misc/NEWS Thu Nov 27 22:14:30 2014 +0200 @@ -191,6 +191,9 @@ Library ------- +- Issue #22915: SAX parser now supports files opened with file descriptor or + bytes path. + - Issue #22609: Constructors and update methods of mapping classes in the collections module now accept the self keyword argument.