commit: 1929e2bdab686004697c3d0fd999a563db43349c Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Mon Feb 1 17:36:46 2016 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Tue Feb 2 01:32:12 2016 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1929e2bd
UserQuery: handle unicode (bug 573386) 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 Acked-by: Brian Dolbec <dolsen <AT> gentoo.org> pym/_emerge/UserQuery.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pym/_emerge/UserQuery.py b/pym/_emerge/UserQuery.py index c866a0d..8096d1b 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,17 +48,23 @@ 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 = _unicode_decode(response.object).rstrip('\n') else: response=raw_input("["+"/".join([colours[i](responses[i]) for i in range(len(responses))])+"] ") + response = _unicode_decode(response) if response or not enter_invalid: for key in responses: # An empty response will match the
