public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] UserQuery: handle unicode (bug 573386)
@ 2016-02-01 17:39 Zac Medico
  2016-02-02  0:48 ` Brian Dolbec
  0 siblings, 1 reply; 2+ messages in thread
From: Zac Medico @ 2016-02-01 17:39 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Handle UnicodeDecodeError from the input function in python3, and from
comparisons with unicode literals in python2.

X-Gentoo-Bug:     573386
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=573386
---
 pym/_emerge/UserQuery.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/pym/_emerge/UserQuery.py b/pym/_emerge/UserQuery.py
index c866a0d..f8fce77 100644
--- a/pym/_emerge/UserQuery.py
+++ b/pym/_emerge/UserQuery.py
@@ -1,11 +1,12 @@
-# Copyright 1999-2014 Gentoo Foundation
+# Copyright 1999-2016 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 import signal
 import sys
 
+from portage import _unicode_decode
 from portage.output import bold, create_color_func
 
 
@@ -47,18 +48,24 @@ class UserQuery(object):
 		elif colours is None:
 			colours=[bold]
 		colours=(colours*len(responses))[:len(responses)]
+		responses = [_unicode_decode(x) for x in responses]
 		if "--alert" in self.myopts:
 			prompt = '\a' + prompt
 		print(bold(prompt), end=' ')
 		try:
 			while True:
 				if sys.hexversion >= 0x3000000:
-					response=input("["+"/".join([colours[i](responses[i])
-								  for i in range(len(responses))])+"] ")
+					try:
+						response = input("[%s] " %
+							"/".join([colours[i](responses[i])
+							for i in range(len(responses))]))
+					except UnicodeDecodeError:
+						response = None
 				else:
 					response=raw_input("["+"/".join([colours[i](responses[i])
 									  for i in range(len(responses))])+"] ")
-				if response or not enter_invalid:
+					response = _unicode_decode(response)
+				if response or (not enter_invalid and response == ''):
 					for key in responses:
 						# An empty response will match the
 						# first value in responses.
-- 
2.4.10



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

* Re: [gentoo-portage-dev] [PATCH] UserQuery: handle unicode (bug 573386)
  2016-02-01 17:39 [gentoo-portage-dev] [PATCH] UserQuery: handle unicode (bug 573386) Zac Medico
@ 2016-02-02  0:48 ` Brian Dolbec
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Dolbec @ 2016-02-02  0:48 UTC (permalink / raw
  To: gentoo-portage-dev

On Mon,  1 Feb 2016 09:39:16 -0800
Zac Medico <zmedico@gentoo.org> wrote:

> Handle UnicodeDecodeError from the input function in python3, and from
> comparisons with unicode literals in python2.
> 
> X-Gentoo-Bug:     573386
> X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=573386
> ---
>  pym/_emerge/UserQuery.py | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/pym/_emerge/UserQuery.py b/pym/_emerge/UserQuery.py
> index c866a0d..f8fce77 100644
> --- a/pym/_emerge/UserQuery.py
> +++ b/pym/_emerge/UserQuery.py
> @@ -1,11 +1,12 @@
> -# Copyright 1999-2014 Gentoo Foundation
> +# Copyright 1999-2016 Gentoo Foundation
>  # Distributed under the terms of the GNU General Public License v2
>  
> -from __future__ import print_function
> +from __future__ import print_function, unicode_literals
>  
>  import signal
>  import sys
>  
> +from portage import _unicode_decode
>  from portage.output import bold, create_color_func
>  
>  
> @@ -47,18 +48,24 @@ class UserQuery(object):
>  		elif colours is None:
>  			colours=[bold]
>  		colours=(colours*len(responses))[:len(responses)]
> +		responses = [_unicode_decode(x) for x in responses]
>  		if "--alert" in self.myopts:
>  			prompt = '\a' + prompt
>  		print(bold(prompt), end=' ')
>  		try:
>  			while True:
>  				if sys.hexversion >= 0x3000000:
> -
> response=input("["+"/".join([colours[i](responses[i])
> -
> for i in range(len(responses))])+"] ")
> +					try:
> +						response =
> input("[%s] " %
> +							"/".join([colours[i](responses[i])
> +							for i in
> range(len(responses))]))
> +					except UnicodeDecodeError:
> +						response = None
>  				else:
>  					response=raw_input("["+"/".join([colours[i](responses[i])
>  									  for
> i in range(len(responses))])+"] ")
> -				if response or not enter_invalid:
> +					response =
> _unicode_decode(response)
> +				if response or (not enter_invalid
> and response == ''): for key in responses:
>  						# An empty response
> will match the # first value in responses.

this looks good to me :)

Thank you

-- 
Brian Dolbec <dolsen>



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

end of thread, other threads:[~2016-02-02  0:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-01 17:39 [gentoo-portage-dev] [PATCH] UserQuery: handle unicode (bug 573386) Zac Medico
2016-02-02  0:48 ` Brian Dolbec

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