def main(argv):
- if argv and isinstance(argv[0], bytes):
- argv = [portage._unicode_decode(x) for x in argv]
+ argv = portage._decode_argv(argv)
nocolor = os.environ.get('NOCOLOR')
if nocolor in ('yes', 'true'):
(opts, args), just like a call to parser.parse_args()
"""
- if argv and isinstance(argv[0], bytes):
- argv = [portage._unicode_decode(x) for x in argv]
+ argv = portage._decode_argv(argv)
modes = {
'commit' : 'Run a scan then commit changes',
if myaction is None and myoptions.deselect is True:
myaction = 'deselect'
- if myargs and isinstance(myargs[0], bytes):
- for i in range(len(myargs)):
- myargs[i] = portage._unicode_decode(myargs[i])
-
myfiles += myargs
return myaction, myopts, myfiles
if args is None:
args = sys.argv[1:]
+ args = portage._decode_argv(args)
+
# Disable color until we're sure that it should be enabled (after
# EMERGE_DEFAULT_OPTS has been parsed).
portage.output.havecolor = 0
}
if sys.hexversion >= 0x3000000:
+
+ def _decode_argv(argv):
+ # With Python 3, the surrogateescape encoding error handler makes it
+ # possible to access the original argv bytes, which can be useful
+ # if their actual encoding does no match the filesystem encoding.
+ fs_encoding = sys.getfilesystemencoding()
+ return [_unicode_decode(x.encode(fs_encoding, 'surrogateescape'))
+ for x in argv]
+
def _unicode_encode(s, encoding=_encodings['content'], errors='backslashreplace'):
if isinstance(s, str):
s = s.encode(encoding, errors)
_native_string = _unicode_decode
else:
+
+ def _decode_argv(argv):
+ return [_unicode_decode(x) for x in argv]
+
def _unicode_encode(s, encoding=_encodings['content'], errors='backslashreplace'):
if isinstance(s, unicode):
s = s.encode(encoding, errors)