-----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(a)xmpp-cls.intamac.com/xmppadmin"
> from="84eb18ceb80d(a)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(a)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
-----BEGIN PGP SIGNATURE-----
iQIzBAEBCgAdFiEEG/EPV+Xzd5wEoQQIwGIDJZdiWIoFAll0v80ACgkQwGIDJZdi
WIppMg/+KuHFKrHpkP2VuVxAy0rcurmKfGR53QhPTrJJoIQSjwj2nzZmda/X9boW
3gtHBClWk4IQRRGTc35D7TbsInLQQ5EWuBDB1RDkeuu9kCqPAfiPXtr8/z6PNh6O
AnsmZCZ9ZgbzNNDv0Pr0n+8TOq+U4jV8hEwGbO7xOPDBfLOXGRB5d2WxDBiI8gKV
iQThQZUt43xAX0MIYF5xlCHzyVV8m8KoAb1HU4Up/sqrj0Z8US11yd9IUr2OvD8/
tkCwtjnUmmqrcsPxgBoVFfYvZiRVYkVxMr8mLufFhlL+WDjO8luEr+TGGd2V66nY
oxvyYSvh3vHFgANTUM0VZnW2y6zXcdB6Vf2Gprh1ImE7hrTh8s8tmwhsqWJ37B/9
04JM50JWMJrZXYkRvon0byxsQdiJ7f8jlrY/JUEV8bTb4ysANZmEuflWH1zuuSkv
bcGdjdxGcGE3OneZ3Yr8JfERY905euf3iNS2wFNfo8gO390X9s4C1XNGCfwOMzTj
Us5NaujadcN9hmdcvaZePdq+3HpmyUyHVtLBY/Wiu+1JCu4kI8aFo91mhQfzozLm
jP5fhjmQqzi2I6y+a/ywbbNKXeRozJ7Q7CzSQXH4m7cj+X1gsm//0dGgVeDE/ybn
5eak+5mGST/EG3Jh+fVo+kmF3izk+mFMWUkwzEqSbh51uW1hq8k=
=xrDN
-----END PGP SIGNATURE-----