From f5035854dcaef6112ff71a111d071e93708bf082 Mon Sep 17 00:00:00 2001 From: Philippe Crama Date: Fri, 21 Jan 2011 15:17:03 +0100 Subject: Avoid debugging output charset problems crashing skyped.py When using irssi in an LC_CTYPE=ISO-8859-1 terminal (thus /set charset iso-8859-1 for irssi, set charset iso-8859-1 for bitlbee and no recode_out_default_charset set for irssi) and skyped.py in a Windows console window (CP1252?), sending a message with a é (the character, not the HTML entity) crashes the server because in its debugging output it tries to print the UTF-8 equivalent intepreted as CP1252 code points. I do not think that the "if options.log: ..." code just below the patch needs the same treatment as the worst that can happen is that some messages in the log file will be garbled. Since I do not use/test that code path, I didn't touch it. --- skype/skyped.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/skype/skyped.py b/skype/skyped.py index bfb09d12..8f69e2ee 100644 --- a/skype/skyped.py +++ b/skype/skyped.py @@ -198,7 +198,17 @@ def dprint(msg): now = strftime("%Y-%m-%d %H:%M:%S") if options.debug: - print now + ": " + msg + try: + print now + ": " + msg + except Exception, s: + try: + sanitized = msg.encode("ascii", "backslashreplace") + except Error, s: + try: + sanitized = "hex [" + msg.encode("hex") + "]" + except Error, s: + sanitized = "[unable to print debug message]" + print now + "~=" + sanitized sys.stdout.flush() if options.log: sock = open(options.log, "a") -- cgit v1.2.3