[pypy-commit] pypy py3.5: fix PYTHONIOENCODING=""

pjenvey pypy.commits at gmail.com
Mon Jan 16 00:04:48 EST 2017


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3.5
Changeset: r89601:2fb902af2c9c
Date: 2017-01-15 20:55 -0800
http://bitbucket.org/pypy/pypy/changeset/2fb902af2c9c/

Log:	fix PYTHONIOENCODING=""

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,10 +291,10 @@
     try:
         if encoding and ':' in encoding:
             encoding, errors = encoding.split(':', 1)
-            encoding = encoding or None
             errors = errors or None
         else:
             errors = None
+        encoding = encoding or None
         if not (encoding or errors):
             # stdin/out default to surrogateescape in C locale
             import _locale
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
@@ -1004,11 +1004,17 @@
             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"
+        for encoding, expected in [
+            (None, "surrogateescape"),
+            ("", "surrogateescape")
+        ]:
+            p = getscript_in_dir("import sys; print(sys.stdout.errors, end='')")
+            env = os.environ.copy()
+            env["LC_ALL"] = "C"
+            if encoding is not None:
+                env["PYTHONIOENCODING"] = encoding
+            data = self.run(p, env=env)
+            assert data == "surrogateescape"
 
     def test_sys_exit_pythonioencoding(self):
         if sys.version_info < (2, 7):


More information about the pypy-commit mailing list