Commit b8f45f03 authored by Victor Stinner's avatar Victor Stinner

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.
parent f7c83bfd
...@@ -271,7 +271,7 @@ def parse_makefile(fn, g=None): ...@@ -271,7 +271,7 @@ def parse_makefile(fn, g=None):
used instead of a new dictionary. used instead of a new dictionary.
""" """
from distutils.text_file import TextFile 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: if g is None:
g = {} g = {}
......
...@@ -58,6 +58,8 @@ class TextFile: ...@@ -58,6 +58,8 @@ class TextFile:
collapse_join [default: false] collapse_join [default: false]
strip leading whitespace from lines that are joined to their strip leading whitespace from lines that are joined to their
predecessor; only matters if (join_lines and not lstrip_ws) 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 Note that since 'rstrip_ws' can strip the trailing newline, the
semantics of 'readline()' must differ from those of the builtin file semantics of 'readline()' must differ from those of the builtin file
...@@ -72,6 +74,7 @@ class TextFile: ...@@ -72,6 +74,7 @@ class TextFile:
'rstrip_ws': 1, 'rstrip_ws': 1,
'join_lines': 0, 'join_lines': 0,
'collapse_join': 0, 'collapse_join': 0,
'errors': 'strict',
} }
def __init__(self, filename=None, file=None, **options): def __init__(self, filename=None, file=None, **options):
...@@ -111,7 +114,7 @@ class TextFile: ...@@ -111,7 +114,7 @@ class TextFile:
"""Open a new file named 'filename'. This overrides both the """Open a new file named 'filename'. This overrides both the
'filename' and 'file' arguments to the constructor.""" 'filename' and 'file' arguments to the constructor."""
self.filename = filename self.filename = filename
self.file = io.open(self.filename, 'r') self.file = io.open(self.filename, 'r', errors=self.errors)
self.current_line = 0 self.current_line = 0
def close(self): def close(self):
......
...@@ -215,7 +215,7 @@ def _parse_makefile(filename, vars=None): ...@@ -215,7 +215,7 @@ def _parse_makefile(filename, vars=None):
done = {} done = {}
notdone = {} notdone = {}
with open(filename) as f: with open(filename, errors="surrogateescape") as f:
lines = f.readlines() lines = f.readlines()
for line in lines: for line in lines:
......
...@@ -10,6 +10,11 @@ What's New in Python 3.2 Beta 1? ...@@ -10,6 +10,11 @@ What's New in Python 3.2 Beta 1?
Core and Builtins 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. - Issue #10089: Add support for arbitrary -X options on the command-line.
They can be retrieved through a new attribute ``sys._xoptions``. They can be retrieved through a new attribute ``sys._xoptions``.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment