]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix usage of bytes in packaging's bdist_wininst.
authorÉric Araujo <merwok@netwok.org>
Sat, 10 Sep 2011 16:14:08 +0000 (18:14 +0200)
committerÉric Araujo <merwok@netwok.org>
Sat, 10 Sep 2011 16:14:08 +0000 (18:14 +0200)
This is copied from the namesake distutils command; there is no
automated test, so buildbots won’t call for my head this time, but it
should be okay as Python 3 users have tested the distutils command.

Lib/packaging/command/bdist_wininst.py

index 4ba2b2db17fd3c6846b30c5b2f4f5334a3ebeae7..6c1e225f9f9467482fadd008e56564358b1b0388 100644 (file)
@@ -1,7 +1,5 @@
 """Create an executable installer for Windows."""
 
-# FIXME synchronize bytes/str use with same file in distutils
-
 import sys
 import os
 
@@ -264,14 +262,17 @@ class bdist_wininst(Command):
                 cfgdata = cfgdata.encode("mbcs")
 
             # Append the pre-install script
-            cfgdata = cfgdata + "\0"
+            cfgdata = cfgdata + b"\0"
             if self.pre_install_script:
-                with open(self.pre_install_script) as fp:
-                    script_data = fp.read()
-                cfgdata = cfgdata + script_data + "\n\0"
+                # We need to normalize newlines, so we open in text mode and
+                # convert back to bytes. "latin-1" simply avoids any possible
+                # failures.
+                with open(self.pre_install_script, encoding="latin-1") as fp:
+                    script_data = fp.read().encode("latin-1")
+                cfgdata = cfgdata + script_data + b"\n\0"
             else:
                 # empty pre-install script
-                cfgdata = cfgdata + "\0"
+                cfgdata = cfgdata + b"\0"
             file.write(cfgdata)
 
             # The 'magic number' 0x1234567B is used to make sure that the