--- Lib/distutils/command/build_scripts.py +++ Lib/distutils/command/build_scripts.py @@ -13,7 +13,7 @@ from distutils import log # check if Python is called on the first line with this expression -first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$') +first_line_re = re.compile(b'^#!.*python[0-9.]*([ \t].*)?$') class build_scripts(Command): @@ -74,7 +74,7 @@ # that way, we'll get accurate feedback if we can read the # script. try: - f = open(script, "r") + f = open(script, "rb") except IOError: if not self.dry_run: raise @@ -88,25 +88,25 @@ match = first_line_re.match(first_line) if match: adjust = True - post_interp = match.group(1) or '' + post_interp = match.group(1) or b'' if adjust: log.info("copying and adjusting %s -> %s", script, self.build_dir) updated_files.append(outfile) if not self.dry_run: - outf = open(outfile, "w") + outf = open(outfile, "wb") if not sysconfig.python_build: - outf.write("#!%s%s\n" % - (self.executable, - post_interp)) + outf.write(b"#!" + + self.executable.encode() + + post_interp + b"\n") else: - outf.write("#!%s%s\n" % - (os.path.join( - sysconfig.get_config_var("BINDIR"), - "python%s%s" % (sysconfig.get_config_var("VERSION"), - sysconfig.get_config_var("EXE"))), - post_interp)) + outf.write(b"#!" + + os.path.join( + sysconfig.get_config_var("BINDIR"), + "python%s%s" % (sysconfig.get_config_var("VERSION"), + sysconfig.get_config_var("EXE"))).encode() + + post_interp + b"\n") outf.writelines(f.readlines()) outf.close() if f: