Remove the dependency on poezio from xhtml.py

This commit is contained in:
Emmanuel Gil Peyrot 2014-02-22 01:11:57 +01:00
parent 9240bc3964
commit a64dd02118
3 changed files with 12 additions and 12 deletions

View file

@ -65,7 +65,7 @@ Options defined
"""
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
import shlex
@ -88,7 +88,7 @@ class Plugin(BasePlugin):
self.do_notify(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:
return
command_str = self.config.get('command', '').strip()

View file

@ -2941,7 +2941,8 @@ class Core(object):
elif message['type'] == 'headline' and message['body']:
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:
return
@ -2983,7 +2984,7 @@ class Core(object):
self.events.trigger('conversation_msg', message, conversation)
if not message['body']:
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)
def try_modify():
@ -3199,7 +3200,8 @@ class Core(object):
return
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:
return
@ -3246,7 +3248,8 @@ class Core(object):
return self.on_groupchat_message(message)
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
ignore = config.get_by_tabname('ignore_private', 'false',
room_from).lower() == 'true'
@ -3260,7 +3263,7 @@ class Core(object):
self.xmpp.send_message(mto=jid.full, mbody=msg, mtype='chat')
return
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:
return
replaced_id = message['replace']['id']

View file

@ -20,9 +20,6 @@ from io import BytesIO
from xml import sax
from xml.sax import saxutils
from config import config
import logging
digits = '0123456789' # never trust the modules
XHTML_NS = 'http://www.w3.org/1999/xhtml'
@ -184,13 +181,13 @@ xhtml_attr_re = re.compile(r'\x19-?\d[^}]*}|\x19[buaio]')
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
poezio colors if there's an xhtml_im element, or
the body (without any color) otherwise
"""
if config.get('enable_xhtml_im', 'true') == 'true':
if use_xhtml:
xhtml = message['html'].xml
xhtml_body = xhtml.find('{http://www.w3.org/1999/xhtml}body')
if xhtml_body: