From: Zac Medico Date: Sat, 29 Oct 2011 00:12:11 +0000 (-0700) Subject: Use bytes instead of unicode with isinstance. X-Git-Tag: v2.2.0_alpha72~31 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a828ef4cb5ee60e448a95bb746a55fb476b1c575;p=portage.git Use bytes instead of unicode with isinstance. This is preferred since the bytes type is available in all supported python versions, while the unicode type is only available in python2. --- diff --git a/bin/repoman b/bin/repoman index 2099241d9..42a615420 100755 --- a/bin/repoman +++ b/bin/repoman @@ -156,7 +156,7 @@ def ParseArgs(argv, qahelp): (opts, args), just like a call to parser.parse_args() """ - if argv and sys.hexversion < 0x3000000 and not isinstance(argv[0], unicode): + if argv and isinstance(argv[0], bytes): argv = [portage._unicode_decode(x) for x in argv] modes = { diff --git a/bin/xpak-helper.py b/bin/xpak-helper.py index 4766d990d..ef74920db 100755 --- a/bin/xpak-helper.py +++ b/bin/xpak-helper.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# Copyright 2009 Gentoo Foundation +# Copyright 2009-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import optparse @@ -36,7 +36,7 @@ def command_recompose(args): def main(argv): - if argv and sys.hexversion < 0x3000000 and not isinstance(argv[0], unicode): + if argv and isinstance(argv[0], bytes): for i, x in enumerate(argv): argv[i] = portage._unicode_decode(x, errors='strict') diff --git a/pym/portage/elog/mod_syslog.py b/pym/portage/elog/mod_syslog.py index 79b11a68c..64558410d 100644 --- a/pym/portage/elog/mod_syslog.py +++ b/pym/portage/elog/mod_syslog.py @@ -23,7 +23,7 @@ def process(mysettings, key, logentries, fulltext): for msgtype,msgcontent in logentries[phase]: for line in msgcontent: line = "%s: %s: %s" % (key, phase, line) - if sys.hexversion < 0x3000000 and isinstance(line, unicode): + if sys.hexversion < 0x3000000 and not isinstance(line, bytes): # Avoid TypeError from syslog.syslog() line = line.encode(_encodings['content'], 'backslashreplace') diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py index 20eecd65a..54e683985 100644 --- a/pym/portage/util/__init__.py +++ b/pym/portage/util/__init__.py @@ -503,14 +503,15 @@ def writedict(mydict,myfilename,writekey=True): def shlex_split(s): """ - This is equivalent to shlex.split but it temporarily encodes unicode - strings to bytes since shlex.split() doesn't handle unicode strings. + This is equivalent to shlex.split, but if the current interpreter is + python2, it temporarily encodes unicode strings to bytes since python2's + shlex.split() doesn't handle unicode strings. """ - is_unicode = sys.hexversion < 0x3000000 and isinstance(s, unicode) - if is_unicode: + convert_to_bytes = sys.hexversion < 0x3000000 and not isinstance(s, bytes) + if convert_to_bytes: s = _unicode_encode(s) rval = shlex.split(s) - if is_unicode: + if convert_to_bytes: rval = [_unicode_decode(x) for x in rval] return rval