I am new in python and I am trying to create a testing python script to test different actions on my XMPP server. I already was able to test the login of my user and now I want to get the information that the server is sending (stanza) and set new information.
I have read several webs and I am not very clear with all this information. The main source has been sleekxmpp.com.
I have my stanza:
<iq type='get' to= 'chat.net' id='id1'>
<aa xmlns='http://myweb.com' />
</iq>
<iq type='result' to= 'chat.net' id='id1'>
<aa xmlns='http://myweb.com' >
<name>My name as included in sent mails<name>
<lang>en</lang>
<mail>My mail as included in sent mails</mail>
</aa>
</iq>
I want to get the information and also set one of the parameters (lets say name) but I don’t know how.
class user_info(sleekxmpp.stanza.Iq):
self.get_query()
I must do it in python. Any help appreciated
What you want to do is create a custom stanza class for your stanza. Here’s one that will work for the example you have:
Ok, so what does all of that do? The
namefield specifies that the XML object’s root tag is ‘aa’, andnamespacespecifies the root tag’s namespace; obvious so far I hope.The
plugin_attribfield is the name that can be used to access this stanza from the parent stanza. For example, you should already be familiar with how you can useiq['type']oriq['from']to extract data out of an Iq stanza. Withplugin_attribset to"aa", then you can useiq['aa']to get a reference to the AA content.The
interfacesset is the set of key names that this stanza provides for extracting information, just like working with dictionaries. For example an Iq stanza has ‘to’, ‘from’, ‘type’, etc in its interfaces set. By default, accessing and modifying these keys will create or modify attributes of the stanza’s main element. So, at this point, your stanza would behave like this:Now, to instead map interface keys to subelements instead of attributes, they need to be in the
sub_interfacesset. So by settingsub_interfaces = interfacesthe above example would now work like so:If you needed something more advanced, you could also define methods of the form get_* / set_* / del_* where * is the interface name which will then be used to extract or modify data.
So, all together, you will be able to do:
Also, don’t forget that we have the sleek@conference.jabber.org chat room for SleekXMPP help if you need it.