Author: Philip Jenvey <pjen...@underboss.org>
Branch: py3k
Changeset: r59272:fcd9446ab85f
Date: 2012-12-02 15:16 -0800
http://bitbucket.org/pypy/pypy/changeset/fcd9446ab85f/

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

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
@@ -60,20 +60,27 @@
                 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):
diff --git a/pypy/module/_multibytecodec/test/test_app_codecs.py 
b/pypy/module/_multibytecodec/test/test_app_codecs.py
--- a/pypy/module/_multibytecodec/test/test_app_codecs.py
+++ b/pypy/module/_multibytecodec/test/test_app_codecs.py
@@ -108,5 +108,5 @@
         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
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to