]> granicus.if.org Git - python/commitdiff
Issue #6011: sysconfig and distutils.sysconfig use the surrogateescape error
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 23 Oct 2010 17:02:31 +0000 (17:02 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 23 Oct 2010 17:02:31 +0000 (17:02 +0000)
handler to parse the Makefile file. Avoid a UnicodeDecodeError if the source
code directory name contains a non-ASCII character and the locale encoding is
ASCII.

Lib/distutils/sysconfig.py
Lib/distutils/text_file.py
Lib/sysconfig.py
Misc/NEWS

index 8847e317436c901ddf3804a84bd061554d1d3628..6b5daa51903012b391762f4ffe91a6c3df24df70 100644 (file)
@@ -271,7 +271,7 @@ def parse_makefile(fn, g=None):
     used instead of a new dictionary.
     """
     from distutils.text_file import TextFile
-    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
+    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
 
     if g is None:
         g = {}
index 97459fbf736ae3c42651c4e7132cbbd9122fb3b9..454725c626da9f049a3c574cc1929acd7454e1c9 100644 (file)
@@ -58,6 +58,8 @@ class TextFile:
          collapse_join [default: false]
            strip leading whitespace from lines that are joined to their
            predecessor; only matters if (join_lines and not lstrip_ws)
+         errors [default: 'strict']
+           error handler used to decode the file content
 
        Note that since 'rstrip_ws' can strip the trailing newline, the
        semantics of 'readline()' must differ from those of the builtin file
@@ -72,6 +74,7 @@ class TextFile:
                         'rstrip_ws':      1,
                         'join_lines':     0,
                         'collapse_join':  0,
+                        'errors':         'strict',
                       }
 
     def __init__(self, filename=None, file=None, **options):
@@ -111,7 +114,7 @@ class TextFile:
         """Open a new file named 'filename'.  This overrides both the
            'filename' and 'file' arguments to the constructor."""
         self.filename = filename
-        self.file = io.open(self.filename, 'r')
+        self.file = io.open(self.filename, 'r', errors=self.errors)
         self.current_line = 0
 
     def close(self):
index 9b804e6b88a6f7681c8a4dcb0595c975280da4be..d38974c561185a833f2e5b82f8b67606dfc303ef 100644 (file)
@@ -215,7 +215,7 @@ def _parse_makefile(filename, vars=None):
     done = {}
     notdone = {}
 
-    with open(filename) as f:
+    with open(filename, errors="surrogateescape") as f:
         lines = f.readlines()
 
     for line in lines:
index 9aa0708aceff4e3b5d48b38f033a3938a908b706..71a4509ce62bdbf4d867ee6613397b138d145aec 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,11 @@ What's New in Python 3.2 Beta 1?
 Core and Builtins
 -----------------
 
+- Issue #6011: sysconfig and distutils.sysconfig use the surrogateescape error
+  handler to parse the Makefile file. Avoid a UnicodeDecodeError if the source
+  code directory name contains a non-ASCII character and the locale encoding is
+  ASCII.
+
 - Issue #10089: Add support for arbitrary -X options on the command-line.
   They can be retrieved through a new attribute ``sys._xoptions``.