-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512
Hi Adam,
First of all, to post to aioxmpp-devel, you need to be subscribed. As an administrator, I still got your message, but nobody else got it. Replying to the list.
On Samstag, 22. Juli 2017 17:01:30 CEST you wrote:
Is there a way to embed a substanza directly (so as a string with XML tags) to the Message and IQ stanzas?
Yes, with some (supported) trickery. See below ...
I need to stress test an IOT application which communicates with various hardware devices, and it would be extremely tedious to define these stanzas properly.
(so I don't care about the response, I just want to send a bunch of stuff)
In general, it is preferable to define it properly. If there is even a slim chance that you might need to do proper interaction with the IoT application at a later point (for example for a server side application or something like that), you’ll benefit from properly defining the schema.
An example of what I want to send:
<message id="2190" type="chat" to="mzclientxmppapp@xmpp-cls.intamac.com/xmppadmin" from="84eb18ceb80d@xmpp-cls.intamac.com/smarthub" xmlns="jabber:client"> <alert xmlns="Intamac:alert" id="14147" alert="Car_AlarmEnd" source="aad" timestamp="1470013199" /> </message>
aioxmpp supports sending and receiving arbitrary XML trees. You cannot directly send raw strings of XML, because that would be unsafe (the whole stream would break if you sent "<test>" without closing tag).
By default, Message stanzas do not support this, but you can monkey patch that behaviour into it using:
# put these lines somewhere in the start up of your app import aioxmpp aioxmpp.Message.raw = aioxmpp.xso.Collector()
(see [1] for details on the Collector descriptor)
Now you can compose your message like this:
import lxml.etree as etree
msg = aioxmpp.Message( type_=aioxmpp.MessageType.CHAT, to=aioxmpp.JID.fromstr("mzclientxmppapp@xmpp-cls.intamac.com/xmppadmin"), ) msg.raw.append(etree.fromstring( '<alert xmlns="Intamac:alert" id="14147" alert="Car_AlarmEnd"' ' source="aad" timestamp="1470013199" />' ))
The Collector-based attribute is a list of ElementTree or Element objects (from the etree-API). It is normally used as catch-all in situations where it isn’t known what elements will occur beforehand (for example in PubSub notifications), but it can also be used to embed arbitrary XML.
I’ve added a send_raw.py example, check it out in the git repository [2].
Have fun! Jonas
[1]: https://docs.zombofant.net/aioxmpp/devel/api/public/ xso.html#aioxmpp.xso.Collector [2]: https://github.com/horazont/aioxmpp/blob/devel/examples/send_raw.py