[merge] python 2.5 fixes

John Arbash Meinel john at arbash-meinel.com
Mon Sep 25 20:45:14 BST 2006


Martin Pool wrote:
> On 25 Sep 2006, James Henstridge <james at jamesh.id.au> wrote:
>> On 22/09/06, Martin Pool <mbp at canonical.com> wrote:
>>> Here's an updated patch including some (much) earlier work.
>>>
>>> This also fixes a missing import of TestSkipped.
>>>
>>> I'm +1 on merging Marien's ElementTree fixes too -- my python2.5 install
>>> doesn't have celementtree.
>> The ElementTree module was renamed to xml.etree.ElementTree when
>> merged into Python 2.5.  Are you sure it wasn't available?
> 
> Well, this is cElementTree, but that's apparently under
> xml.etree.cElementTree too.  But I think without his fix we would still
> have had trouble on 2.4.
> 
> This patch makes bzr look in the new location.
> 
> It also cleans up some code that tries to access elementtree's
> ElementTree class, as opposed othte one from cElementTree.  As far as I
> can see they're the same thing - is there some reason why we can't just
> import the name once?  Anyhow, with this change it passes tests on both
> 2.4 and 2.5.

-1 to your changes.

Actually, they aren't the same thing. The elementtree class is at
elementtree.ElementTree.ElementTree()

we are actually importing the *module* 'elementtree.ElementTree' because
we want to hijack the _escape_attrib and _escape_cdata functions because
we have more efficient ones. (Which doesn't matter as much anymore,
because we have an entirely different xml serializer).

Also, the classes are at different locations in memory:

>>> import elementtree.ElementTree
>>> import cElementTree
>>> elementtree.ElementTree.ElementTree
<class elementtree.ElementTree.ElementTree at 0xb7d0a29c>
>>> cElementTree.ElementTree
<class __builtin__.ElementTree at 0xb7b7323c>
>>> elementtree.ElementTree
<module 'elementtree.ElementTree' from
'/usr/lib/python2.4/site-packages/elementtree/ElementTree.pyc'>

And their functions are at different locations.
>>> id(cElementTree.ElementTree._write)
-1211101316
>>> id(elementtree.ElementTree.ElementTree._write)
-1210676492

So even if we weren't doing what we do, it seems they aren't 100% the
same class.

Also, as part of my 'improve startup times' work, I would like for us to
modify our copy of ElementTree to avoid compiling a nasty regex that
costs us a lot of startup time, and then install the modified version as
the 'official' version. (It would be api consistent with the original,
just a couple modifications to make it load faster).

If you don't want to change the ElementTree sources (which I think we
should, and contribute the changes upstream). I can modify
're.compile()' before importing elementtree, and then restore it afterwards.

John
=:->


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060925/0b66e34f/attachment.pgp 


More information about the bazaar mailing list