Re: [xml] faster replacement libxml.py for python 2.2



On Sat, Jan 04, 2003 at 05:08:06PM +0500, Hannu Krosing wrote:

I have modified libxml.py (the handmade part of libxml2.py) 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 libxml.py code ...
    else:
        ... your property based definitions ...

  see the enclosed result.

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

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

veillard:~/XML/python -> python1.5 tst.py
Traceback (innermost last):
  File "tst.py", line 17, in ?
    nodecount(rec)
  File "tst.py", line 10, in nodecount
    for node in doc:
  File "libxml2.py", 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 node.next 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 tested it by running the following test function over 75000 nodes of
old testament

    Changed it a bit to conform to 1.5 and 2.1 syntax, but it doesn't
run due to the previously mentionned problem, enclosed too.

  I integrated the current version of libxml.py in CVS, but I would
really like to have the portability of the iterator fixed...

  thanks,

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

Attachment: libxml.py
Description: Text document

Attachment: tst.py
Description: Text document



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