Commits

Philip Jenvey committed fcd9446

adapt 66eb9aa93bb4 to py3k, fixes some cases of surrogateescape failing. as an
aside, this finishes syncing runicode.py between the branches

  • Participants
  • Parent commits 0785926
  • Branches py3k

Comments (0)

Files changed (2)

pypy/module/_codecs/interp_codecs.py

                 raise operationerrfmt(
                     space.w_IndexError,
                     "position %d from error handler out of bounds", newpos)
-            replace = space.unicode_w(w_replace)
-            return replace, newpos
+            return w_replace, newpos
         return call_errorhandler
 
     def make_decode_errorhandler(self, space):
-        return self._make_errorhandler(space, True)
+        errorhandler = self._make_errorhandler(space, True)
+        def decode_call_errorhandler(errors, encoding, reason, input,
+                                     startpos, endpos):
+            w_replace, newpos = errorhandler(errors, encoding, reason, input,
+                                             startpos, endpos)
+            return space.unicode_w(w_replace), newpos
+        return decode_call_errorhandler
 
     def make_encode_errorhandler(self, space):
         errorhandler = self._make_errorhandler(space, False)
-        def encode_call_errorhandler(errors, encoding, reason, input, startpos,
-                                     endpos):
-            replace, newpos = errorhandler(errors, encoding, reason, input,
-                                           startpos, endpos)
-            return replace, None, newpos
+        def encode_call_errorhandler(errors, encoding, reason, input,
+                                     startpos, endpos):
+            w_replace, newpos = errorhandler(errors, encoding, reason, input,
+                                             startpos, endpos)
+            if space.isinstance_w(w_replace, space.w_unicode):
+                return space.unicode_w(w_replace), None, newpos
+            return None, space.bytes_w(w_replace), newpos
         return encode_call_errorhandler
 
     def get_unicodedata_handler(self, space):

pypy/module/_multibytecodec/test/test_app_codecs.py

         import sys
         codecs.register_error("test.test_encode_custom_error_handler_type",
                               lambda e: ('\xc3', e.end))
-        raises(TypeError, u"\uDDA1".encode, "gbk",
-               "test.test_encode_custom_error_handler_type")
+        result = "\uDDA1".encode("gbk", "test.test_encode_custom_error_handler_type")
+        assert '\xc3' in result