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


Reply via email to