commit:     1e43b60d734f601cde727d690c7ae4d576146659
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon May  4 04:49:19 2015 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon May  4 05:13:31 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=1e43b60d

bintree.populate: binhost connection failure triggers TypeError (bug 532784)

Since commit 4496ee37d6fa327ada635c67500e82f830141a9e, binhost
connection errors result in a TypeError. Fix it to call the unicode
function correctly (with only a single argument). Also, handle
a possible UnicodeDecodeError.

Fixes: 4496ee37d6fa ("bintree.py: fix str() calls for Python 2 (532784)")
X-Gentoo-Bug: 532784
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=532784
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>

 pym/portage/dbapi/bintree.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
index b37f388..4043016 100644
--- a/pym/portage/dbapi/bintree.py
+++ b/pym/portage/dbapi/bintree.py
@@ -961,8 +961,12 @@ class binarytree(object):
                                # With Python 2, the EnvironmentError message 
may
                                # contain bytes or unicode, so use _unicode to 
ensure
                                # safety with all locales (bug #532784).
-                               writemsg("!!! %s\n\n" % _unicode(e,
-                                       _encodings["stdio"], errors="replace"))
+                               try:
+                                       error_msg = _unicode(e)
+                               except UnicodeDecodeError as uerror:
+                                       error_msg = _unicode(uerror.object,
+                                               encoding='utf_8', 
errors='replace')
+                               writemsg("!!! %s\n\n" % error_msg)
                                del e
                                pkgindex = None
                        if proc is not None:

Reply via email to