[pypy-commit] pypy unicode-utf8-py3: split complicated logic
mattip
pypy.commits at gmail.com
Wed Aug 22 05:24:19 EDT 2018
Author: Matti Picus <matti.picus at gmail.com>
Branch: unicode-utf8-py3
Changeset: r95020:740e7000561f
Date: 2018-08-22 12:22 +0300
http://bitbucket.org/pypy/pypy/changeset/740e7000561f/
Log: split complicated logic
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
@@ -62,13 +62,7 @@
space.newtext(reason))
w_res = space.call_function(w_errorhandler, w_exc)
if (not space.isinstance_w(w_res, space.w_tuple)
- or space.len_w(w_res) != 2
- or not (space.isinstance_w(
- space.getitem(w_res, space.newint(0)),
- space.w_unicode) or
- (not decode and space.isinstance_w(
- space.getitem(w_res, space.newint(0)),
- space.w_bytes)))):
+ or space.len_w(w_res) != 2):
if decode:
msg = ("decoding error handler must return "
"(str, int) tuple")
@@ -78,6 +72,15 @@
raise OperationError(space.w_TypeError, space.newtext(msg))
w_replace, w_newpos = space.fixedview(w_res, 2)
+ if not (space.isinstance_w(w_replace, space.w_unicode) or
+ (not decode and space.isinstance_w(w_replace, space.w_bytes))):
+ if decode:
+ msg = ("decoding error handler must return "
+ "(str, int) tuple")
+ else:
+ msg = ("encoding error handler must return "
+ "(str/bytes, int) tuple")
+ raise OperationError(space.w_TypeError, space.newtext(msg))
try:
newpos = space.int_w(w_newpos)
except OperationError as e:
More information about the pypy-commit
mailing list