[lxml-dev] objectify.ObjectPath("wrongroot.a.b")(root, None) should not raise an exception

Holger Joukl jholg at gmx.de
Wed Aug 20 17:09:09 CEST 2008


Hi,

 using an absolute ObjectPath with a wrong root element 

objectify.ObjectPath("wrongroot.a.b")(root, None) currently raises 
ValueError

even if a default is given:

 >>> root = objectify.fromstring("<root><a><b>23</b></a></root>")
>>> objectify.ObjectPath("root.a.b")(root, None)
23
>>> objectify.ObjectPath("wrongroot.a.b")(root, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "objectpath.pxi", line 53, in lxml.objectify.ObjectPath.__call__
  File "objectpath.pxi", line 197, in lxml.objectify._findObjectPath
ValueError: root element does not match: need wrongroot, got root
>>> 

 Whereas ObjectPath returns a given default if any other 

element of the path is not in the tree:

 >>> objectify.ObjectPath("root.wronga.b")(root, None)
>>>
 I'll change this in trunk to gracefully return the default, and add some 
tests

(unless someone stops me... :)

 Holger 

 
-- 
Psssst! Schon das coole Video vom GMX MultiMessenger gesehen?
Der Eine für Alle: http://www.gmx.net/de/go/messenger03
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/lxml-dev/attachments/20080820/a16ed6d3/attachment.htm 


More information about the lxml-dev mailing list