Does XPATH in python Twisted support this syntax: "/message/body[.='test']"?

120 Views Asked by At

I'm working on a XMPP testing tool, use Twisted xpath to match XMPP message.

Suppose I have a message stanza like:

<message to='xxx' type='chat'><body>test</body></message>

If I want to match that the message's body text value is "test", then for standard xpath syntax, it will be:

"/message/body[.='test']"

But this syntax is not supported in twisted.

My question is: Is there anyway to resolve this issue? Or it is just impossible?

Thanks in advance.

1

There are 1 best solutions below

1
On

The xpath support provided by Twisted Words for XMPP interactions is very limited. It is far from a full xpath implementation. So, for any particular questions about whether some xpath feature is supported by it or not, the answer is quite possibly that it is not supported.

Ideally, Twisted Words wouldn't need an xpath implementation at all. It could be built on top of one of the other xpath implementations available to Python (eg, the one exposed by lxml). However, no one has yet done the work to determine how to actually achieve this (considering Twisted Words also uses a custom DOM implementation for XMPP as well).

Until that task is undertaken, you can get some idea of what parts of xpath are supported by looking at the grammar at the end of twisted/words/xish/xpathparser.g.

As far as I know, no one has invented a way to combine the Twisted Words DOM with another xpath library, so you're just stuck with the missing features (if you know of such an invention, or invent such a thing yourself, let us know! It might make the above mentioned task easier :).