diff sat/plugins/plugin_exp_pubsub_schema.py @ 3040:fee60f17ebac

jp: jp asyncio port: /!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\ This patch implements the port of jp to asyncio, so it is now correctly using the bridge asynchronously, and it can be used with bridges like `pb`. This also simplify the code, notably for things which were previously implemented with many callbacks (like pagination with RSM). During the process, some behaviours have been modified/fixed, in jp and backends, check diff for details.
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:56:41 +0200
parents ab2696e34d29
children 68d423f4fb55
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_pubsub_schema.py	Wed Sep 25 08:53:38 2019 +0200
+++ b/sat/plugins/plugin_exp_pubsub_schema.py	Wed Sep 25 08:56:41 2019 +0200
@@ -18,11 +18,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from collections import Iterable
-import copy
 import itertools
 from zope.interface import implementer
 from twisted.words.protocols.jabber import jid
 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
+from twisted.words.xish import domish
 from twisted.internet import defer
 from wokkel import disco, iwokkel
 from wokkel import data_form
@@ -174,7 +174,16 @@
                 )
         elif isinstance(schema, data_form.Form):
             if copy_form:
-                schema = copy.deepcopy(schema)
+                # XXX: we don't use deepcopy as it will do an infinite loop if a
+                #      domish.Element is present in the form fields (happens for
+                #      XEP-0315 data forms XML Element)
+                schema = data_form.Form(
+                    formType = schema.formType,
+                    title = schema.title,
+                    instructions = schema.instructions[:],
+                    formNamespace = schema.formNamespace,
+                    fields = schema.fieldList,
+                )
             defer.returnValue(schema)
 
         try:
@@ -394,6 +403,18 @@
                 if not values_list:
                     # if values don't map to allowed values, we use default ones
                     values_list = field.values
+            elif field.ext_type == 'xml':
+                # FIXME: XML elements are not handled correctly, we need to know if we
+                #        actual XML/XHTML, or text to escape
+                for idx, value in enumerate(values_list[:]):
+                    if not isinstance(value, domish.Element):
+                        if field.value and field.value.uri == C.NS_XHTML:
+                            div_elt = domish.Element((C.NS_XHTML, 'div'))
+                            div_elt.addContent(str(value))
+                            values_list[idx] = div_elt
+                    else:
+                        raise NotImplementedError
+
             field.values = values_list
 
         yield self._p.sendItem(
@@ -546,9 +567,7 @@
             form = data_form.findForm(item_elt, form_ns)
             if form is None:
                 log.warning(
-                    _(
-                        "Can't parse previous item, update ignored: data form not found"
-                    ).format(reason=e)
+                    _("Can't parse previous item, update ignored: data form not found")
                 )
             else:
                 for name, field in form.fields.items():