(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 = {
#!/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
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')
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')
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