This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aroberge
Recipients aroberge
Date 2009-07-24.19:46:50
SpamBayes Score 7.675467e-08
Marked as misclassified No
Message-id <1248464813.63.0.470228683416.issue6565@psf.upfronthosting.co.za>
In-reply-to
Content
I have a function to replace the content of an ElementTree Element by
that of another one which works using Python 2 but not with Python 3.
I get an assertion error.  

It was suggested on the Python list that the problem is that in Python 3
slice assignments are done with __setitem__ rather than __setslice__ but
ElementTree has not been adapted to that -- hence the title given to
this bug.

The function that I use to demonstrate this (with a workaround solution)
is as follows:

def replace_element(elem, replacement):
    '''replace the content of an ElementTree Element by that of
another
       one.
    '''
    elem.clear()
    elem.text = replacement.text
    elem.tail = replacement.tail
    elem.tag = replacement.tag
    elem.attrib = replacement.attrib
    try:
        elem[:] = replacement[:]  # works with Python 2.5 but not 3.1
    except AssertionError:
        del elem[:]
        for child in replacement:
            elem.append(child)

I have included a small test file which demonstrate the behaviour.
History
Date User Action Args
2009-07-24 19:46:53arobergesetrecipients: + aroberge
2009-07-24 19:46:53arobergesetmessageid: <1248464813.63.0.470228683416.issue6565@psf.upfronthosting.co.za>
2009-07-24 19:46:51arobergelinkissue6565 messages
2009-07-24 19:46:51arobergecreate