]> granicus.if.org Git - python/commitdiff
bdist_wininst does now properly handle unicode strings or byte strings
authorThomas Heller <theller@ctypes.org>
Fri, 23 Jul 2004 19:44:29 +0000 (19:44 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 23 Jul 2004 19:44:29 +0000 (19:44 +0000)
with umlauts in the author argument and others.

Fixes sf # 993943.

Lib/distutils/command/bdist_wininst.py

index 79c95ae2aed4b38b0bbdfda7bd2bb382bd8235b8..506a4a26bab878bf7bfcdca74f6c722859b23ce9 100644 (file)
@@ -176,36 +176,38 @@ class bdist_wininst (Command):
         lines = []
         metadata = self.distribution.metadata
 
-        # Write the [metadata] section.  Values are written with
-        # repr()[1:-1], so they do not contain unprintable characters, and
-        # are not surrounded by quote chars.
+        # Write the [metadata] section.
         lines.append("[metadata]")
 
         # 'info' will be displayed in the installer's dialog box,
         # describing the items to be installed.
         info = (metadata.long_description or '') + '\n'
 
+        # Escape newline characters
+        def escape(s):
+            return string.replace(s, "\n", "\\n")
+
         for name in ["author", "author_email", "description", "maintainer",
                      "maintainer_email", "name", "url", "version"]:
             data = getattr(metadata, name, "")
             if data:
                 info = info + ("\n    %s: %s" % \
-                               (string.capitalize(name), data))
-                lines.append("%s=%s" % (name, repr(data)[1:-1]))
+                               (string.capitalize(name), escape(data)))
+                lines.append("%s=%s" % (name, escape(data)))
 
         # The [setup] section contains entries controlling
         # the installer runtime.
         lines.append("\n[Setup]")
         if self.install_script:
             lines.append("install_script=%s" % self.install_script)
-        lines.append("info=%s" % repr(info)[1:-1])
+        lines.append("info=%s" % escape(info))
         lines.append("target_compile=%d" % (not self.no_target_compile))
         lines.append("target_optimize=%d" % (not self.no_target_optimize))
         if self.target_version:
             lines.append("target_version=%s" % self.target_version)
 
         title = self.title or self.distribution.get_fullname()
-        lines.append("title=%s" % repr(title)[1:-1])
+        lines.append("title=%s" % escape(title))
         import time
         import distutils
         build_info = "Built %s with distutils-%s" % \
@@ -244,6 +246,15 @@ class bdist_wininst (Command):
         if bitmap:
             file.write(bitmapdata)
 
+        # Convert cfgdata from unicode to ascii, mbcs encoded
+        try:
+            unicode
+        except NameError:
+            pass
+        else:
+            if isinstance(cfgdata, unicode):
+                cfgdata = cfgdata.encode("mbcs")
+
         # Append the pre-install script
         cfgdata = cfgdata + "\0"
         if self.pre_install_script: