Rename to slixmpp
[slixmpp.git] / slixmpp / plugins / xep_0004 / dataforms.py
blob90a87774aa716555c9f6735d236d80e7e13fab27
1 """
2 Slixmpp: The Slick XMPP Library
3 Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of Slixmpp.
6 See the file LICENSE for copying permission.
7 """
9 from slixmpp import Message
10 from slixmpp.xmlstream import register_stanza_plugin
11 from slixmpp.xmlstream.handler import Callback
12 from slixmpp.xmlstream.matcher import StanzaPath
13 from slixmpp.plugins import BasePlugin
14 from slixmpp.plugins.xep_0004 import stanza
15 from slixmpp.plugins.xep_0004.stanza import Form, FormField, FieldOption
18 class XEP_0004(BasePlugin):
20 """
21 XEP-0004: Data Forms
22 """
24 name = 'xep_0004'
25 description = 'XEP-0004: Data Forms'
26 dependencies = set(['xep_0030'])
27 stanza = stanza
29 def plugin_init(self):
30 self.xmpp.register_handler(
31 Callback('Data Form',
32 StanzaPath('message/form'),
33 self.handle_form))
35 register_stanza_plugin(FormField, FieldOption, iterable=True)
36 register_stanza_plugin(Form, FormField, iterable=True)
37 register_stanza_plugin(Message, Form)
39 def plugin_end(self):
40 self.xmpp.remove_handler('Data Form')
41 self.xmpp['xep_0030'].del_feature(feature='jabber:x:data')
43 def session_bind(self, jid):
44 self.xmpp['xep_0030'].add_feature('jabber:x:data')
46 def make_form(self, ftype='form', title='', instructions=''):
47 f = Form()
48 f['type'] = ftype
49 f['title'] = title
50 f['instructions'] = instructions
51 return f
53 def handle_form(self, message):
54 self.xmpp.event("message_xform", message)
56 def build_form(self, xml):
57 return Form(xml=xml)