[pypy-commit] pypy py3.5: Fix for issue #2618

arigo pypy.commits at gmail.com
Thu Jul 27 11:17:33 EDT 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r91979:35d75cdc5dd0
Date: 2017-07-27 17:15 +0200
http://bitbucket.org/pypy/pypy/changeset/35d75cdc5dd0/

Log:	Fix for issue #2618

diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -618,6 +618,8 @@
 def make_encoder_wrapper(name):
     rname = "unicode_encode_%s" % (name.replace("_encode", ""), )
     assert hasattr(runicode, rname)
+    if hasattr(runicode, 'py3k_' + rname):
+        rname = 'py3k_' + rname
     @unwrap_spec(uni=unicode, errors='text_or_none')
     def wrap_encoder(space, uni, errors="strict"):
         if errors is None:
@@ -632,6 +634,8 @@
 def make_utf_encoder_wrapper(name):
     rname = "unicode_encode_%s" % (name.replace("_encode", ""), )
     assert hasattr(runicode, rname)
+    if hasattr(runicode, 'py3k_' + rname):
+        rname = 'py3k_' + rname
     @unwrap_spec(uni=unicode, errors='text_or_none')
     def wrap_encoder(space, uni, errors="strict"):
         if errors is None:
@@ -647,6 +651,8 @@
 def make_decoder_wrapper(name):
     rname = "str_decode_%s" % (name.replace("_decode", ""), )
     assert hasattr(runicode, rname)
+    if hasattr(runicode, 'py3k_' + rname):
+        rname = 'py3k_' + rname
     @unwrap_spec(string='bufferstr', errors='text_or_none',
                  w_final=WrappedDefault(False))
     def wrap_decoder(space, string, errors="strict", w_final=None):
diff --git a/pypy/module/_codecs/test/test_codecs.py b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -623,6 +623,9 @@
                "surrogatepass")
         raises(UnicodeDecodeError, b"abc\xed\xa0z".decode, "utf-8",
                "surrogatepass")
+        assert u'\ud8ae'.encode('utf_16_be', 'surrogatepass') == b'\xd8\xae'
+        assert (u'\U0000d8ae'.encode('utf-32-be', 'surrogatepass') ==
+                b'\x00\x00\xd8\xae')
 
     def test_badandgoodsurrogatepassexceptions(self):
         import codecs


More information about the pypy-commit mailing list