[Python-checkins] distutils2: Fix usage of bytes in bdist_wininst.

eric.araujo python-checkins at python.org
Mon Sep 19 15:12:40 CEST 2011


http://hg.python.org/distutils2/rev/62c7c062516b
changeset:   1178:62c7c062516b
user:        Éric Araujo <merwok at netwok.org>
date:        Mon Sep 19 05:00:50 2011 +0200
summary:
  Fix usage of bytes in bdist_wininst.

This is copied from the namesake distutils command; I can’t test the
change but it should be okay, as Python 3 users have tested the
distutils command.

files:
  distutils2/command/bdist_wininst.py |  10 ++++++----
  1 files changed, 6 insertions(+), 4 deletions(-)


diff --git a/distutils2/command/bdist_wininst.py b/distutils2/command/bdist_wininst.py
--- a/distutils2/command/bdist_wininst.py
+++ b/distutils2/command/bdist_wininst.py
@@ -1,9 +1,8 @@
 """Create an executable installer for Windows."""
 
-# FIXME synchronize bytes/str use with same file in distutils
-
 import sys
 import os
+import codecs
 
 from shutil import rmtree
 
@@ -271,9 +270,12 @@
             # Append the pre-install script
             cfgdata = cfgdata + "\0"
             if self.pre_install_script:
-                fp = open(self.pre_install_script)
+                # We need to normalize newlines, so we open in text mode and
+                # convert back to bytes. "latin-1" simply avoids any possible
+                # failures.
+                fp = codecs.open(self.pre_install_script, encoding="latin-1")
                 try:
-                    script_data = fp.read()
+                    script_data = fp.read().encode("latin-1")
                 finally:
                     fp.close()
                 cfgdata = cfgdata + script_data + "\n\0"

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


More information about the Python-checkins mailing list