mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue #14007: implement doctype() method calling in XMLParser of _elementtree.
Includes exposing a doctype handler from expat through pyexpat.
This commit is contained in:
parent
20d4174b3d
commit
2b6b73e7e1
4 changed files with 120 additions and 11 deletions
|
@ -2009,7 +2009,6 @@ class TreeBuilderTest(unittest.TestCase):
|
|||
|
||||
self.assertEqual(lst, ['toplevel'])
|
||||
|
||||
@unittest.expectedFailure # XXX issue 14007 with C ElementTree
|
||||
def test_doctype(self):
|
||||
class DoctypeParser:
|
||||
_doctype = None
|
||||
|
@ -2030,6 +2029,10 @@ class TreeBuilderTest(unittest.TestCase):
|
|||
|
||||
class XMLParserTest(unittest.TestCase):
|
||||
sample1 = '<file><line>22</line></file>'
|
||||
sample2 = ('<!DOCTYPE html PUBLIC'
|
||||
' "-//W3C//DTD XHTML 1.0 Transitional//EN"'
|
||||
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
|
||||
'<html>text</html>')
|
||||
|
||||
def _check_sample_element(self, e):
|
||||
self.assertEqual(e.tag, 'file')
|
||||
|
@ -2055,6 +2058,20 @@ class XMLParserTest(unittest.TestCase):
|
|||
parser.feed(self.sample1)
|
||||
self._check_sample_element(parser.close())
|
||||
|
||||
def test_subclass_doctype(self):
|
||||
_doctype = None
|
||||
class MyParserWithDoctype(ET.XMLParser):
|
||||
def doctype(self, name, pubid, system):
|
||||
nonlocal _doctype
|
||||
_doctype = (name, pubid, system)
|
||||
|
||||
parser = MyParserWithDoctype()
|
||||
parser.feed(self.sample2)
|
||||
parser.close()
|
||||
self.assertEqual(_doctype,
|
||||
('html', '-//W3C//DTD XHTML 1.0 Transitional//EN',
|
||||
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'))
|
||||
|
||||
|
||||
class NoAcceleratorTest(unittest.TestCase):
|
||||
# Test that the C accelerator was not imported for pyET
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue