summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/_emerge/Package.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py
index cb14062ac..61a976530 100644
--- a/pym/_emerge/Package.py
+++ b/pym/_emerge/Package.py
@@ -4,6 +4,7 @@
import sys
from itertools import chain
import portage
+from portage import _unicode_decode
from portage.cache.mappings import slot_dict_class
from portage.const import EBUILD_PHASES
from portage.dep import Atom, check_required_use, use_reduce, \
@@ -221,6 +222,16 @@ class Package(Task):
return True
def _metadata_exception(self, k, e):
+
+ # For unicode safety with python-2.x we need to avoid
+ # using the string format operator with a non-unicode
+ # format string, since that will result in the
+ # PortageException.__str__() method being invoked,
+ # followed by unsafe decoding that may result in a
+ # UnicodeDecodeError. Therefore, use _unicode_decode()
+ # to ensure that format strings are unicode, so that
+ # PortageException.__unicode__() is used when necessary
+ # in python-2.x.
if not self.installed:
categorized_error = False
if e.errors:
@@ -229,11 +240,11 @@ class Package(Task):
continue
categorized_error = True
self._invalid_metadata(error.category,
- "%s: %s" % (k, error))
+ _unicode_decode("%s: %s") % (k, error))
if not categorized_error:
self._invalid_metadata(k + ".syntax",
- "%s: %s" % (k, e))
+ _unicode_decode("%s: %s") % (k, e))
else:
# For installed packages, show the path of the file
# containing the invalid metadata, since the user may
@@ -241,7 +252,7 @@ class Package(Task):
vardb = self.root_config.trees['vartree'].dbapi
path = vardb.getpath(self.cpv, filename=k)
self._invalid_metadata(k + ".syntax",
- "%s: %s in '%s'" % (k, e, path))
+ _unicode_decode("%s: %s in '%s'") % (k, e, path))
def _invalid_metadata(self, msg_type, msg):
if self.invalid is None: