From e46e42d4b9da1b902bd1e8d1236b10bdeda9f3b4 Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Fri, 17 Apr 2009 17:40:53 -0600 Subject: [PATCH] make decoding less recursive --- irc.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/irc.py b/irc.py index 56588f6..a5af647 100644 --- a/irc.py +++ b/irc.py @@ -9,12 +9,12 @@ import Queue queue = Queue.Queue def decode(txt, codecs=['utf-8', 'iso-8859-1', 'shift_jis', 'cp1252']): - if len(codecs) == 0: - return txt.decode('utf-8', 'ignore') - try: - return txt.decode(codecs[0]) - except UnicodeDecodeError: - return decode(txt, codecs[1:]) + for codec in ('utf-8', 'iso-8859-1', 'shift_jis', 'cp1252'): + try: + return txt.decode(codec) + except UnicodeDecodeError: + continue + return txt.decode('utf-8', 'ignore') class crlf_tcp(asynchat.async_chat): "Handles tcp connections that consist of utf-8 lines ending with crlf"