In python-2.x, convert PortageException.value attribute from unicode to str
authorZac Medico <zmedico@gentoo.org>
Fri, 29 Jan 2010 18:45:49 +0000 (18:45 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 29 Jan 2010 18:45:49 +0000 (18:45 -0000)
in order to avoid empty output with string format operator. (trunk r15169)

svn path=/main/branches/2.1.7/; revision=15237

pym/portage/exception.py

index 85efc2767af64d50227704b886a42fc777cc2da7..900dab7df0f188fc61f807ec949949ac225e75d1 100644 (file)
@@ -3,6 +3,7 @@
 # $Id$
 
 import sys
+from portage import _unicode_encode
 from portage.localization import _
 
 if sys.hexversion >= 0x3000000:
@@ -12,6 +13,10 @@ class PortageException(Exception):
        """General superclass for portage exceptions"""
        def __init__(self,value):
                self.value = value[:]
+               if sys.hexversion < 0x3000000 and isinstance(self.value, unicode):
+                       # Workaround for string formatting operator and unicode value
+                       # attribute triggering empty output in formatted string.
+                       self.value = _unicode_encode(self.value)
        def __str__(self):
                if isinstance(self.value, basestring):
                        return self.value