From bd01e5719b878ebf9a0b77e253a3bd8d0ffdb8a7 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Wed, 6 Sep 2006 13:28:38 +0000 Subject: [PATCH] INTRODUCING ensure_utf8_string, use it to fix BLOCKER bug for Gajim/Windows (#2392) --- src/common/helpers.py | 8 ++++++++ src/conversation_textview.py | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/common/helpers.py b/src/common/helpers.py index d48c740ca..18c8bab16 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -534,6 +534,14 @@ def decode_string(string): return string +def ensure_utf8_string(string): + '''make sure string is in UTF-8''' + try: + string = decode_string(string).encode('utf-8') + except: + pass + return string + def get_windows_reg_env(varname, default=''): '''asks for paths commonly used but not exposed as ENVs in english Windows 2003 those are: diff --git a/src/conversation_textview.py b/src/conversation_textview.py index 032e19f88..2cf3b58bb 100644 --- a/src/conversation_textview.py +++ b/src/conversation_textview.py @@ -681,9 +681,11 @@ class ConversationTextview: if day_str: format += day_str + ' ' format += '%X' + after_str - # format comes as unicode, because of day_str. - # we convert it to the encoding that we want - tim_format = time.strftime(format, tim).encode('utf-8') + tim_format = time.strftime(format, tim) + # if format comes as unicode because of day_str. + # we convert it to the encoding that we want (and that is utf-8) + tim_format = helpers.ensure_utf8_string(tim_format) + tim_format = tim_format.encode('utf-8') buffer.insert_with_tags_by_name(end_iter, tim_format + ' ', *other_tags_for_time) elif current_print_time == 'sometimes' and kind != 'info':