Author: Philip Jenvey <[email protected]>
Branch: py3.5
Changeset: r89597:31367d8c9631
Date: 2017-01-15 12:55 -0800
http://bitbucket.org/pypy/pypy/changeset/31367d8c9631/

Log:    o stdin/out now default to surrogateescape in C locale o tighten
        PYTHONIOENCODING parsing

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
@@ -291,8 +291,15 @@
     try:
         if encoding and ':' in encoding:
             encoding, errors = encoding.split(':', 1)
+            encoding = encoding or None
+            errors = errors or None
         else:
             errors = None
+        if not (encoding or errors):
+            # stdin/out default to surrogateescape in C locale
+            import _locale
+            if _locale.setlocale(_locale.LC_CTYPE, None) == 'C':
+                errors = 'surrogateescape'
 
         sys.stderr = sys.__stderr__ = create_stdio(
             2, True, "<stderr>", encoding, 'backslashreplace', unbuffered)
diff --git a/pypy/interpreter/test/test_app_main.py 
b/pypy/interpreter/test/test_app_main.py
--- a/pypy/interpreter/test/test_app_main.py
+++ b/pypy/interpreter/test/test_app_main.py
@@ -992,6 +992,24 @@
             data = self.run(p, env=env)
             assert data == expected
 
+    def test_pythonioencoding2(self):
+        for encoding, expected in [
+            ("ascii:", "strict"),
+            (":surrogateescape", "surrogateescape"),
+        ]:
+            p = getscript_in_dir("import sys; print(sys.stdout.errors, 
end='')")
+            env = os.environ.copy()
+            env["PYTHONIOENCODING"] = encoding
+            data = self.run(p, env=env)
+            assert data == expected
+
+    def test_pythonioencoding_c_locale(self):
+        p = getscript_in_dir("import sys; print(sys.stdout.errors, end='')")
+        env = os.environ.copy()
+        env["LC_ALL"] = "C"
+        data = self.run(p, env=env)
+        assert data == "surrogateescape"
+
     def test_sys_exit_pythonioencoding(self):
         if sys.version_info < (2, 7):
             skip("test required Python >= 2.7")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to