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.
This commit is contained in:
Goffi 2019-09-25 08:56:41 +02:00
commit 76aadbb3fb

View file

@ -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 @@ class PubsubSchema(object):
)
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 @@ class PubsubSchema(object):
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 @@ class PubsubSchema(object):
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():