From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id F10C91389E2 for ; Wed, 17 Dec 2014 22:13:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2CC29E0880; Wed, 17 Dec 2014 22:13:26 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B2956E0880 for ; Wed, 17 Dec 2014 22:13:25 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 780553405E8 for ; Wed, 17 Dec 2014 22:13:24 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 207FDCAD9 for ; Wed, 17 Dec 2014 22:13:23 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1418854357.4496ee37d6fa327ada635c67500e82f830141a9e.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/dbapi/bintree.py X-VCS-Directories: pym/portage/dbapi/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 4496ee37d6fa327ada635c67500e82f830141a9e X-VCS-Branch: master Date: Wed, 17 Dec 2014 22:13:23 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: c67d119a-5807-4821-be5d-96afc0d7ac3f X-Archives-Hash: 51a133c0ffb693b754ca7e1bad70363d commit: 4496ee37d6fa327ada635c67500e82f830141a9e Author: Zac Medico gentoo org> AuthorDate: Wed Dec 17 17:33:50 2014 +0000 Commit: Zac Medico gentoo org> CommitDate: Wed Dec 17 22:12:37 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=4496ee37 bintree.py: fix str() calls for Python 2 (532784) Avoid a UnicodeDecodeError raised when str(e) converts an exception to bytes with Python 2. Since this file has unicode_literals enabled, use literal unicode format strings to format messages for unicode exceptions. However, with Python 2, an EnvironmentError exception may contain either bytes or unicode, so use _unicode(errors="replace") to ensure safety for EnvironmentError with all locales. Also, convert remaining str() calls to use _unicode() for uniform behavior regardless of python version. X-Gentoo-Bug: 532784 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=532784 Acked-by: Brian Dolbec gentoo.org> --- pym/portage/dbapi/bintree.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index d7c7f95..1156b66 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -391,7 +391,7 @@ class binarytree(object): # sanity check for atom in (origcp, newcp): if not isjustname(atom): - raise InvalidPackageName(str(atom)) + raise InvalidPackageName(_unicode(atom)) mynewcat = catsplit(newcp)[0] origmatches=self.dbapi.cp_list(origcp) moves = 0 @@ -803,8 +803,8 @@ class binarytree(object): d["CPV"] = mycpv d["SLOT"] = slot - d["MTIME"] = str(s[stat.ST_MTIME]) - d["SIZE"] = str(s.st_size) + d["MTIME"] = _unicode(s[stat.ST_MTIME]) + d["SIZE"] = _unicode(s.st_size) d.update(zip(self._pkgindex_aux_keys, self.dbapi.aux_get(mycpv, self._pkgindex_aux_keys))) @@ -1024,7 +1024,11 @@ class binarytree(object): except EnvironmentError as e: writemsg(_("\n\n!!! Error fetching binhost package" \ " info from '%s'\n") % _hide_url_passwd(base_url)) - writemsg("!!! %s\n\n" % str(e)) + # 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")) del e pkgindex = None if proc is not None: @@ -1242,8 +1246,8 @@ class binarytree(object): d["CPV"] = cpv st = os.stat(pkg_path) - d["MTIME"] = str(st[stat.ST_MTIME]) - d["SIZE"] = str(st.st_size) + d["MTIME"] = _unicode(st[stat.ST_MTIME]) + d["SIZE"] = _unicode(st.st_size) rel_path = self._pkg_paths[cpv] # record location if it's non-default @@ -1270,7 +1274,7 @@ class binarytree(object): if profile_path.startswith(profiles_base): profile_path = profile_path[len(profiles_base):] header["PROFILE"] = profile_path - header["VERSION"] = str(self._pkgindex_version) + header["VERSION"] = _unicode(self._pkgindex_version) base_uri = self.settings.get("PORTAGE_BINHOST_HEADER_URI") if base_uri: header["URI"] = base_uri @@ -1316,8 +1320,7 @@ class binarytree(object): deps = use_reduce(deps, uselist=use, token_class=token_class) deps = paren_enclose(deps) except portage.exception.InvalidDependString as e: - writemsg("%s: %s\n" % (k, str(e)), - noiselevel=-1) + writemsg("%s: %s\n" % (k, e), noiselevel=-1) raise metadata[k] = deps