mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #18997: fix ElementTree crash with using pickle and __getstate__.
Based on report and initial patch from Germán M. Bravo
This commit is contained in:
parent
aa04f9ae7d
commit
dd3661e782
2 changed files with 37 additions and 26 deletions
|
@ -1462,6 +1462,7 @@ class BugsTest(unittest.TestCase):
|
|||
ET.register_namespace('test10777', 'http://myuri/')
|
||||
ET.register_namespace('test10777', 'http://myuri/')
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -1542,6 +1543,18 @@ class BasicElementTest(ElementTestCase, unittest.TestCase):
|
|||
self.assertEqual(len(e2), 2)
|
||||
self.assertEqualElements(e, e2)
|
||||
|
||||
def test_pickle_issue18997(self):
|
||||
for dumper, loader in product(self.modules, repeat=2):
|
||||
XMLTEXT = """<?xml version="1.0"?>
|
||||
<group><dogs>4</dogs>
|
||||
</group>"""
|
||||
e1 = dumper.fromstring(XMLTEXT)
|
||||
if hasattr(e1, '__getstate__'):
|
||||
self.assertEqual(e1.__getstate__()['tag'], 'group')
|
||||
e2 = self.pickleRoundTrip(e1, 'xml.etree.ElementTree', dumper, loader)
|
||||
self.assertEqual(e2.tag, 'group')
|
||||
self.assertEqual(e2[0].tag, 'dogs')
|
||||
|
||||
|
||||
class ElementTreeTypeTest(unittest.TestCase):
|
||||
def test_istype(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue