[XML-SIG] 'Strange' behaviour of TreeWalker

jpoenninghaus@canopus.lili.uni-bielefeld.de jpoenninghaus@canopus.lili.uni-bielefeld.de
Wed, 17 Apr 2002 10:02:53 +0200


Hi,

I'm quite new to Python (and pyxml / 4Suite ) and was quite confused by a
'strange' difference between NodeIterator and TreeWalker.

While instances of NodeIterator are "printable" and give reasonable
error messages, eg. accessing undefined attributes, instances of TreeWalker
give hard times to novice users as __getattr__() effectively prevents any such 
access without reasonable message.

Is that the intended behaviour or just an unwanted side-effect?
At least, a note in the docs might be valuable to others.


Thanks for your attention

Jens Poenninghaus

_________________

Transcript of simple session:

>>> from xml.dom import NodeIterator,TreeWalker
>>> no=NodeIterator.NodeIterator("a","b","c",1) 
>>> tw=TreeWalker.TreeWalker("a","b","c",1) 

>>> print no
<xml.dom.NodeIterator.NodeIterator instance at 0x81a3f44>

>>> print no.__dict__
{'_nodeStack': [], '_current': 'a', 'expandEntityReferences': 1, '_atStart': 1, 'root': 'a', '_detached': 0, 'whatToShow': 'b', '_atEnd': 0, 'filter': 'c'}

>>> print tw.__dict__
{'__root': 'a', '__whatToShow': 'b', '__expandEntityReferences': 1, '__currentNode': 'a', '__filter': 'c'}
>>> print tw

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object of type 'None' is not callable

>>> print no.stupidMethodCall()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: NodeIterator instance has no attribute 'stupidMethodCall'

>>> print tw.stupidMethodCall()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object of type 'None' is not callable