mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #22915: SAX parser now supports files opened with file descriptor or
bytes path.
This commit is contained in:
commit
5916d53032
3 changed files with 28 additions and 1 deletions
|
@ -648,6 +648,30 @@ class ExpatReaderTest(XmlTestBase):
|
|||
|
||||
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:
|
||||
|
|
|
@ -346,7 +346,7 @@ def prepare_input_source(source, base=""):
|
|||
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:
|
||||
|
|
|
@ -191,6 +191,9 @@ Core and Builtins
|
|||
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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue