Source code for slixmpp.plugins.xep_0004.dataforms
# Slixmpp: The Slick XMPP Library# Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout# This file is part of Slixmpp.# See the file LICENSE for copying permission.fromslixmppimportMessagefromslixmpp.xmlstreamimportregister_stanza_pluginfromslixmpp.xmlstream.handlerimportCallbackfromslixmpp.xmlstream.matcherimportStanzaPathfromslixmpp.pluginsimportBasePluginfromslixmpp.plugins.xep_0004importstanzafromslixmpp.plugins.xep_0004.stanzaimportForm,FormField,FieldOption
[docs]classXEP_0004(BasePlugin):""" XEP-0004: Data Forms """name='xep_0004'description='XEP-0004: Data Forms'dependencies={'xep_0030'}stanza=stanzadefplugin_init(self):self.xmpp.register_handler(Callback('Data Form',StanzaPath('message/form'),self.handle_form))register_stanza_plugin(FormField,FieldOption,iterable=True)register_stanza_plugin(Form,FormField,iterable=True)register_stanza_plugin(Message,Form)defplugin_end(self):self.xmpp.remove_handler('Data Form')self.xmpp['xep_0030'].del_feature(feature='jabber:x:data')defsession_bind(self,jid):self.xmpp['xep_0030'].add_feature('jabber:x:data')defmake_form(self,ftype='form',title='',instructions=''):f=Form()f['type']=ftypef['title']=titlef['instructions']=instructionsreturnfdefhandle_form(self,message):self.xmpp.event("message_xform",message)defbuild_form(self,xml):returnForm(xml=xml)