Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2019-11-03 16:41:50 +0300
committerPhilipp Hörist <philipp@hoerist.com>2019-11-04 00:08:31 +0300
commit1a844d5042f90e42f577dc57fa161cd801ca145f (patch)
tree28352c6762acad2d5d1ac4623cf417c99ede94d5 /nbxmpp/modules
parenta335c9ec46651e029703a97a3d5ec2d46f68a077 (diff)
Refactor XHTML code
- setXHTML expects now a body Node - getXHTML returns the html Node - Add XHTMLData struct
Diffstat (limited to 'nbxmpp/modules')
-rw-r--r--nbxmpp/modules/message.py14
-rw-r--r--nbxmpp/modules/misc.py14
2 files changed, 27 insertions, 1 deletions
diff --git a/nbxmpp/modules/message.py b/nbxmpp/modules/message.py
index 27ef286..8a708eb 100644
--- a/nbxmpp/modules/message.py
+++ b/nbxmpp/modules/message.py
@@ -19,8 +19,10 @@ import logging
from nbxmpp.protocol import NodeProcessed
from nbxmpp.protocol import NS_DATA
+from nbxmpp.protocol import NS_XHTML
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import StanzaIDData
+from nbxmpp.structs import XHTMLData
from nbxmpp.util import error_factory
from nbxmpp.const import MessageType
@@ -79,7 +81,17 @@ class BaseMessage:
forms = stanza.getTags('x', namespace=NS_DATA)
if forms:
properties.forms = forms
- properties.xhtml = stanza.getXHTML()
+
+ xhtml = stanza.getXHTML()
+ if xhtml is None:
+ return
+
+ if xhtml.getTag('body', namespace=NS_XHTML) is None:
+ log.warning('xhtml without body found')
+ log.warning(stanza)
+ return
+
+ properties.xhtml = XHTMLData(xhtml)
@staticmethod
def _parse_type(stanza):
diff --git a/nbxmpp/modules/misc.py b/nbxmpp/modules/misc.py
index 4fdbf4e..02efa8c 100644
--- a/nbxmpp/modules/misc.py
+++ b/nbxmpp/modules/misc.py
@@ -22,6 +22,7 @@ from nbxmpp.protocol import NS_FORWARD
from nbxmpp.protocol import NS_MUC_USER
from nbxmpp.protocol import NS_MAM_1
from nbxmpp.protocol import NS_MAM_2
+from nbxmpp.protocol import NS_XHTML
from nbxmpp.protocol import NodeProcessed
from nbxmpp.protocol import InvalidFrom
from nbxmpp.protocol import InvalidStanza
@@ -118,3 +119,16 @@ def unwrap_mam(stanza, own_jid):
archive=stanza.getFrom(),
namespace=result.getNamespace(),
timestamp=delay_timestamp)
+
+
+def build_xhtml_body(xhtml, xmllang=None):
+ try:
+ if xmllang is not None:
+ body = '<body xmlns="%s" xml:lang="%s">%s</body>' % (
+ NS_XHTML, xmllang, xhtml)
+ else:
+ body = '<body xmlns="%s">%s</body>' % (NS_XHTML, xhtml)
+ except Exception as error:
+ log.error('Error while building xhtml node: %s', error)
+ return None
+ return body