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 |