UnsupportedAPIException: handle unicode in EAPI
authorZac Medico <zmedico@gentoo.org>
Sun, 27 Mar 2011 20:55:11 +0000 (13:55 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 27 Mar 2011 20:58:10 +0000 (13:58 -0700)
Normally EAPI doesn't contain unicode, but as in bug #359675, it can
contain practically anything if files in /var/db/pkg are corrupt.

pym/portage/dbapi/vartree.py
pym/portage/exception.py

index ce94fa41802fd9aeac7c45b8223a8eab976e71eb..a9e8edef21cd4a703ef5eb4de56b555158e004cf 100644 (file)
@@ -1536,7 +1536,7 @@ class dblink(object):
                                showMessage(_("!!! FAILED prerm: %s\n") % \
                                        os.path.join(self.dbdir, "EAPI"),
                                        level=logging.ERROR, noiselevel=-1)
-                               showMessage("%s\n" % (e,),
+                               showMessage(_unicode_decode("%s\n") % (e,),
                                        level=logging.ERROR, noiselevel=-1)
                                myebuildpath = None
 
index 64d0f7b0db334c38bd39ad56c129696599e7d5ae..789112072710c5e3153502f0dcf6439504c131f2 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1998-2004 Gentoo Foundation
+# Copyright 1998-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import signal
@@ -150,13 +150,24 @@ class UnsupportedAPIException(PortagePackageException):
        def __init__(self, cpv, eapi):
                self.cpv, self.eapi = cpv, eapi
        def __str__(self):
+               eapi = self.eapi
+               if not isinstance(eapi, basestring):
+                       eapi = str(eapi)
+               eapi = eapi.lstrip("-")
                msg = _("Unable to do any operations on '%(cpv)s', since "
                "its EAPI is higher than this portage version's. Please upgrade"
                " to a portage version that supports EAPI '%(eapi)s'.") % \
-               {"cpv": self.cpv, "eapi": str(self.eapi).lstrip("-")}
-               return msg
+               {"cpv": self.cpv, "eapi": eapi}
+               return _unicode_decode(msg,
+                       encoding=_encodings['content'], errors='replace')
 
+       if sys.hexversion < 0x3000000:
+
+               __unicode__ = __str__
 
+               def __str__(self):
+                       return _unicode_encode(self.__unicode__(),
+                               encoding=_encodings['content'], errors='backslashreplace')
 
 class SignatureException(PortageException):
        """Signature was not present in the checked file"""