-# Copyright 1999-2009 Gentoo Foundation
+# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
+import sys
+
+from portage import _encodings, _unicode_encode
from portage.output import red
from portage.util import cmp_sort_key
from portage.output import blue
+
class UseFlagDisplay(object):
__slots__ = ('name', 'enabled', 'forced')
s = '(%s)' % s
return s
+ if sys.hexversion < 0x3000000:
+
+ __unicode__ = __str__
+
+ def __str__(self):
+ return _unicode_encode(self.__unicode__(),
+ encoding=_encodings['content'])
+
def _cmp_combined(a, b):
"""
Sort by name, combining enabled and disabled flags.
f not in use_expand_flags:
use_disabled['USE'].append(f)
+ flag_displays = []
for varname in var_order:
if varname in use_expand_hidden:
continue
flags.sort(key=UseFlagDisplay.sort_combined)
else:
flags.sort(key=UseFlagDisplay.sort_separated)
- print('%s="%s"' % (varname, ' '.join(str(f) for f in flags)), end=' ')
- print()
+ # Use _unicode_decode() to force unicode format string so
+ # that UseFlagDisplay.__unicode__() is called in python2.
+ flag_displays.append('%s="%s"' % (varname,
+ ' '.join(_unicode_decode("%s") % (f,) for f in flags)))
+ writemsg_stdout('%s\n' % ' '.join(flag_displays))
if pkg_type == "installed":
for myvar in mydesiredvars:
if metadata[myvar].split() != settings.get(myvar, '').split():
from portage.exception import PortageException
from portage.tests import TestCase
from _emerge.DependencyArg import DependencyArg
+from _emerge.UseFlagDisplay import UseFlagDisplay
+
+if sys.hexversion >= 0x3000000:
+ basestring = str
STR_IS_UNICODE = sys.hexversion >= 0x3000000
# Test the __str__ method which returns encoded bytes in python2
formatted_bytes = "%s" % (e,)
self.assertEqual(formatted_bytes, arg_bytes)
+
+ def testUseFlagDisplay(self):
+
+ self.assertEqual(_encodings['content'], 'utf_8')
+
+ for enabled in (True, False):
+ for forced in (True, False):
+ for arg_bytes in self.unicode_strings:
+ arg_unicode = _unicode_decode(arg_bytes, encoding=_encodings['content'])
+ e = UseFlagDisplay(arg_unicode, enabled, forced)
+
+ # Force unicode format string so that __unicode__() is
+ # called in python2.
+ formatted_str = _unicode_decode("%s") % (e,)
+ self.assertEqual(isinstance(formatted_str, basestring), True)
+
+ if STR_IS_UNICODE:
+
+ # Test the __str__ method which returns unicode in python3
+ formatted_str = "%s" % (e,)
+ self.assertEqual(isinstance(formatted_str, str), True)
+
+ else:
+
+ # Test the __str__ method which returns encoded bytes in python2
+ formatted_bytes = "%s" % (e,)
+ self.assertEqual(isinstance(formatted_bytes, bytes), True)