From ea65b672e75d2b544a2d9c3ef0d497c1e66075bc Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Sat, 12 Sep 2015 22:10:28 -0600 Subject: Initial cut at getting the stanzas to work. (cherry picked from commit 8c7df49) --- sleekxmpp/plugins/xep_0122/__init__.py | 1 + sleekxmpp/plugins/xep_0122/stanza.py | 83 ++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 sleekxmpp/plugins/xep_0122/__init__.py create mode 100644 sleekxmpp/plugins/xep_0122/stanza.py (limited to 'sleekxmpp') diff --git a/sleekxmpp/plugins/xep_0122/__init__.py b/sleekxmpp/plugins/xep_0122/__init__.py new file mode 100644 index 00000000..65ce96a1 --- /dev/null +++ b/sleekxmpp/plugins/xep_0122/__init__.py @@ -0,0 +1 @@ +from sleekxmpp.plugins.xep_0122.stanza import FormValidation diff --git a/sleekxmpp/plugins/xep_0122/stanza.py b/sleekxmpp/plugins/xep_0122/stanza.py new file mode 100644 index 00000000..1807b11c --- /dev/null +++ b/sleekxmpp/plugins/xep_0122/stanza.py @@ -0,0 +1,83 @@ + +from sleekxmpp.xmlstream import ElementBase, ET + + +class FormValidation(ElementBase): + """ + Validation values for form fields. + + Example: + + + + 2003-10-06T11:22:00-07:00 + + """ + + namespace = 'http://jabber.org/protocol/xdata-validate' + name = 'validate' + plugin_attrib = 'validate' + interfaces = set(('datatype', 'basic', 'open', 'range', 'regex', )) + sub_interfaces = set(('basic', 'open', 'range', 'regex', )) + plugin_attrib_map = {} + plugin_tag_map = {} + + def _add_field(self, name): + item_xml = ET.Element('{%s}%s' % (self.namespace, name)) + self.xml.append(item_xml) + return item_xml + + def set_basic(self, value): + self.remove_all() + if value: + self._add_field('basic') + + def set_open(self, value): + self.remove_all() + if value: + self._add_field('open') + + def set_regex(self, regex): + self.remove_all() + if regex: + _regex = self._add_field('regex') + _regex.text = regex + + def set_range(self, value, minimum=None, maximum=None): + self.remove_all() + if value: + _range = self._add_field('range') + _range.attrib['min'] = str(minimum) + _range.attrib['max'] = str(maximum) + + def remove_all(self, except_tag=None): + for a in self.sub_interfaces: + if a != except_tag: + del self[a] + + def get_basic(self): + present = self.xml.find('{%s}basic' % self.namespace) + return present is not None + + def get_open(self): + present = self.xml.find('{%s}open' % self.namespace) + return present is not None + + def get_regex(self): + present = self.xml.find('{%s}regex' % self.namespace) + if present: + return present.text + + return False + + def get_range(self): + present = self.xml.find('{%s}regex' % self.namespace) + if present: + return dict(present.attrib) + + return False + + +FormValidation.getBasic = FormValidation.get_basic +FormValidation.setBasic = FormValidation.set_basic -- cgit v1.2.3 From 5f9abe2e0e06b4cda898db90ba1b524640411e42 Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Mon, 14 Sep 2015 17:04:16 -0600 Subject: Working through test case issues. (cherry picked from commit 6b58cef) --- sleekxmpp/plugins/xep_0122/stanza.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'sleekxmpp') diff --git a/sleekxmpp/plugins/xep_0122/stanza.py b/sleekxmpp/plugins/xep_0122/stanza.py index 1807b11c..bf8545c8 100644 --- a/sleekxmpp/plugins/xep_0122/stanza.py +++ b/sleekxmpp/plugins/xep_0122/stanza.py @@ -24,28 +24,27 @@ class FormValidation(ElementBase): plugin_tag_map = {} def _add_field(self, name): + self.remove_all() item_xml = ET.Element('{%s}%s' % (self.namespace, name)) self.xml.append(item_xml) return item_xml def set_basic(self, value): - self.remove_all() if value: self._add_field('basic') + else: + self['basic'] = False def set_open(self, value): - self.remove_all() if value: self._add_field('open') def set_regex(self, regex): - self.remove_all() if regex: _regex = self._add_field('regex') _regex.text = regex def set_range(self, value, minimum=None, maximum=None): - self.remove_all() if value: _range = self._add_field('range') _range.attrib['min'] = str(minimum) -- cgit v1.2.3 From f2bf6072ec447cf5cc331b4057b29078b1c932b5 Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Mon, 14 Sep 2015 16:35:47 -0600 Subject: Add plugin (cherry picked from commit 2296d56) --- sleekxmpp/plugins/xep_0122/data_validation.py | 19 +++++++++++++++ sleekxmpp/plugins/xep_0122/stanza.py | 34 ++++++++++++++++++--------- 2 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 sleekxmpp/plugins/xep_0122/data_validation.py (limited to 'sleekxmpp') diff --git a/sleekxmpp/plugins/xep_0122/data_validation.py b/sleekxmpp/plugins/xep_0122/data_validation.py new file mode 100644 index 00000000..6f6cbe8c --- /dev/null +++ b/sleekxmpp/plugins/xep_0122/data_validation.py @@ -0,0 +1,19 @@ +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.plugins import BasePlugin +from sleekxmpp.plugins.xep_0004 import stanza +from sleekxmpp.plugins.xep_0004.stanza import FormField +from sleekxmpp.plugins.xep_0122.stanza import FormValidation + + +class XEP_0122(BasePlugin): + """ + XEP-0004: Data Forms + """ + + name = 'xep_0122' + description = 'XEP-0122: Data Forms Validation' + dependencies = set(['xep_0004']) + stanza = stanza + + def plugin_init(self): + register_stanza_plugin(FormField, FormValidation, iterable=True) diff --git a/sleekxmpp/plugins/xep_0122/stanza.py b/sleekxmpp/plugins/xep_0122/stanza.py index bf8545c8..bc3c177a 100644 --- a/sleekxmpp/plugins/xep_0122/stanza.py +++ b/sleekxmpp/plugins/xep_0122/stanza.py @@ -13,13 +13,17 @@ class FormValidation(ElementBase): datatype='xs:dateTime'/> 2003-10-06T11:22:00-07:00 + + Questions: + Should this look at the datatype value and convert the range values as appropriate? + Should this stanza provide a pass/fail for a value from the field, or convert field value to datatype? """ namespace = 'http://jabber.org/protocol/xdata-validate' name = 'validate' plugin_attrib = 'validate' - interfaces = set(('datatype', 'basic', 'open', 'range', 'regex', )) - sub_interfaces = set(('basic', 'open', 'range', 'regex', )) + interfaces = {'datatype', 'basic', 'open', 'range', 'regex', } + sub_interfaces = {'basic', 'open', 'range', 'regex', } plugin_attrib_map = {} plugin_tag_map = {} @@ -33,22 +37,28 @@ class FormValidation(ElementBase): if value: self._add_field('basic') else: - self['basic'] = False + del self['basic'] def set_open(self, value): if value: self._add_field('open') + else: + del self['open'] def set_regex(self, regex): if regex: _regex = self._add_field('regex') _regex.text = regex + else: + del self['regex'] def set_range(self, value, minimum=None, maximum=None): if value: _range = self._add_field('range') _range.attrib['min'] = str(minimum) _range.attrib['max'] = str(maximum) + else: + del self['range'] def remove_all(self, except_tag=None): for a in self.sub_interfaces: @@ -65,18 +75,20 @@ class FormValidation(ElementBase): def get_regex(self): present = self.xml.find('{%s}regex' % self.namespace) - if present: + if present is not None: return present.text return False def get_range(self): - present = self.xml.find('{%s}regex' % self.namespace) - if present: - return dict(present.attrib) + present = self.xml.find('{%s}range' % self.namespace) + if present is not None: + attributes = present.attrib + return_value = dict() + if 'min' in attributes: + return_value['minimum'] = attributes['min'] + if 'max' in attributes: + return_value['maximum'] = attributes['max'] + return return_value return False - - -FormValidation.getBasic = FormValidation.get_basic -FormValidation.setBasic = FormValidation.set_basic -- cgit v1.2.3 From 110cf25c6d6055e0decb6907bfc7d0df8434c839 Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Mon, 14 Sep 2015 17:06:07 -0600 Subject: Add plugin support --- sleekxmpp/plugins/xep_0122/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sleekxmpp') diff --git a/sleekxmpp/plugins/xep_0122/__init__.py b/sleekxmpp/plugins/xep_0122/__init__.py index 65ce96a1..c0a0bc35 100644 --- a/sleekxmpp/plugins/xep_0122/__init__.py +++ b/sleekxmpp/plugins/xep_0122/__init__.py @@ -1 +1,11 @@ + +from sleekxmpp.plugins.base import register_plugin from sleekxmpp.plugins.xep_0122.stanza import FormValidation +from sleekxmpp.plugins.xep_0122.data_validation import XEP_0122 + + +register_plugin(XEP_0122) + + +# Retain some backwards compatibility +xep_0121 = XEP_0122 -- cgit v1.2.3 From d9b47b33f5101b52e781780f1a9685c7281b3015 Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Tue, 15 Sep 2015 10:20:37 -0600 Subject: Update __init__.py changed xep_0121 to xep_0122 --- sleekxmpp/plugins/xep_0122/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sleekxmpp') diff --git a/sleekxmpp/plugins/xep_0122/__init__.py b/sleekxmpp/plugins/xep_0122/__init__.py index c0a0bc35..4b3e9483 100644 --- a/sleekxmpp/plugins/xep_0122/__init__.py +++ b/sleekxmpp/plugins/xep_0122/__init__.py @@ -8,4 +8,4 @@ register_plugin(XEP_0122) # Retain some backwards compatibility -xep_0121 = XEP_0122 +xep_0122 = XEP_0122 -- cgit v1.2.3 From 329cb5a9f846ca0ce38c0d5730ba7da8480e50ae Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Thu, 17 Sep 2015 16:21:13 -0600 Subject: Add 0122 to plugin/__init__.py __all__ --- sleekxmpp/plugins/__init__.py | 1 + 1 file changed, 1 insertion(+) (limited to 'sleekxmpp') diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py index 2c90d357..f501687b 100644 --- a/sleekxmpp/plugins/__init__.py +++ b/sleekxmpp/plugins/__init__.py @@ -47,6 +47,7 @@ __all__ = [ 'xep_0108', # User Activity 'xep_0115', # Entity Capabilities 'xep_0118', # User Tune + 'xep_0122', # Data Forms Validation 'xep_0128', # Extended Service Discovery 'xep_0131', # Standard Headers and Internet Metadata 'xep_0133', # Service Administration -- cgit v1.2.3 From a7ac9692153ef28f55279a000e106622df7ccabb Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Thu, 17 Sep 2015 16:21:54 -0600 Subject: register_Stanza_plugin shouldn't be iterable Should not use iterable for registering the stanza plugins. --- sleekxmpp/plugins/xep_0122/data_validation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sleekxmpp') diff --git a/sleekxmpp/plugins/xep_0122/data_validation.py b/sleekxmpp/plugins/xep_0122/data_validation.py index 6f6cbe8c..ec2cdfcc 100644 --- a/sleekxmpp/plugins/xep_0122/data_validation.py +++ b/sleekxmpp/plugins/xep_0122/data_validation.py @@ -16,4 +16,4 @@ class XEP_0122(BasePlugin): stanza = stanza def plugin_init(self): - register_stanza_plugin(FormField, FormValidation, iterable=True) + register_stanza_plugin(FormField, FormValidation) -- cgit v1.2.3