Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] UserQuery: handle unicode (bug 573386)
Date: Mon, 01 Feb 2016 17:39:39
Message-Id: 1454348356-30027-1-git-send-email-zmedico@gentoo.org
1 Handle UnicodeDecodeError from the input function in python3, and from
2 comparisons with unicode literals in python2.
3
4 X-Gentoo-Bug: 573386
5 X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=573386
6 ---
7 pym/_emerge/UserQuery.py | 17 ++++++++++++-----
8 1 file changed, 12 insertions(+), 5 deletions(-)
9
10 diff --git a/pym/_emerge/UserQuery.py b/pym/_emerge/UserQuery.py
11 index c866a0d..f8fce77 100644
12 --- a/pym/_emerge/UserQuery.py
13 +++ b/pym/_emerge/UserQuery.py
14 @@ -1,11 +1,12 @@
15 -# Copyright 1999-2014 Gentoo Foundation
16 +# Copyright 1999-2016 Gentoo Foundation
17 # Distributed under the terms of the GNU General Public License v2
18
19 -from __future__ import print_function
20 +from __future__ import print_function, unicode_literals
21
22 import signal
23 import sys
24
25 +from portage import _unicode_decode
26 from portage.output import bold, create_color_func
27
28
29 @@ -47,18 +48,24 @@ class UserQuery(object):
30 elif colours is None:
31 colours=[bold]
32 colours=(colours*len(responses))[:len(responses)]
33 + responses = [_unicode_decode(x) for x in responses]
34 if "--alert" in self.myopts:
35 prompt = '\a' + prompt
36 print(bold(prompt), end=' ')
37 try:
38 while True:
39 if sys.hexversion >= 0x3000000:
40 - response=input("["+"/".join([colours[i](responses[i])
41 - for i in range(len(responses))])+"] ")
42 + try:
43 + response = input("[%s] " %
44 + "/".join([colours[i](responses[i])
45 + for i in range(len(responses))]))
46 + except UnicodeDecodeError:
47 + response = None
48 else:
49 response=raw_input("["+"/".join([colours[i](responses[i])
50 for i in range(len(responses))])+"] ")
51 - if response or not enter_invalid:
52 + response = _unicode_decode(response)
53 + if response or (not enter_invalid and response == ''):
54 for key in responses:
55 # An empty response will match the
56 # first value in responses.
57 --
58 2.4.10

Replies