diff options
author | Sebastian Pipping <sebastian@pipping.org> | 2014-10-25 02:57:00 +0200 |
---|---|---|
committer | Sebastian Pipping <sebastian@pipping.org> | 2014-10-25 03:00:22 +0200 |
commit | c5d8333994b782733954e5f76143e00b6a9b7682 (patch) | |
tree | 45fb790911e0aede3d412e3361d00ae551532b53 | |
parent | Release 0.7.6.2 (diff) | |
download | elogv-c5d8333994b782733954e5f76143e00b6a9b7682.tar.gz elogv-c5d8333994b782733954e5f76143e00b6a9b7682.tar.bz2 elogv-c5d8333994b782733954e5f76143e00b6a9b7682.zip |
Prevent crash with LC_TIME=ja_JP.UTF-8 (Gentoo bug #464962)
-rwxr-xr-x | elogv | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -1,4 +1,5 @@ #!/usr/bin/python +# -*- coding: UTF-8 -*- # Author: Luca Marturana (luca89) <lucamarturana@gmail.com> # This program is free software; you can redistribute it and/or modify @@ -99,6 +100,16 @@ class CannotOpenElogdir(Exception): def __init__(self): pass +def date2str(d): + u = d.strftime(date_format).decode(locale.getlocale()[1]) + try: + u.encode('ascii') + except UnicodeEncodeError: + # Prevent crash locales like ja_JP.UTF-8, e.g. "2014年10月24日" + # https://bugs.gentoo.org/show_bug.cgi?id=464962 + u = u.encode('ascii', errors='replace').decode('ascii') + return u + # Main class (called with curses.wrapper later) class ElogViewer: def __init__(self, screen): @@ -287,13 +298,13 @@ class ElogViewer: class_char, curses.A_BOLD + curses.color_pair(prev_pkg[CLASS])) self.file_pad.addstr(prev_usel,3, - list_format % (prev_pkg[CAT], prev_pkg[PN], prev_pkg[DATE].strftime(date_format) ), + list_format % (prev_pkg[CAT], prev_pkg[PN], date2str(prev_pkg[DATE]) ), curses.color_pair(normal)) self.file_pad.addstr(self.usel,1, class_char, curses.A_BOLD + curses.color_pair(pkg[CLASS])) self.file_pad.addstr(self.usel,3, - list_format % (pkg[CAT], pkg[PN], pkg[DATE].strftime(date_format) ), + list_format % (pkg[CAT], pkg[PN], date2str(pkg[DATE]) ), curses.color_pair(selected)) first = self.pposy @@ -420,7 +431,7 @@ class ElogViewer: class_char, curses.A_BOLD + curses.color_pair(pkg[CLASS])) self.file_pad.addstr(i,3, - list_format % (pkg[CAT], pkg[PN], pkg[DATE].strftime(date_format) ), + list_format % (pkg[CAT], pkg[PN], date2str(pkg[DATE]) ), curses.color_pair(cp)) def get_class(self,filepath): |