1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00

wrapped unicode() and ''.encode('utf8') inside exception

This commit is contained in:
urlbot
2014-08-11 23:32:40 +02:00
parent 9b66386f25
commit 1f3d2577f0

View File

@@ -88,8 +88,16 @@ def chat_write(message, prefix='/say '):
else:
try:
fd = open(fifo_path, 'wb')
# FIXME: somehow, unicode chars can end up inside a <str> message,
# which seems to make both unicode() and ''.encode('utf8') fail.
try:
msg = unicode(prefix) + unicode(message) + '\n'
fd.write(msg.encode('utf8'))
msg.encode('utf8')
except UnicodeDecodeError:
msg = prefix + message + '\n'
fd.write(msg)
fd.close()
except IOError:
logger('err', "couldn't print to fifo " + fifo_path)