[pypy-commit] pypy win32-encoding: start to use filesystemencoderrors

mattip pypy.commits at gmail.com
Thu May 30 17:13:35 EDT 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-encoding
Changeset: r96721:51a97447c69a
Date: 2019-05-30 11:20 +0300
http://bitbucket.org/pypy/pypy/changeset/51a97447c69a/

Log:	start to use filesystemencoderrors

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
@@ -25,6 +25,7 @@
         self.recursionlimit = 1000
         self.defaultencoding = "utf-8"
         self.filesystemencoding = None
+        self.filesystemencoderrors = None
         self.debug = True
         self.track_resources = False
         self.finalizing = False
@@ -152,16 +153,27 @@
         space = self.space
 
         if not space.config.translating:
-            ##from pypy.module.sys.interp_encoding import _getfilesystemencoding
-            ##self.filesystemencoding = _getfilesystemencoding(space)
-            # XXX the two lines above take a few seconds to run whenever
-            # we initialize the space; for tests, use a simpler version.
-            # Check what exactly breaks, if anything, in py3.5.  This is
-            # not strictly necessary but is an extremely nice-to-have
-            # feature: running just one test for example take 3.5
-            # seconds instead of 11.
-            from pypy.module.sys.interp_encoding import base_encoding
-            self.filesystemencoding = base_encoding
+            if sys.platform == 'win32':
+                legacywindowsfsencodingflag = 0
+                # TODO: read os.environ.get('PYTHONLEGACYWINDOWSFSENCODING', 0)
+                if legacywindowsfsencodingflag:
+                    self.filesystemencoding = 'mbcs'
+                    self.filesystemencoderrors = 'replace'
+                else:
+                    self.filesystemencoding = 'utf-8'
+                    self.filesystemencoderrors = 'surrogatepass'
+            else:
+                ##from pypy.module.sys.interp_encoding import _getfilesystemencoding
+                ##self.filesystemencoding = _getfilesystemencoding(space)
+                # XXX the two lines above take a few seconds to run whenever
+                # we initialize the space; for tests, use a simpler version.
+                # Check what exactly breaks, if anything, in py3.  This is
+                # not strictly necessary but is an extremely nice-to-have
+                # feature: running just one test for example take 3.5
+                # seconds instead of 11.
+                from pypy.module.sys.interp_encoding import base_encoding
+                self.filesystemencoding = base_encoding
+                self.filesystemencoderrors = 'surrogateescape'
 
             # Set up sys.prefix and friends, like app_main.py would do
             # We somewhat arbitrarily use the repo's root dir as sys.prefix
diff --git a/pypy/module/sys/interp_encoding.py b/pypy/module/sys/interp_encoding.py
--- a/pypy/module/sys/interp_encoding.py
+++ b/pypy/module/sys/interp_encoding.py
@@ -1,6 +1,5 @@
 import sys
 from rpython.rlib import rlocale
-from rpython.rlib.objectmodel import we_are_translated
 
 def getdefaultencoding(space):
     """Return the current default string encoding used by the Unicode
@@ -8,7 +7,8 @@
     return space.newtext(space.sys.defaultencoding)
 
 if sys.platform == "win32":
-    base_encoding = "mbcs"
+    # crash, this should not be used
+    base_encoding = "utf-8"
 elif sys.platform == "darwin":
     base_encoding = "utf-8"
 elif sys.platform == "linux2":
@@ -51,4 +51,6 @@
 
 
 def getfilesystemencodeerrors(space):
-    return space.newtext('surrogateescape')
+    if space.sys.filesystemencoderrors is None:
+        return space.newtext('surrogateescape')
+    return space.newtext(space.sys.filesystemencoderrors)


More information about the pypy-commit mailing list