public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] localized_size: handle UnicodeDecodeError (bug 577862)
@ 2016-03-21  4:11 Zac Medico
  2016-03-21  4:17 ` Brian Dolbec
  0 siblings, 1 reply; 2+ messages in thread
From: Zac Medico @ 2016-03-21  4:11 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] localized_size: handle UnicodeDecodeError (bug 577862)
  2016-03-21  4:11 [gentoo-portage-dev] [PATCH] localized_size: handle UnicodeDecodeError (bug 577862) Zac Medico
@ 2016-03-21  4:17 ` Brian Dolbec
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Dolbec @ 2016-03-21  4:17 UTC (permalink / raw
  To: gentoo-portage-dev

On Sun, 20 Mar 2016 21:11:41 -0700
Zac Medico <zmedico@gentoo.org> wrote:

> 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')


looks good.  Also if you haven't looked at the forum thread again.

Portage did not fail when he set python 2.7 as the active one.  So it
is 3.4 only that is failing for him (just those 2 installed).

-- 
Brian Dolbec <dolsen>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-21  4:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-21  4:11 [gentoo-portage-dev] [PATCH] localized_size: handle UnicodeDecodeError (bug 577862) Zac Medico
2016-03-21  4:17 ` Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox