fix various encoding crash

This commit is contained in:
louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 2010-06-13 00:45:45 +00:00
parent 78ff11afb1
commit 1ae7bc2f63
3 changed files with 20 additions and 34 deletions

View file

@ -527,7 +527,7 @@ class Gui(object):
if not r: # if the room window exists, we don't recreate it.
self.join_room(room, nick)
else:
r.own_nick = nick
# r.own_nick = nick
r.users = []
def command_bookmark(self, args):

View file

@ -66,18 +66,23 @@ class Room(object):
"""
user = self.get_user_by_name(nickname) if nickname is not None else None
time = time if time is not None else datetime.now()
from common import debug
# debug("add_message: %s, %s, %s, %s" % (str(txt), str(time), str(nickname), str(user)))
color = None
if nickname is not None:
self.set_color_state(12)
else:
color = 8
if nickname != self.own_nick and self.joined and nickname is not None: # do the highlight
try:
if self.own_nick.encode('utf-8') in txt:
self.set_color_state(13)
color = 3
except UnicodeDecodeError:
try:
if self.own_nick in txt:
self.set_color_state(13)
color = 3
except:
pass
else:
highlight_words = config.get('highlight_on', '').split(':')
for word in highlight_words:
@ -87,32 +92,6 @@ class Room(object):
break
self.messages.append(Message(txt, time, nickname, user, color))
# def add_message(nick, msg, date=None)
# TODO: limit the message kept in memory (configurable)
# if not msg:
# logger.info('msg is None..., %s' % (nick))
# return
# self.lines.append((date, nick.encode('utf-8'),
# msg.encode('utf-8'), color))
# user = self.get_user_by_name(nick)
# if user:
# user.set_last_talked(date)
# if self.joined: # log only NEW messages, not the history received on join
# logger.message(self.name, nick.encode('utf-8'), msg.encode('utf-8'))
# return color
# def add_info(self, info, date=None):
# """ info, like join/quit/status messages"""
# if not date:
# date = datetime.now()
# try:
# self.lines.append((date, info.encode('utf-8')))
# return info.encode('utf-8')
# except:
# self.lines.append((date, info))
# return info
def get_user_by_name(self, nick):
for user in self.users:
if user.nick == nick.encode('utf-8'):
@ -120,5 +99,9 @@ class Room(object):
return None
def set_color_state(self, color):
"""
Set the color that will be used to display the room's
number in the RoomInfo window
"""
if self.color_state < color or color == 11:
self.color_state = color

View file

@ -429,7 +429,10 @@ class Input(Win):
self.hit_list.append(self.hit_list.pop(0)) # rotate list
end = len(begin) + len(after)
x -= end
try:
self.win.move(y, x)
except:
pass
# remove begin from the line
self.win.clrtoeol()
self.text = self.text[:-end]