diff options
author | Pauli Virtanen <pav@iki.fi> | 2010-05-11 20:42:42 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-05-11 20:42:42 +0000 |
commit | 4e2e78f908d8b8191b6257614096801c5d1af2f4 (patch) | |
tree | 111f005ea3032ab679ea49badd486632c98dc97d /numpy | |
parent | e3cea87edc4a036b7e5643a488615c57c41de739 (diff) | |
download | numpy-4e2e78f908d8b8191b6257614096801c5d1af2f4.tar.gz |
BUG/3K: distutils: do not assume that files output e.g. by gcc can be read in ascii codec
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/compat/py3k.py | 6 | ||||
-rw-r--r-- | numpy/distutils/exec_command.py | 14 |
2 files changed, 13 insertions, 7 deletions
diff --git a/numpy/compat/py3k.py b/numpy/compat/py3k.py index 7357bacff..7349964b8 100644 --- a/numpy/compat/py3k.py +++ b/numpy/compat/py3k.py @@ -5,7 +5,7 @@ Python 3 compatibility tools. __all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception', 'strchar', 'unicode', 'asunicode', 'asbytes_nested', 'asunicode_nested', - 'asstr'] + 'asstr', 'open_latin1'] import sys @@ -24,6 +24,8 @@ if sys.version_info[0] >= 3: return s.decode('latin1') def isfileobj(f): return isinstance(f, io.FileIO) + def open_latin1(filename, mode='r'): + return open(f, mode=mode, encoding='iso-8859-1') strchar = 'U' else: bytes = str @@ -37,6 +39,8 @@ else: if isinstance(s, unicode): return s return s.decode('ascii') + def open_latin1(filename, mode='r'): + return open(filename, mode=mode) def getexception(): return sys.exc_info()[1] diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py index e1855df20..e0c3e1c97 100644 --- a/numpy/distutils/exec_command.py +++ b/numpy/distutils/exec_command.py @@ -55,6 +55,8 @@ from numpy.distutils.misc_util import is_sequence, make_temp_file from numpy.distutils import log from numpy.distutils.compat import get_exception +from numpy.compat import open_latin1 + def temp_file_name(): fo, name = make_temp_file() fo.close() @@ -248,13 +250,13 @@ def _exec_command_posix( command, return _exec_command(command, use_shell=use_shell, **env) if stsfile is not None: - f = open(stsfile,'r') + f = open_latin1(stsfile,'r') status_text = f.read() status = int(status_text) f.close() os.remove(stsfile) - f = open(tmpfile,'r') + f = open_latin1(tmpfile,'r') text = f.read() f.close() os.remove(tmpfile) @@ -293,12 +295,12 @@ def _exec_command_python(command, raise RuntimeError("%r failed" % (cmd,)) os.remove(cmdfile) - f = open(stsfile,'r') + f = open_latin1(stsfile,'r') status = int(f.read()) f.close() os.remove(stsfile) - f = open(outfile,'r') + f = open_latin1(outfile,'r') text = f.read() f.close() os.remove(outfile) @@ -390,14 +392,14 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ): os.dup2(se_dup,se_fileno) fout.close() - fout = open(outfile,'r') + fout = open_latin1(outfile,'r') text = fout.read() fout.close() os.remove(outfile) if using_command: ferr.close() - ferr = open(errfile,'r') + ferr = open_latin1(errfile,'r') errmess = ferr.read() ferr.close() os.remove(errfile) |