Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r61104:b745bd223983 Date: 2013-02-11 13:43 -0800 http://bitbucket.org/pypy/pypy/changeset/b745bd223983/
Log: default stderr to backslashreplace diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py --- a/pypy/interpreter/app_main.py +++ b/pypy/interpreter/app_main.py @@ -251,7 +251,7 @@ sys.stdout = sys.__stdout__ = create_stdio( 1, True, "<stdout>", encoding, errors, unbuffered) sys.stderr = sys.__stderr__ = create_stdio( - 2, True, "<stderr>", encoding, errors, unbuffered) + 2, True, "<stderr>", encoding, 'backslashreplace', unbuffered) def create_stdio(fd, writing, name, encoding, errors, unbuffered): diff --git a/pypy/interpreter/test2/test_app_main.py b/pypy/interpreter/test2/test_app_main.py --- a/pypy/interpreter/test2/test_app_main.py +++ b/pypy/interpreter/test2/test_app_main.py @@ -880,6 +880,19 @@ assert status == 1 assert data.startswith("15\xe2\x82\xac") + def test_stderr_backslashreplace(self): + if sys.version_info < (2, 7): + skip("test required Python >= 2.7") + p = getscript_in_dir(""" + import sys + sys.exit('15\u20ac {}'.format((sys.stdout.errors, sys.stderr.errors))) + """) + env = os.environ.copy() + env["PYTHONIOENCODING"] = 'ascii' + data, status = self.run_with_status_code(p, env=env) + assert status == 1 + assert data.startswith("15\\u20ac ('strict', 'backslashreplace')") + class TestAppMain: def test_print_info(self): diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py --- a/pypy/module/sys/__init__.py +++ b/pypy/module/sys/__init__.py @@ -121,6 +121,7 @@ closefd=False) sys.stdout.buffer.raw.name = "<stdout>" sys.stderr = sys.__stderr__ = io.open(2, "w", encoding="ascii", + errors="backslashreplace", closefd=False) sys.stderr.buffer.raw.name = "<stderr>" """) diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py --- a/pypy/module/sys/test/test_sysmodule.py +++ b/pypy/module/sys/test/test_sysmodule.py @@ -96,6 +96,7 @@ assert isinstance(sys.__stdout__, io.IOBase) assert isinstance(sys.__stderr__, io.IOBase) assert isinstance(sys.__stdin__, io.IOBase) + assert sys.__stderr__.errors == 'backslashreplace' if self.appdirect and not isinstance(sys.stdin, io.IOBase): return @@ -103,6 +104,7 @@ assert isinstance(sys.stdout, io.IOBase) assert isinstance(sys.stderr, io.IOBase) assert isinstance(sys.stdin, io.IOBase) + assert sys.stderr.errors == 'backslashreplace' def test_getfilesystemencoding(self): import sys _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit