Commit a64dd021 authored by Link Mauve's avatar Link Mauve

Remove the dependency on poezio from xhtml.py

parent 9240bc39
...@@ -65,7 +65,7 @@ Options defined ...@@ -65,7 +65,7 @@ Options defined
""" """
from plugin import BasePlugin from plugin import BasePlugin
from xhtml import clean_text, get_body_from_message_stanza from xhtml import get_body_from_message_stanza
from timed_events import DelayedEvent from timed_events import DelayedEvent
import shlex import shlex
...@@ -88,7 +88,7 @@ class Plugin(BasePlugin): ...@@ -88,7 +88,7 @@ class Plugin(BasePlugin):
self.do_notify(message, fro) self.do_notify(message, fro)
def do_notify(self, message, fro): def do_notify(self, message, fro):
body = clean_text(get_body_from_message_stanza(message)) body = get_body_from_message_stanza(message, use_xhtml=False)
if not body: if not body:
return return
command_str = self.config.get('command', '').strip() command_str = self.config.get('command', '').strip()
......
...@@ -2941,7 +2941,8 @@ class Core(object): ...@@ -2941,7 +2941,8 @@ class Core(object):
elif message['type'] == 'headline' and message['body']: elif message['type'] == 'headline' and message['body']:
return self.information('%s says: %s' % (message['from'], message['body']), 'Headline') return self.information('%s says: %s' % (message['from'], message['body']), 'Headline')
body = xhtml.get_body_from_message_stanza(message) use_xhtml = config.get('enable_xhtml_im', 'true') == 'true'
body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
if not body: if not body:
return return
...@@ -2983,7 +2984,7 @@ class Core(object): ...@@ -2983,7 +2984,7 @@ class Core(object):
self.events.trigger('conversation_msg', message, conversation) self.events.trigger('conversation_msg', message, conversation)
if not message['body']: if not message['body']:
return return
body = xhtml.get_body_from_message_stanza(message) body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
delayed, date = common.find_delayed_tag(message) delayed, date = common.find_delayed_tag(message)
def try_modify(): def try_modify():
...@@ -3199,7 +3200,8 @@ class Core(object): ...@@ -3199,7 +3200,8 @@ class Core(object):
return return
self.events.trigger('muc_msg', message, tab) self.events.trigger('muc_msg', message, tab)
body = xhtml.get_body_from_message_stanza(message) use_xhtml = config.get('enable_xhtml_im', 'true') == 'true'
body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
if not body: if not body:
return return
...@@ -3246,7 +3248,8 @@ class Core(object): ...@@ -3246,7 +3248,8 @@ class Core(object):
return self.on_groupchat_message(message) return self.on_groupchat_message(message)
room_from = jid.bare room_from = jid.bare
body = xhtml.get_body_from_message_stanza(message) use_xhtml = config.get('enable_xhtml_im', 'true') == 'true'
body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
tab = self.get_tab_by_name(jid.full, tabs.PrivateTab) # get the tab with the private conversation tab = self.get_tab_by_name(jid.full, tabs.PrivateTab) # get the tab with the private conversation
ignore = config.get_by_tabname('ignore_private', 'false', ignore = config.get_by_tabname('ignore_private', 'false',
room_from).lower() == 'true' room_from).lower() == 'true'
...@@ -3260,7 +3263,7 @@ class Core(object): ...@@ -3260,7 +3263,7 @@ class Core(object):
self.xmpp.send_message(mto=jid.full, mbody=msg, mtype='chat') self.xmpp.send_message(mto=jid.full, mbody=msg, mtype='chat')
return return
self.events.trigger('private_msg', message, tab) self.events.trigger('private_msg', message, tab)
body = xhtml.get_body_from_message_stanza(message) body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
if not body or not tab: if not body or not tab:
return return
replaced_id = message['replace']['id'] replaced_id = message['replace']['id']
......
...@@ -20,9 +20,6 @@ from io import BytesIO ...@@ -20,9 +20,6 @@ from io import BytesIO
from xml import sax from xml import sax
from xml.sax import saxutils from xml.sax import saxutils
from config import config
import logging
digits = '0123456789' # never trust the modules digits = '0123456789' # never trust the modules
XHTML_NS = 'http://www.w3.org/1999/xhtml' XHTML_NS = 'http://www.w3.org/1999/xhtml'
...@@ -184,13 +181,13 @@ xhtml_attr_re = re.compile(r'\x19-?\d[^}]*}|\x19[buaio]') ...@@ -184,13 +181,13 @@ xhtml_attr_re = re.compile(r'\x19-?\d[^}]*}|\x19[buaio]')
xhtml_simple_attr_re = re.compile(r'\x19\d') xhtml_simple_attr_re = re.compile(r'\x19\d')
def get_body_from_message_stanza(message): def get_body_from_message_stanza(message, use_xhtml=False):
""" """
Returns a string with xhtml markups converted to Returns a string with xhtml markups converted to
poezio colors if there's an xhtml_im element, or poezio colors if there's an xhtml_im element, or
the body (without any color) otherwise the body (without any color) otherwise
""" """
if config.get('enable_xhtml_im', 'true') == 'true': if use_xhtml:
xhtml = message['html'].xml xhtml = message['html'].xml
xhtml_body = xhtml.find('{http://www.w3.org/1999/xhtml}body') xhtml_body = xhtml.find('{http://www.w3.org/1999/xhtml}body')
if xhtml_body: if xhtml_body:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment