Commits

Philip Jenvey  committed b745bd2

default stderr to backslashreplace

  • Participants
  • Parent commits 0f6032e
  • Branches py3k

Comments (0)

Files changed (4)

File pypy/interpreter/app_main.py

     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):

File pypy/interpreter/test2/test_app_main.py

         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):

File pypy/module/sys/__init__.py

                                                       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>"
                """)

File pypy/module/sys/test/test_sysmodule.py

         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
         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