From 33800064c7f19a5dafe37854743cfe5662c25086 Mon Sep 17 00:00:00 2001 From: bmng-dev Date: Sat, 16 Aug 2014 04:23:30 +0000 Subject: [PATCH] Update l10n to ensure decoding actually works Fix for encoding issue in #706 --- src/l10n.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/l10n.py b/src/l10n.py index d097f2f9..e3e8d07e 100644 --- a/src/l10n.py +++ b/src/l10n.py @@ -30,10 +30,31 @@ if shared.config.has_option('bitmessagesettings', 'timeformat'): try: time.strftime(time_format) except: + logger.exception('Could not format timestamp') time_format = DEFAULT_TIME_FORMAT else: time_format = DEFAULT_TIME_FORMAT +#It seems some systems lie about the encoding they use so we perform +#comprehensive decoding tests +if time_format != DEFAULT_TIME_FORMAT: + try: + #Check day names + for i in xrange(7): + unicode(time.strftime(time_format, (0, 0, 0, 0, 0, 0, i, 0, 0)), encoding) + #Check month names + for i in xrange(1, 13): + unicode(time.strftime(time_format, (0, i, 0, 0, 0, 0, 0, 0, 0)), encoding) + #Check AM/PM + unicode(time.strftime(time_format, (0, 0, 0, 11, 0, 0, 0, 0, 0)), encoding) + unicode(time.strftime(time_format, (0, 0, 0, 13, 0, 0, 0, 0, 0)), encoding) + #Check DST + unicode(time.strftime(time_format, (0, 0, 0, 0, 0, 0, 0, 0, 1)), encoding) + except: + logger.exception('Could not decode locale formatted timestamp') + time_format = DEFAULT_TIME_FORMAT + encoding = DEFAULT_ENCODING + def formatTimestamp(timestamp = None, as_unicode = True): #For some reason some timestamps are strings so we need to sanitize.