[Python-checkins] cpython: Fix usage of bytes in packaging's bdist_wininst.

eric.araujo python-checkins at python.org
Mon Sep 12 17:42:20 CEST 2011


http://hg.python.org/cpython/rev/770d61fa5bab
changeset:   72353:770d61fa5bab
user:        Éric Araujo <merwok at netwok.org>
date:        Sat Sep 10 18:14:08 2011 +0200
summary:
  Fix usage of bytes in packaging's bdist_wininst.

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.

files:
  Lib/packaging/command/bdist_wininst.py |  15 +++++++------
  1 files changed, 8 insertions(+), 7 deletions(-)


diff --git a/Lib/packaging/command/bdist_wininst.py b/Lib/packaging/command/bdist_wininst.py
--- a/Lib/packaging/command/bdist_wininst.py
+++ b/Lib/packaging/command/bdist_wininst.py
@@ -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 @@
                 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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list