Fix localized_size to handle UnicodeDecodeError, which is necessary if the locale data is corrupt or has an unexpected encoding.
X-Gentoo-bug: 577862 X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=577862 --- pym/portage/localization.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pym/portage/localization.py b/pym/portage/localization.py index 2db4b7a..90202fb 100644 --- a/pym/portage/localization.py +++ b/pym/portage/localization.py @@ -38,5 +38,9 @@ def localized_size(num_bytes): # always round up, so that small files don't end up as '0 KiB' num_kib = math.ceil(num_bytes / 1024) - formatted_num = locale.format('%d', num_kib, grouping=True) + try: + formatted_num = locale.format('%d', num_kib, grouping=True) + except UnicodeDecodeError: + # failure to decode locale data + formatted_num = str(num_kib) return (_unicode_decode(formatted_num, encoding=_encodings['stdio']) + ' KiB') -- 2.7.2