ensure that messages are encoded in utf-8 during calls to safe()

master
mutantmonkey 2011-10-22 21:12:54 -04:00
parent 27ebfea407
commit d9a8cb9a12
1 changed files with 3 additions and 1 deletions

4
irc.py
View File

@ -101,7 +101,7 @@ class Bot(asynchat.async_chat):
if use_ssl:
sock = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLSv1)
# FIXME: ssl module does not appear to work properly with nonblocking sockets
sock.setblocking(0)
#sock.setblocking(0)
self.set_socket(sock)
def handle_connect(self):
@ -175,6 +175,8 @@ class Bot(asynchat.async_chat):
return
def safe(input):
if type(input) == str:
input = input.encode('utf-8')
input = input.replace(b'\n', b'')
return input.replace(b'\r', b'')
self.__write((b'PRIVMSG', safe(recipient)), safe(text))