Add non UTF-8 message support into nemuspeak

This commit is contained in:
Némunaire 2012-06-16 22:47:35 +02:00
parent 14dd8874eb
commit 04788fbc9b

View File

@ -168,10 +168,17 @@ class Server:
readbuffer = "" #Here we store all the messages from server readbuffer = "" #Here we store all the messages from server
while 1: while 1:
try: try:
readbuffer = readbuffer + self.s.recv(1024).decode() #recieve server messages raw = self.s.recv(1024) #recieve server messages
data = raw.decode()
if not data:
break
except UnicodeDecodeError: except UnicodeDecodeError:
print ("ERREUR de décodage unicode") try:
continue data = raw.decode("utf-8", "replace")
except UnicodeDecodeError:
print ("\033[1;31mERROR:\033[0m while decoding of: %s"%data)
continue
readbuffer = readbuffer + data
temp = readbuffer.split("\n") temp = readbuffer.split("\n")
readbuffer = temp.pop( ) readbuffer = temp.pop( )