bzr-0.7 and cElementTree
John Arbash Meinel
john at arbash-meinel.com
Wed Jan 25 16:34:16 GMT 2006
Adis Nezirovic wrote:
> bzr 0.7
> cElementTree c1.0.5-20051216
>
This is because of a newer version of cElementTree. On my machine:
python
>>> import cElementTree
>>> cElementTree.__version__
'1.0.3'
>>> cElementTree.fromstring
<function XML at 0xb7a1df7c>
>
> I noticed this log message in my ~/.bzr.log:
> ---8<---
> WARNING: using slower ElementTree; consider installing cElementTree and
> make sure it's on your PYTHONPATH
> --->8---
>
> I think that cElementTree is installed properly at
> /usr/lib/python2.4/site-packages/cElementTree.so
>
> i.e.
>
> python -c 'import cElementTree;print cElementTree'
> returns
> <module 'cElementTree' from 'cElementTree.so'>
>
> And after:
>
>>>>from cElementTree import *
>
> I can issue
>
>>>>help ("cElementTree")
>
> etc.
>
>
> It seems to me that there is a problem in bzrlib/xml.py
> Please note that documentation at
> http://effbot.org/zone/celementtree.htm explicitly states that we need
> *both* cElementTree and standard ElementTree. (e.g. 'fromstring' is not
> defined in cElementTree, I double checked 'cElementTree.so' with nm)
>
> Attached patch resolves issue for me. Did I get it right, or I am
> horribly wrong :-)
>
>
> ------------------------------------------------------------------------
>
> --- bzrlib/xml.py.orig 2006-01-25 16:58:14.000000000 +0100
> +++ bzrlib/xml.py 2006-01-25 17:15:51.000000000 +0100
> @@ -25,8 +25,8 @@
> from bzrlib.trace import mutter, warning
>
> try:
> - from cElementTree import (ElementTree, SubElement, Element,
> - XMLTreeBuilder, fromstring, tostring)
> + from cElementTree import (SubElement, Element, XMLTreeBuilder)
> + from util.elementtree.ElementTree import (ElementTree, fromstring, tostring)
> except ImportError:
> mutter('WARNING: using slower ElementTree; consider installing cElementTree'
> " and make sure it's on your PYTHONPATH")
I would tend to write the functionality as:
try:
from cElementTree import (SubElement, Element,
XMLTreeBuilder)
except ImportError:
mutter('WARNING: using slower ElementTree; consider installing
cElementTree'
" and make sure it's on your PYTHONPATH")
from util.elementtree.ElementTree import (SubElement,
Element, XMLTreeBuilder)
from util.elementtree.ElementTree import fromstring, tostring
However, if we are importing fromstring and tostring from ElementTree
and not cElementTree, doesn't this mean we are loosing the performance
benefits?
I'm not positive, because tostring is the same function, but
'fromstring' seems to be a different function.
>>> import cElementTree
>>> import elementtree.ElementTree
>>> cElementTree.fromstring
<function XML at 0xb7aedf7c>
>>> elementtree.ElementTree.fromstring
<function XML at 0xb7aed8b4>
>>> elementtree.ElementTree.tostring
<function tostring at 0xb7aed9cc>
>>> cElementTree.tostring
<function tostring at 0xb7aed9cc>
>>>
Are you sure that both fromstring and tostring are missing? And that it
isn't a bug in cElementTree? tostring probably is about the same in
speed, but fromstring should be much faster using cElementTree. (since
it would use C callbacks rather than Python callbacks).
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060125/c32398e6/attachment.pgp
More information about the bazaar
mailing list