changeset 2778:f7deb1c36b47

core, XEP-0315: move XML element handling to sat_tmp: XML Element is now implemented in sat_tmp, so it can be available also for SàT Pubsub. The XEP-0315 is thus not needed anymore and have been removed, XEP-0315 namespace has been added to base disco features. Use the new install() function of sat_tmp to do the patching.
author Goffi <goffi@goffi.org>
date Wed, 16 Jan 2019 09:18:16 +0100 (2019-01-16)
parents ff1b40823b07
children 4cfa2085aebf
files sat/core/xmpp.py sat/plugins/__init__.py sat/plugins/plugin_xep_0315.py
diffstat 3 files changed, 7 insertions(+), 125 deletions(-) [+]
line wrap: on
line diff
--- a/sat/core/xmpp.py	Tue Jan 15 08:51:56 2019 +0100
+++ b/sat/core/xmpp.py	Wed Jan 16 09:18:16 2019 +0100
@@ -45,6 +45,7 @@
 
 NS_X_DATA = u"jabber:x:data"
 NS_DISCO_INFO = u"http://jabber.org/protocol/disco#info"
+NS_XML_ELEMENT = u"urn:xmpp:xml-element"
 
 
 class SatXMPPEntity(object):
@@ -1393,7 +1394,10 @@
         disco.DiscoClientProtocol.__init__(self)
 
     def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
+        # those features are implemented in Wokkel (or sat_tmp.wokkel)
+        # and thus are always available
         return [disco.DiscoFeature(NS_X_DATA),
+                disco.DiscoFeature(NS_XML_ELEMENT),
                 disco.DiscoFeature(NS_DISCO_INFO)]
 
     def getDiscoItems(self, requestor, target, nodeIdentifier=""):
--- a/sat/plugins/__init__.py	Tue Jan 15 08:51:56 2019 +0100
+++ b/sat/plugins/__init__.py	Wed Jan 16 09:18:16 2019 +0100
@@ -1,8 +1,4 @@
-# FIXME: remove this when RSM and MAM are in wokkel
 # XXX: the Monkey Patch is here and not in src/__init__ to avoir issues with pyjamas compilation
-import wokkel
-from sat_tmp.wokkel import pubsub as tmp_pubsub, rsm as tmp_rsm, mam as tmp_mam
-
-wokkel.pubsub = tmp_pubsub
-wokkel.rsm = tmp_rsm
-wokkel.mam = tmp_mam
+# TODO: remove this when changes are merged in Wokkel
+from sat_tmp.wokkel import install
+install()
--- a/sat/plugins/plugin_xep_0315.py	Tue Jan 15 08:51:56 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,118 +0,0 @@
-#!/usr/bin/env python2
-# -*- coding: utf-8 -*-
-
-# SAT plugin to implement XEP-0315 (Data Forms XML Element)
-# Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Affero General Public License for more details.
-
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-from sat.core.i18n import _
-from sat.core.constants import Const as C
-from sat.core.log import getLogger
-from wokkel import data_form
-from twisted.words.xish import domish
-
-log = getLogger(__name__)
-
-PLUGIN_INFO = {
-    C.PI_NAME: "Data Forms XML Element",
-    C.PI_IMPORT_NAME: "XEP-0315",
-    C.PI_TYPE: "XEP",
-    C.PI_PROTOCOLS: ["XEP-0315"],
-    C.PI_DEPENDENCIES: [],
-    C.PI_MAIN: "XEP_0315",
-    C.PI_HANDLER: "no",
-    C.PI_DESCRIPTION: _(u"""Implementation of Data Forms XML Element"""),
-}
-
-NS_XML_ELEMENT = u"urn:xmpp:xml-element"
-
-
-class Field(data_form.Field):
-    """Field class adding implementation for XML Element"""
-
-
-    def __init__(self, fieldType='text-single', var=None, value=None,
-                       values=None, options=None, label=None, desc=None,
-                       required=False, ext_type=None):
-        """
-        @ext_type(None, unicode): extended type, can be:
-            - xml: field is an XML Element
-            - None: field is a base (XEP-0004) type
-        """
-
-        super(Field, self).__init__(fieldType, var, value, values, options, label, desc,
-                                    required)
-        self.ext_type = ext_type
-
-    def typeCheck(self):
-        if self.ext_type is not None:
-            # we use an extended type
-            if self.fieldType not in (None, 'hidden'):
-                raise ValueError('Invalid main type for a extended type field')
-            if len(self.values) != 1:
-                raise ValueError('extended type must have one and only one value')
-            if self.options:
-                raise ValueError('options must not be set for extented type')
-            if self.ext_type == u'xml':
-                if not isinstance(self.value, domish.Element):
-                    raise ValueError('invalid value, a domish.Element is expected')
-            else:
-                raise ValueError(
-                    'Unknown extended type: {ext_type}'.format(ext_type=self.ext_type))
-        return super(Field, self).typeCheck()
-
-    def toElement(self, asForm=False):
-        if self.ext_type is None:
-            return super(Field, self).toElement(asForm)
-        else:
-            self.typeCheck()
-            field_elt = domish.Element((data_form.NS_X_DATA, 'field'))
-            if self.fieldType:
-                field_elt['type'] = self.fieldType
-
-            if self.var is not None:
-                field_elt['var'] = self.var
-
-            wrapper_elt = field_elt.addElement((NS_XML_ELEMENT, u'wrapper'))
-            wrapper_elt.addChild(self.value)
-
-            if asForm:
-                if self.label is not None:
-                    field_elt['label'] = self.label
-
-                if self.desc is not None:
-                    field_elt.addElement('desc', content=self.desc)
-
-                if self.required:
-                    field_elt.addElement('required')
-
-            return field_elt
-
-    @staticmethod
-    def fromElement(element):
-        field = super(Field, Field).fromElement(element)
-        if element.wrapper and element.wrapper.uri == NS_XML_ELEMENT:
-            field.ext_type = u"xml"
-            field.value = element.wrapper.firstChildElement()
-        return field
-
-
-class XEP_0315(object):
-
-    def __init__(self, host):
-        self.host = host
-        if data_form.Field is not Field:
-            log.debug(u"installing data_form data extension")
-            data_form.Field = Field