From: Zac Medico Date: Fri, 21 Jun 2013 23:07:31 +0000 (-0700) Subject: install.py: use surrogateescape for Python >=3.2 X-Git-Tag: v2.2.0_alpha184~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d31b8be0806815b1c01f36ec4b83126b1483c8b6;p=portage.git install.py: use surrogateescape for Python >=3.2 We can't trust that the filesystem encoding (locale dependent) correctly matches the arguments, so use surrogateescape to pass through the original argv bytes for Python 3. Since Python <3.2 does not support bytes in Popen args, trust the locale in that case. --- diff --git a/bin/install.py b/bin/install.py index 2ca62f233..f7118a683 100755 --- a/bin/install.py +++ b/bin/install.py @@ -223,6 +223,20 @@ def main(args): path_installs = Which('install', all=True) cmdline = path_installs[0:1] cmdline += args + + if sys.hexversion >= 0x3020000: + # We can't trust that the filesystem encoding (locale dependent) + # correctly matches the arguments, so use surrogateescape to + # pass through the original argv bytes for Python 3. + # Since Python <3.2 does not support bytes in Popen args, trust + # the locale in that case. + fs_encoding = sys.getfilesystemencoding() + cmdline = [x.encode(fs_encoding, 'surrogateescape') for x in cmdline] + files = [x.encode(fs_encoding, 'surrogateescape') for x in files] + if opts.target_directory is not None: + opts.target_directory = \ + opts.target_directory.encode(fs_encoding, 'surrogateescape') + returncode = subprocess.call(cmdline) if returncode == os.EX_OK: returncode = copy_xattrs(opts, files)