[pypy-commit] pypy default: move the PYTHONIOENCODING logic to its own function

antocuni noreply at buildbot.pypy.org
Mon Jun 11 17:20:04 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r55589:4f58f2db96c0
Date: 2012-06-11 17:05 +0200
http://bitbucket.org/pypy/pypy/changeset/4f58f2db96c0/

Log:	move the PYTHONIOENCODING logic to its own function

diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -238,6 +238,24 @@
             sys.path.append(dir)
             _seen[dir] = True
 
+def set_stdio_encodings(ignore_environment):
+    import os
+    readenv = not ignore_environment
+    io_encoding = readenv and os.getenv("PYTHONIOENCODING")
+    if io_encoding:
+        errors = None
+        if ":" in io_encoding:
+            io_encoding, errors = io_encoding.split(":", 1)
+        set_io_encoding(io_encoding, io_encoding, errors, True)
+    else:
+        if IS_WINDOWS:
+            import __pypy__
+            io_encoding, io_encoding_output = __pypy__.get_console_cp()
+        else:
+            io_encoding = io_encoding_output = sys.getfilesystemencoding()
+        if io_encoding:
+            set_io_encoding(io_encoding, io_encoding_output, None, False)
+
 def set_io_encoding(io_encoding, io_encoding_output, errors, overridden):
     try:
         import _file
@@ -471,22 +489,9 @@
         except:
             print >> sys.stderr, "'import site' failed"
 
+    set_stdio_encodings(ignore_environment)
+
     readenv = not ignore_environment
-    io_encoding = readenv and os.getenv("PYTHONIOENCODING")
-    if io_encoding:
-        errors = None
-        if ":" in io_encoding:
-            io_encoding, errors = io_encoding.split(":", 1)
-        set_io_encoding(io_encoding, io_encoding, errors, True)
-    else:
-        if IS_WINDOWS:
-            import __pypy__
-            io_encoding, io_encoding_output = __pypy__.get_console_cp()
-        else:
-            io_encoding = io_encoding_output = sys.getfilesystemencoding()
-        if io_encoding:
-            set_io_encoding(io_encoding, io_encoding_output, None, False)
-
     pythonwarnings = readenv and os.getenv('PYTHONWARNINGS')
     if pythonwarnings:
         warnoptions.extend(pythonwarnings.split(','))


More information about the pypy-commit mailing list