Author: Armin Rigo <[email protected]>
Branch:
Changeset: r44763:3f3be23451d0
Date: 2011-06-06 20:07 +0200
http://bitbucket.org/pypy/pypy/changeset/3f3be23451d0/
Log: (prompted by amaury)
In CPython some codecs raise IndexError but others raise
OverflowError in the error handler if the integer position is out of
bounds. Decided that just sticking with OverflowError to make the
code simpler is a good enough solution. Fixed a few tests in lib-
python to accept either IndexError or OverflowError.
diff --git a/lib-python/2.7/test/test_multibytecodec.py
b/lib-python/modified-2.7/test/test_multibytecodec.py
copy from lib-python/2.7/test/test_multibytecodec.py
copy to lib-python/modified-2.7/test/test_multibytecodec.py
--- a/lib-python/2.7/test/test_multibytecodec.py
+++ b/lib-python/modified-2.7/test/test_multibytecodec.py
@@ -42,7 +42,7 @@
dec = codecs.getdecoder('euc-kr')
myreplace = lambda exc: (u'', sys.maxint+1)
codecs.register_error('test.cjktest', myreplace)
- self.assertRaises(IndexError, dec,
+ self.assertRaises((IndexError, OverflowError), dec,
'apple\x92ham\x93spam', 'test.cjktest')
def test_codingspec(self):
diff --git a/lib-python/2.7/test/test_multibytecodec_support.py
b/lib-python/modified-2.7/test/test_multibytecodec_support.py
copy from lib-python/2.7/test/test_multibytecodec_support.py
copy to lib-python/modified-2.7/test/test_multibytecodec_support.py
--- a/lib-python/2.7/test/test_multibytecodec_support.py
+++ b/lib-python/modified-2.7/test/test_multibytecodec_support.py
@@ -107,8 +107,8 @@
def myreplace(exc):
return (u'x', sys.maxint + 1)
codecs.register_error("test.cjktest", myreplace)
- self.assertRaises(IndexError, self.encode, self.unmappedunicode,
- 'test.cjktest')
+ self.assertRaises((IndexError, OverflowError), self.encode,
+ self.unmappedunicode, 'test.cjktest')
def test_callback_None_index(self):
def myreplace(exc):
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
@@ -46,15 +46,9 @@
space.w_TypeError, msg,
space.str_w(space.repr(w_res)))
w_replace, w_newpos = space.fixedview(w_res, 2)
- try:
- newpos = space.int_w(w_newpos)
- except OperationError, e:
- if not e.match(space, space.w_OverflowError):
- raise
- newpos = -1
- else:
- if newpos < 0:
- newpos = len(input) + newpos
+ newpos = space.int_w(w_newpos)
+ if newpos < 0:
+ newpos = len(input) + newpos
if newpos < 0 or newpos > len(input):
raise operationerrfmt(
space.w_IndexError,
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
@@ -64,7 +64,8 @@
import sys
codecs.register_error("test.test_decode_custom_error_handler_overflow",
lambda e: (u'', sys.maxint + 1))
- raises(IndexError, "abc\xDD".decode, "hz",
"test.test_decode_custom_error_handler_overflow")
+ raises((IndexError, OverflowError), "abc\xDD".decode, "hz",
+ "test.test_decode_custom_error_handler_overflow")
def test_encode_hz(self):
import _codecs_cn
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit