aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sebastian@pipping.org>2014-10-29 01:28:56 +0100
committerSebastian Pipping <sebastian@pipping.org>2014-10-29 02:03:47 +0100
commit4a567e9f0a56b24e449f398343c45e99945450d6 (patch)
treed91cd739dfdfba017ef21b0caec86b72e3be16d2
parentFix resuming from Ctrl+Z/SIGTSTP (Gentoo bug #348110) (diff)
downloadelogv-4a567e9f0a56b24e449f398343c45e99945450d6.tar.gz
elogv-4a567e9f0a56b24e449f398343c45e99945450d6.tar.bz2
elogv-4a567e9f0a56b24e449f398343c45e99945450d6.zip
Fix crash for locale without explicit encoding (Gentoo bug #527240)
-rw-r--r--ChangeLog5
-rwxr-xr-xelogv25
2 files changed, 28 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e67ae4d..8ba397c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
# ChangeLog for elogv
-0.7.6.7
+0.7.6.6
+ * Fix crash for locale without explicit encoding,
+ e.g. when running LC_ALL=C elogv (Gentoo bug #527240)
+ * Check locale variable LC_ALL during startup, too.
* Fix resuming from Ctrl-Z/SIGTSTP (Gentoo bug #348110)
0.7.6.5
diff --git a/elogv b/elogv
index a693cf4..a33046b 100755
--- a/elogv
+++ b/elogv
@@ -40,6 +40,8 @@ _LOCALE_CATEGORY_PAIRS = (
(locale.LC_MONETARY, 'LC_MONETARY'),
(locale.LC_NUMERIC, 'LC_NUMERIC'),
(locale.LC_TIME, 'LC_TIME'),
+
+ (locale.LC_ALL, 'LC_ALL'),
)
no_liblzma = False
@@ -79,6 +81,9 @@ except locale.Error:
# Test locale in depth (issue #3), try to be helpful
for category, variable in _LOCALE_CATEGORY_PAIRS:
+ if category == locale.LC_ALL:
+ continue
+
try:
locale.getlocale(category)
except ValueError as e:
@@ -164,7 +169,25 @@ def handle_sig_cont(signum, frame):
def date2str(d):
- u = d.strftime(date_format).decode(locale.getlocale()[1])
+ b = d.strftime(date_format)
+
+ for encoding in (
+ locale.getlocale(locale.LC_TIME)[1],
+ locale.getlocale()[1],
+ sys.getdefaultencoding(),
+ 'utf-8',
+ ):
+ if encoding is None:
+ continue
+
+ try:
+ u = b.decode(encoding)
+ break
+ except UnicodeDecodeError:
+ pass
+ else:
+ raise ValueError('Cannot decode byte stream')
+
try:
u.encode('ascii')
except UnicodeEncodeError: