From 7265682a4d57d88956cb54f98f7a470465bbf417 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 18 Aug 2014 00:52:24 +0200 Subject: cleanup semicolons, whitespace and mutable default arguments --- sleekxmpp/plugins/xep_0004/stanza/form.py | 1 - 1 file changed, 1 deletion(-) (limited to 'sleekxmpp/plugins/xep_0004/stanza') diff --git a/sleekxmpp/plugins/xep_0004/stanza/form.py b/sleekxmpp/plugins/xep_0004/stanza/form.py index bbd8540f..baa01528 100644 --- a/sleekxmpp/plugins/xep_0004/stanza/form.py +++ b/sleekxmpp/plugins/xep_0004/stanza/form.py @@ -151,7 +151,6 @@ class Form(ElementBase): return fields def get_instructions(self): - instructions = '' instsXML = self.xml.findall('{%s}instructions' % self.namespace) return "\n".join([instXML.text for instXML in instsXML]) -- cgit v1.2.3 From 3dd379cdf12d885e26f8ec26c54879a95d5f0b84 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 18 Aug 2014 15:15:14 +0200 Subject: Revert "cleanup semicolons, whitespace and mutable default arguments" This reverts commit 7265682a4d57d88956cb54f98f7a470465bbf417. --- sleekxmpp/plugins/xep_0004/stanza/form.py | 1 + 1 file changed, 1 insertion(+) (limited to 'sleekxmpp/plugins/xep_0004/stanza') diff --git a/sleekxmpp/plugins/xep_0004/stanza/form.py b/sleekxmpp/plugins/xep_0004/stanza/form.py index baa01528..bbd8540f 100644 --- a/sleekxmpp/plugins/xep_0004/stanza/form.py +++ b/sleekxmpp/plugins/xep_0004/stanza/form.py @@ -151,6 +151,7 @@ class Form(ElementBase): return fields def get_instructions(self): + instructions = '' instsXML = self.xml.findall('{%s}instructions' % self.namespace) return "\n".join([instXML.text for instXML in instsXML]) -- cgit v1.2.3 From aabec8b993748866b9cf3f09ebb7ae7ce2ddc426 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 21 Aug 2014 10:05:42 -0700 Subject: Fix some more Unicode in **kwargs issues in Py2.6 --- sleekxmpp/plugins/xep_0004/stanza/form.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'sleekxmpp/plugins/xep_0004/stanza') diff --git a/sleekxmpp/plugins/xep_0004/stanza/form.py b/sleekxmpp/plugins/xep_0004/stanza/form.py index bbd8540f..f51e7f09 100644 --- a/sleekxmpp/plugins/xep_0004/stanza/form.py +++ b/sleekxmpp/plugins/xep_0004/stanza/form.py @@ -195,7 +195,14 @@ class Form(ElementBase): fields = fields.items() for var, field in fields: field['var'] = var - self.add_field(**field) + self.add_field( + var = field.get('var'), + label = field.get('label'), + desc = field.get('desc'), + required = field.get('required'), + value = field.get('value'), + options = field.get('options'), + type = field.get('type')) def set_instructions(self, instructions): del self['instructions'] -- cgit v1.2.3 From afc939708ff71e168f9204f1eab8823b7dc9f875 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 18 Aug 2014 00:52:24 +0200 Subject: cleanup semicolons, whitespace and mutable default arguments --- sleekxmpp/plugins/xep_0004/stanza/form.py | 1 - 1 file changed, 1 deletion(-) (limited to 'sleekxmpp/plugins/xep_0004/stanza') diff --git a/sleekxmpp/plugins/xep_0004/stanza/form.py b/sleekxmpp/plugins/xep_0004/stanza/form.py index f51e7f09..1d733760 100644 --- a/sleekxmpp/plugins/xep_0004/stanza/form.py +++ b/sleekxmpp/plugins/xep_0004/stanza/form.py @@ -151,7 +151,6 @@ class Form(ElementBase): return fields def get_instructions(self): - instructions = '' instsXML = self.xml.findall('{%s}instructions' % self.namespace) return "\n".join([instXML.text for instXML in instsXML]) -- cgit v1.2.3 From 0724f623bb613007f9acd6540efd4f256c8b6503 Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Mon, 14 Sep 2015 14:31:17 -0600 Subject: Force forms and fields to use plugin resolution Instead of using the interface/subinterface code that was currently being implemented for the plugin. (cherry picked from commit 1467ec7) --- sleekxmpp/plugins/xep_0004/stanza/field.py | 4 +++- sleekxmpp/plugins/xep_0004/stanza/form.py | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'sleekxmpp/plugins/xep_0004/stanza') diff --git a/sleekxmpp/plugins/xep_0004/stanza/field.py b/sleekxmpp/plugins/xep_0004/stanza/field.py index 51f85995..73e48758 100644 --- a/sleekxmpp/plugins/xep_0004/stanza/field.py +++ b/sleekxmpp/plugins/xep_0004/stanza/field.py @@ -13,8 +13,9 @@ class FormField(ElementBase): namespace = 'jabber:x:data' name = 'field' plugin_attrib = 'field' + plugin_multi_attrib = 'fields' interfaces = set(('answer', 'desc', 'required', 'value', - 'options', 'label', 'type', 'var')) + 'label', 'type', 'var')) sub_interfaces = set(('desc',)) plugin_tag_map = {} plugin_attrib_map = {} @@ -165,6 +166,7 @@ class FieldOption(ElementBase): plugin_attrib = 'option' interfaces = set(('label', 'value')) sub_interfaces = set(('value',)) + plugin_multi_attrib = 'options' FormField.addOption = FormField.add_option diff --git a/sleekxmpp/plugins/xep_0004/stanza/form.py b/sleekxmpp/plugins/xep_0004/stanza/form.py index 1d733760..cca9d2e0 100644 --- a/sleekxmpp/plugins/xep_0004/stanza/form.py +++ b/sleekxmpp/plugins/xep_0004/stanza/form.py @@ -22,8 +22,8 @@ class Form(ElementBase): namespace = 'jabber:x:data' name = 'x' plugin_attrib = 'form' - interfaces = set(('fields', 'instructions', 'items', - 'reported', 'title', 'type', 'values')) + interfaces = set(('instructions', 'items', + 'reported', 'title', 'type', )) sub_interfaces = set(('title',)) form_types = set(('cancel', 'form', 'result', 'submit')) @@ -48,7 +48,7 @@ class Form(ElementBase): def set_type(self, ftype): self._set_attr('type', ftype) if ftype == 'submit': - fields = self['fields'] + fields = self.get_fields() for var in fields: field = fields[var] del field['type'] @@ -74,7 +74,8 @@ class Form(ElementBase): field['desc'] = desc field['required'] = required if options is not None: - field['options'] = options + for option in options: + field.add_option(**option) else: del field['type'] self.append(field) @@ -227,9 +228,9 @@ class Form(ElementBase): def set_values(self, values): fields = self['fields'] for field in values: - if field not in fields: + if field not in self.get_fields(): fields[field] = self.add_field(var=field) - fields[field]['value'] = values[field] + self.get_fields()[field]['value'] = values[field] def merge(self, other): new = copy.copy(self) -- cgit v1.2.3 From 93c705fb3133b27388c0845f925b0615c88414b1 Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Mon, 14 Sep 2015 17:00:53 -0600 Subject: Fix xep_0050 changes after form refactor. --- sleekxmpp/plugins/xep_0004/stanza/form.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'sleekxmpp/plugins/xep_0004/stanza') diff --git a/sleekxmpp/plugins/xep_0004/stanza/form.py b/sleekxmpp/plugins/xep_0004/stanza/form.py index cca9d2e0..f55e88a9 100644 --- a/sleekxmpp/plugins/xep_0004/stanza/form.py +++ b/sleekxmpp/plugins/xep_0004/stanza/form.py @@ -22,8 +22,7 @@ class Form(ElementBase): namespace = 'jabber:x:data' name = 'x' plugin_attrib = 'form' - interfaces = set(('instructions', 'items', - 'reported', 'title', 'type', )) + interfaces = set(('instructions', 'items', 'reported', 'title', 'type', )) sub_interfaces = set(('title',)) form_types = set(('cancel', 'form', 'result', 'submit')) @@ -43,7 +42,7 @@ class Form(ElementBase): @property def field(self): - return self['fields'] + return self.get_fields() def set_type(self, ftype): self._set_attr('type', ftype) @@ -178,7 +177,7 @@ class Form(ElementBase): def get_values(self): values = OrderedDict() - fields = self['fields'] + fields = self.get_fields() for var in fields: values[var] = fields[var]['value'] return values @@ -226,7 +225,7 @@ class Form(ElementBase): self.add_reported(var, **field) def set_values(self, values): - fields = self['fields'] + fields = self.get_fields() for field in values: if field not in self.get_fields(): fields[field] = self.add_field(var=field) -- cgit v1.2.3 From 0b14ef82d4058925e7e9db22038777d4654e8199 Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Tue, 15 Sep 2015 10:05:53 -0600 Subject: Add test case for reported and items Previous stanza test cases didn't have test cases for reported and item field types in forms. This fixes that issue. Modified stanzabase to use an ordered dict so that can guarentee the that 'items' in a form are added after reported. Also updated the set of interfaces that are stored in Form to be a ordered set. Used the order set implementation from: https://code.activestate.com/recipes/576694/ The OrderedSet implementation is licensed under the MIT license and is developed by the same developer of the ordereddict. --- sleekxmpp/plugins/xep_0004/stanza/form.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'sleekxmpp/plugins/xep_0004/stanza') 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() -- cgit v1.2.3