summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0004
diff options
context:
space:
mode:
authorRobert Robinson <rerobins@gmail.com>2015-09-15 10:07:34 -0600
committerRobert Robinson <rerobins@gmail.com>2015-09-15 10:07:34 -0600
commit7059400020d21c960b87aa41189b1b26c3776061 (patch)
treea8b563451b58ba582564f5ef5c2b7f8c7e2735cd /sleekxmpp/plugins/xep_0004
parent110cf25c6d6055e0decb6907bfc7d0df8434c839 (diff)
parent0b14ef82d4058925e7e9db22038777d4654e8199 (diff)
downloadslixmpp-7059400020d21c960b87aa41189b1b26c3776061.tar.gz
slixmpp-7059400020d21c960b87aa41189b1b26c3776061.tar.bz2
slixmpp-7059400020d21c960b87aa41189b1b26c3776061.tar.xz
slixmpp-7059400020d21c960b87aa41189b1b26c3776061.zip
Merge branch 'refactor_forms' into add_xep_0122
Diffstat (limited to 'sleekxmpp/plugins/xep_0004')
-rw-r--r--sleekxmpp/plugins/xep_0004/stanza/form.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/sleekxmpp/plugins/xep_0004/stanza/form.py b/sleekxmpp/plugins/xep_0004/stanza/form.py
index f55e88a9..3dcc7821 100644
--- a/sleekxmpp/plugins/xep_0004/stanza/form.py
+++ b/sleekxmpp/plugins/xep_0004/stanza/form.py
@@ -9,7 +9,7 @@
import copy
import logging
-from sleekxmpp.thirdparty import OrderedDict
+from sleekxmpp.thirdparty import OrderedDict, OrderedSet
from sleekxmpp.xmlstream import ElementBase, ET
from sleekxmpp.plugins.xep_0004.stanza import FormField
@@ -22,7 +22,7 @@ class Form(ElementBase):
namespace = 'jabber:x:data'
name = 'x'
plugin_attrib = 'form'
- interfaces = set(('instructions', 'items', 'reported', 'title', 'type', ))
+ interfaces = OrderedSet(('instructions', 'reported', 'title', 'type', 'items', ))
sub_interfaces = set(('title',))
form_types = set(('cancel', 'form', 'result', 'submit'))
@@ -169,7 +169,7 @@ class Form(ElementBase):
def get_reported(self):
fields = OrderedDict()
xml = self.xml.findall('{%s}reported/{%s}field' % (self.namespace,
- FormField.namespace))
+ FormField.namespace))
for field in xml:
field = FormField(xml=field)
fields[field['var']] = field
@@ -219,10 +219,26 @@ class Form(ElementBase):
self.add_item(item)
def set_reported(self, reported):
+ """
+ This either needs a dictionary or dictionaries or a dictionary of form fields.
+ :param reported:
+ :return:
+ """
for var in reported:
field = reported[var]
- field['var'] = var
- self.add_reported(var, **field)
+
+ if isinstance(field, dict):
+ self.add_reported(**field)
+ else:
+ reported = self.xml.find('{%s}reported' % self.namespace)
+ if reported is None:
+ reported = ET.Element('{%s}reported' % self.namespace)
+ self.xml.append(reported)
+
+ fieldXML = ET.Element('{%s}field' % FormField.namespace)
+ reported.append(fieldXML)
+ new_field = FormField(xml=fieldXML)
+ new_field.values = field.values
def set_values(self, values):
fields = self.get_fields()