Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] localized_size: handle UnicodeDecodeError (bug 577862)
Date: Mon, 21 Mar 2016 04:12:07
Message-Id: 1458533501-9015-1-git-send-email-zmedico@gentoo.org
1 Fix localized_size to handle UnicodeDecodeError, which is necessary
2 if the locale data is corrupt or has an unexpected encoding.
3
4 X-Gentoo-bug: 577862
5 X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=577862
6 ---
7 pym/portage/localization.py | 6 +++++-
8 1 file changed, 5 insertions(+), 1 deletion(-)
9
10 diff --git a/pym/portage/localization.py b/pym/portage/localization.py
11 index 2db4b7a..90202fb 100644
12 --- a/pym/portage/localization.py
13 +++ b/pym/portage/localization.py
14 @@ -38,5 +38,9 @@ def localized_size(num_bytes):
15
16 # always round up, so that small files don't end up as '0 KiB'
17 num_kib = math.ceil(num_bytes / 1024)
18 - formatted_num = locale.format('%d', num_kib, grouping=True)
19 + try:
20 + formatted_num = locale.format('%d', num_kib, grouping=True)
21 + except UnicodeDecodeError:
22 + # failure to decode locale data
23 + formatted_num = str(num_kib)
24 return (_unicode_decode(formatted_num, encoding=_encodings['stdio']) + ' KiB')
25 --
26 2.7.2

Replies