Re: [xml] faster replacement for python 2.2

Daniel Veillard kirjutas P, 05.01.2003 kell 01:30:
On Sat, Jan 04, 2003 at 05:08:06PM +0500, Hannu Krosing wrote:

I have modified (the handmade part of to make 
use of some new features of python 2.2 , namely

1) replaced __gettattr__() with property()

  Okay, I integrated both using
    import sys
    if float(sys.version[0:3]) < 2.2:
        def __getattr__(self, attr):
            ... existing code ...
        ... your property based definitions ...

  see the enclosed result.

2) added an __iter__() method that returns an iterator over subtree of

  That I couldn't make to work over 1.5 and 2.1 :

It will not work on 1.5 as it just does not support iterators.

It _may_ work with 2.1 with some "from __future__ import xxx2 stuff

veillard:~/XML/python -> python1.5
Traceback (innermost last):
  File "", line 17, in ?
  File "", line 10, in nodecount
    for node in doc:
  File "", line 307, in __getattr__
    raise AttributeError,attr
AttributeError: __getitem__
veillard:~/XML/python ->

  It seems that defining __getitem__ along to __getattr__ for the
old code would allow to provide that facility on the older framework
and I would really prefer that. Maybe reuse the iterator is possible
it should just be a bit of glue it seems.

The result of replacing __gettattr__() with property() is a 2x speedup
when iterating over tree using and node.children

An additional 12% speedup can be gained by not having a separate xmlCore
class (it is used only by xmlNode) but including the hand-made part
directly in definition of class xmlNode.

    Well, that's harder due to the autogeneration of xmlNode,

I was thinking about generating a chunk of code that would be inserted
into the xmlNode in the phase that merges the two (handmade and
generated) parts.

Hannu Krosing <hannu tm ee>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]