diff options
-rw-r--r-- | sunshine/channel/text.py | 2 | ||||
-rw-r--r-- | sunshine/connection.py | 18 | ||||
-rw-r--r-- | sunshine/util/decorator.py | 9 |
3 files changed, 22 insertions, 7 deletions
diff --git a/sunshine/channel/text.py b/sunshine/channel/text.py index 15ff76c..34c2269 100644 --- a/sunshine/channel/text.py +++ b/sunshine/channel/text.py @@ -46,7 +46,7 @@ class SunshineTextChannel(telepathy.server.ChannelTypeText): def Send(self, message_type, text): if message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: logger.info("Sending message to %s, id %s, body: '%s'" % (str(self.handle.name), str(self.handle.id), unicode(text))) - msg = text.encode('windows-1250') + msg = text.decode('UTF-8').encode('windows-1250', 'replace') self.conn.gadu_client.sendTo(int(self.handle.name), str(text), str(msg)) else: raise telepathy.NotImplemented("Unhandled message type") diff --git a/sunshine/connection.py b/sunshine/connection.py index 7734c2c..bcf6ee1 100644 --- a/sunshine/connection.py +++ b/sunshine/connection.py @@ -42,7 +42,7 @@ from sunshine.handle import SunshineHandleFactory from sunshine.capabilities import SunshineCapabilities from sunshine.contacts import SunshineContacts from sunshine.channel_manager import SunshineChannelManager -from sunshine.util.decorator import async +from sunshine.util.decorator import async, stripHTML __all__ = ['SunshineConfig', 'GaduClientFactory', 'SunshineConnection'] @@ -272,8 +272,7 @@ class SunshineConnection(telepathy.server.Connection, self.profile.addGroup(g) logger.info("We have %s contacts in file." % (self.configfile.get_contacts_count())) - - + self.factory = GaduClientFactory(self.profile) self._channel_manager = SunshineChannelManager(self) @@ -616,7 +615,11 @@ class SunshineConnection(telepathy.server.Connection, logger.info("Msg from %r %d %d [%r] [%r]" % (msg.sender, msg.content.offset_plain, msg.content.offset_attrs, msg.content.plain_message, msg.content.html_message)) - message = "%s" % unicode(str(msg.content.plain_message).replace('\x00', '').replace('\r', '').decode('windows-1250').encode('utf-8')) + #we need to strip all html tags + text = stripHTML(msg.content.html_message) + + #message = "%s" % unicode(str(msg.content.plain_message).replace('\x00', '').replace('\r', '').decode('windows-1250').encode('utf-8')) + message = "%s" % unicode(str(text).replace('\x00', '').replace('\r', '')) #print 'message: ', message channel.Received(self._recv_id, timestamp, ahandle, type, 0, message) self._recv_id += 1 @@ -643,7 +646,12 @@ class SunshineConnection(telepathy.server.Connection, handle, False) channel = self._channel_manager.channel_for_props(props, signal=True, conversation=None) - message = "%s" % unicode(str(msg.content.plain_message).replace('\x00', '').replace('\r', '').decode('windows-1250').encode('utf-8')) + + #we need to strip all html tags + text = stripHTML(msg.content.html_message).replace('<', '<').replace('>', '>') + + message = "%s" % unicode(str(text).replace('\x00', '').replace('\r', '')) + #message = "%s" % unicode(str(msg.content.plain_message).replace('\x00', '').replace('\r', '').decode('windows-1250').encode('utf-8')) #print 'message: ', message channel.Received(self._recv_id, timestamp, handle, type, 0, message) self._recv_id += 1 diff --git a/sunshine/util/decorator.py b/sunshine/util/decorator.py index 250e2d2..fe53b33 100644 --- a/sunshine/util/decorator.py +++ b/sunshine/util/decorator.py @@ -25,9 +25,16 @@ import time import gobject -__all__ = ['decorator', 'rw_property', 'deprecated', 'unstable', 'async', +import re + +__all__ = ['stripHTML', 'decorator', 'rw_property', 'deprecated', 'unstable', 'async', 'throttled'] +def stripHTML(string): + "Replacing HTML-like tags from text." + p = re.compile(r'<.*?>') + return p.sub('', string) + def decorator(function): """decorator to be used on decorators, it preserves the docstring and |