[Twisted-Python] domish.Element.__getattr__() or xpath.XPathQuery

Hello everyone, I was wondering what you would recommend, accessing nodes via domish.Element.__getattr__() (e.g. el.node1.node1_1, where el is /msg) or via xpath.XPathQuery() (e.g. xpath.XPathQuery("/msg/node1/node1_1").queryForNodes(el)[0])? I was wondering which would be faster, the __getattr__() is O(n) (in my example there are 2 calls) but what about xpath.XPathQuery()? Thank you, Gabriel

On 4 Feb, 10:48 am, gabriel.rossetti@arimaz.com wrote:
Hello everyone,
I was wondering what you would recommend, accessing nodes via domish.Element.__getattr__() (e.g. el.node1.node1_1, where el is /msg) or via xpath.XPathQuery() (e.g. xpath.XPathQuery("/msg/node1/node1_1").queryForNodes(el)[0])?
I was wondering which would be faster, the __getattr__() is O(n) (in my example there are 2 calls) but what about xpath.XPathQuery()?
I don't think you'll find the xpath API to be much more optimized. I haven't used XMPP much, but considering the xpath implementation is incomplete (and afaik there's little documentation about what subset is supported), I'd stick with the simpler (if still terrible) Element.__getattr__. Jean-Paul

exarkun@twistedmatrix.com wrote:
On 4 Feb, 10:48 am, gabriel.rossetti@arimaz.com wrote:
Hello everyone,
I was wondering what you would recommend, accessing nodes via domish.Element.__getattr__() (e.g. el.node1.node1_1, where el is /msg) or via xpath.XPathQuery() (e.g. xpath.XPathQuery("/msg/node1/node1_1").queryForNodes(el)[0])?
I was wondering which would be faster, the __getattr__() is O(n) (in my example there are 2 calls) but what about xpath.XPathQuery()?
I don't think you'll find the xpath API to be much more optimized. I haven't used XMPP much, but considering the xpath implementation is incomplete (and afaik there's little documentation about what subset is supported), I'd stick with the simpler (if still terrible) Element.__getattr__.
Jean-Paul
Ok, thank you. Just a question, would it be interesting to anyone to be able to choose in between the internal XPATH implementation and an external lib/implementation for the XMPP stuff? I have often wondered if it would not be better to allow the user to choose. Gabriel

On Mon, Feb 08, 2010 at 08:26:43AM +0100, Gabriel Rossetti wrote:
Ok, thank you. Just a question, would it be interesting to anyone to be able to choose in between the internal XPATH implementation and an external lib/implementation for the XMPP stuff? I have often wondered if it would not be better to allow the user to choose.
I seem to recall that the last time people discussed reusing a generic XML library rather than a custom one, it was discovered that XMPP isn't quite actually XML - it has a bunch of crazy restrictions that basically mean you need an XMPP-specific library. If there's a third-part XMPP library that could be plugged in, that would be a very interesting thing to know.

On 11:03 am, screwtape@froup.com wrote:
On Mon, Feb 08, 2010 at 08:26:43AM +0100, Gabriel Rossetti wrote:
Ok, thank you. Just a question, would it be interesting to anyone to be able to choose in between the internal XPATH implementation and an external lib/implementation for the XMPP stuff? I have often wondered if it would not be better to allow the user to choose.
I seem to recall that the last time people discussed reusing a generic XML library rather than a custom one, it was discovered that XMPP isn't quite actually XML - it has a bunch of crazy restrictions that basically mean you need an XMPP-specific library. If there's a third-part XMPP library that could be plugged in, that would be a very interesting thing to know.
The discussion is mostly summarized here: http://twistedmatrix.com/trac/ticket/3201 I hope that eventually someone will find a good XML library which has the the features described there, and then we can switch to it. Jean-Paul
participants (3)
-
exarkun@twistedmatrix.com
-
Gabriel Rossetti
-
Tim Allen