Re: cElementTree compatibility issue
Martijn Faassen <faassen <at> infrae.com>
2005-06-13 10:47:57 GMT
Olivier Grisel wrote:
> I wanted to try to replace cElementTree by lxml.etree in the promising
> bazaar-ng SCM tool [1],
Cool! I didn't know it was using ElementTree. Thanks for trying this!
What motivated you to try this?
> but it seems to me there is a API compatibility issue.
This is quite possible.
> I read the compatbility doc [2] to as to replace import lines in
> the BZR source code, but then whene I run the tests, I get::
>
> AttributeError: 'etree._ElementTree' object has no attribute 'parse'
Yup, this is a known (by me :) weakness in the lxml implementation --
not all of the API of ElementTree is supported (yet). What 'parse' on
the ElementTree class is *replace* the contents of an XML document with
a newly parsed tree. There's in fact a commented out completely bogus
code for it in etree.pyx:
## def parse(self, source, parser=None):
## # XXX ignore parser for now
## cdef xmlDoc* c_doc
## c_doc = theParser.parseDoc(source)
## result._c_doc = c_doc
## return self.getroot()
(Continue reading)