make decoding less recursive
This commit is contained in:
parent
21285882c9
commit
e46e42d4b9
12
irc.py
12
irc.py
|
@ -9,12 +9,12 @@ import Queue
|
||||||
queue = Queue.Queue
|
queue = Queue.Queue
|
||||||
|
|
||||||
def decode(txt, codecs=['utf-8', 'iso-8859-1', 'shift_jis', 'cp1252']):
|
def decode(txt, codecs=['utf-8', 'iso-8859-1', 'shift_jis', 'cp1252']):
|
||||||
if len(codecs) == 0:
|
for codec in ('utf-8', 'iso-8859-1', 'shift_jis', 'cp1252'):
|
||||||
return txt.decode('utf-8', 'ignore')
|
try:
|
||||||
try:
|
return txt.decode(codec)
|
||||||
return txt.decode(codecs[0])
|
except UnicodeDecodeError:
|
||||||
except UnicodeDecodeError:
|
continue
|
||||||
return decode(txt, codecs[1:])
|
return txt.decode('utf-8', 'ignore')
|
||||||
|
|
||||||
class crlf_tcp(asynchat.async_chat):
|
class crlf_tcp(asynchat.async_chat):
|
||||||
"Handles tcp connections that consist of utf-8 lines ending with crlf"
|
"Handles tcp connections that consist of utf-8 lines ending with crlf"
|
||||||
|
|
Loading…
Reference in New Issue