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] bintree.populate: binhost connection failure triggers TypeError (bug 532784)
Date: Mon, 04 May 2015 04:53:02
Message-Id: 1430715153-27893-1-git-send-email-zmedico@gentoo.org
1 Since commit 4496ee37d6fa327ada635c67500e82f830141a9e, binhost
2 connection errors result in a TypeError. Fix it to call the unicode
3 function correctly (with only a single argument). Also, handle
4 a possible UnicodeDecodeError.
5
6 Fixes: 4496ee37d6fa ("bintree.py: fix str() calls for Python 2 (532784)")
7 X-Gentoo-Bug: 532784
8 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=532784
9 ---
10 pym/portage/dbapi/bintree.py | 8 ++++++--
11 1 file changed, 6 insertions(+), 2 deletions(-)
12
13 diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
14 index b37f388..4043016 100644
15 --- a/pym/portage/dbapi/bintree.py
16 +++ b/pym/portage/dbapi/bintree.py
17 @@ -961,8 +961,12 @@ class binarytree(object):
18 # With Python 2, the EnvironmentError message may
19 # contain bytes or unicode, so use _unicode to ensure
20 # safety with all locales (bug #532784).
21 - writemsg("!!! %s\n\n" % _unicode(e,
22 - _encodings["stdio"], errors="replace"))
23 + try:
24 + error_msg = _unicode(e)
25 + except UnicodeDecodeError as uerror:
26 + error_msg = _unicode(uerror.object,
27 + encoding='utf_8', errors='replace')
28 + writemsg("!!! %s\n\n" % error_msg)
29 del e
30 pkgindex = None
31 if proc is not None:
32 --
33 2.3.5

Replies