From efc2ebe2c4eaabd061139a16efb403368f9f82e0 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 26 Nov 2016 17:57:51 +0000 Subject: XHTML-IM: Check for the existence of elements manually. This fixes part of #3186, slixmpp was previously adding a new XHTML-IM payload whenever we just wanted to check for its presence. Also makes the code abort faster in the common case where no XHTML-IM element is present. --- poezio/xhtml.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'poezio/xhtml.py') diff --git a/poezio/xhtml.py b/poezio/xhtml.py index 0b774494..6ab48733 100644 --- a/poezio/xhtml.py +++ b/poezio/xhtml.py @@ -195,15 +195,18 @@ def get_body_from_message_stanza(message, use_xhtml=False, poezio colors if there's an xhtml_im element, or the body (without any color) otherwise """ - if use_xhtml: - xhtml = message['html'].xml - xhtml_body = xhtml.find('{http://www.w3.org/1999/xhtml}body') - if xhtml_body: - content = xhtml_to_poezio_colors(xhtml_body, tmp_dir=tmp_dir, - extract_images=extract_images) - content = content if content else message['body'] - return content or " " - return message['body'] + if not use_xhtml: + return message['body'] + xhtml = message.xml.find('{http://jabber.org/protocol/xhtml-im}html') + if not xhtml: + return message['body'] + xhtml_body = xhtml.find('{http://www.w3.org/1999/xhtml}body') + if not xhtml_body: + return message['body'] + content = xhtml_to_poezio_colors(xhtml_body, tmp_dir=tmp_dir, + extract_images=extract_images) + content = content if content else message['body'] + return content or " " def ncurses_color_to_html(color): """ -- cgit v1.2.3