[pypy-commit] pypy unicode-utf8-py3: use rutf8 to do decode(..., 'replace', ...)

mattip pypy.commits at gmail.com
Sun Aug 5 14:13:27 EDT 2018


Author: Matti Picus <matti.picus at gmail.com>
Branch: unicode-utf8-py3
Changeset: r94951:91d7f28bf01c
Date: 2018-08-05 11:08 -0700
http://bitbucket.org/pypy/pypy/changeset/91d7f28bf01c/

Log:	use rutf8 to do decode(..., 'replace', ...)

diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -517,10 +517,14 @@
                     elif fmt == 'N':
                         result = _decode_utf8(value.getname(space))
                     elif fmt == '8':
+                        # u'str\uxxxx' -> 'str\xXX\xXX' -> u"'str\xXX\xXX'"
                         if isinstance(value, unicode):
                             result = value.encode('utf8')
                         else:
-                            result = value.decode('utf8', 'replace')
+                            from pypy.interpreter import unicodehelper
+                            result = _decode_utf8(unicodehelper.str_decode_utf8(
+                                value, 'replace', True,
+                                unicodehelper.decode_never_raise, True)[0])
                     else:
                         if isinstance(value, unicode):
                             result = value


More information about the pypy-commit mailing list