fix various encoding crash
This commit is contained in:
parent
78ff11afb1
commit
1ae7bc2f63
3 changed files with 20 additions and 34 deletions
|
@ -527,7 +527,7 @@ class Gui(object):
|
||||||
if not r: # if the room window exists, we don't recreate it.
|
if not r: # if the room window exists, we don't recreate it.
|
||||||
self.join_room(room, nick)
|
self.join_room(room, nick)
|
||||||
else:
|
else:
|
||||||
r.own_nick = nick
|
# r.own_nick = nick
|
||||||
r.users = []
|
r.users = []
|
||||||
|
|
||||||
def command_bookmark(self, args):
|
def command_bookmark(self, args):
|
||||||
|
|
47
src/room.py
47
src/room.py
|
@ -66,18 +66,23 @@ class Room(object):
|
||||||
"""
|
"""
|
||||||
user = self.get_user_by_name(nickname) if nickname is not None else None
|
user = self.get_user_by_name(nickname) if nickname is not None else None
|
||||||
time = time if time is not None else datetime.now()
|
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
|
color = None
|
||||||
if nickname is not None:
|
if nickname is not None:
|
||||||
self.set_color_state(12)
|
self.set_color_state(12)
|
||||||
else:
|
else:
|
||||||
color = 8
|
color = 8
|
||||||
if nickname != self.own_nick and self.joined and nickname is not None: # do the highlight
|
if nickname != self.own_nick and self.joined and nickname is not None: # do the highlight
|
||||||
if self.own_nick in txt:
|
try:
|
||||||
self.set_color_state(13)
|
if self.own_nick.encode('utf-8') in txt:
|
||||||
color = 3
|
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:
|
else:
|
||||||
highlight_words = config.get('highlight_on', '').split(':')
|
highlight_words = config.get('highlight_on', '').split(':')
|
||||||
for word in highlight_words:
|
for word in highlight_words:
|
||||||
|
@ -87,32 +92,6 @@ class Room(object):
|
||||||
break
|
break
|
||||||
self.messages.append(Message(txt, time, nickname, user, color))
|
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):
|
def get_user_by_name(self, nick):
|
||||||
for user in self.users:
|
for user in self.users:
|
||||||
if user.nick == nick.encode('utf-8'):
|
if user.nick == nick.encode('utf-8'):
|
||||||
|
@ -120,5 +99,9 @@ class Room(object):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def set_color_state(self, color):
|
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:
|
if self.color_state < color or color == 11:
|
||||||
self.color_state = color
|
self.color_state = color
|
||||||
|
|
|
@ -429,7 +429,10 @@ class Input(Win):
|
||||||
self.hit_list.append(self.hit_list.pop(0)) # rotate list
|
self.hit_list.append(self.hit_list.pop(0)) # rotate list
|
||||||
end = len(begin) + len(after)
|
end = len(begin) + len(after)
|
||||||
x -= end
|
x -= end
|
||||||
self.win.move(y, x)
|
try:
|
||||||
|
self.win.move(y, x)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
# remove begin from the line
|
# remove begin from the line
|
||||||
self.win.clrtoeol()
|
self.win.clrtoeol()
|
||||||
self.text = self.text[:-end]
|
self.text = self.text[:-end]
|
||||||
|
|
Loading…
Reference in a new issue