Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3k Changeset: r75902:ab4e84ecd24c Date: 2015-02-15 19:36 +0100 http://bitbucket.org/pypy/pypy/changeset/ab4e84ecd24c/
Log: Rename function unicodehelper.encode_error_handler(), it is used in many places in py3k, and it's too dangerous to change the raised exception. diff --git a/pypy/interpreter/unicodehelper.py b/pypy/interpreter/unicodehelper.py --- a/pypy/interpreter/unicodehelper.py +++ b/pypy/interpreter/unicodehelper.py @@ -24,6 +24,19 @@ space.wrap(msg)])) return raise_unicode_exception_decode +@specialize.memo() +def encode_error_handler(space): + # Fast version of the "strict" errors handler. + def raise_unicode_exception_encode(errors, encoding, msg, u, + startingpos, endingpos): + raise OperationError(space.w_UnicodeEncodeError, + space.newtuple([space.wrap(encoding), + space.wrap(u), + space.wrap(startingpos), + space.wrap(endingpos), + space.wrap(msg)])) + return raise_unicode_exception_encode + class RUnicodeEncodeError(Exception): def __init__(self, encoding, object, start, end, reason): self.encoding = encoding @@ -33,8 +46,8 @@ self.reason = reason @specialize.memo() -def encode_error_handler(space): - # Fast version of the "strict" errors handler. +def rpy_encode_error_handler(): + # A RPython version of the "strict" error handler. def raise_unicode_exception_encode(errors, encoding, msg, u, startingpos, endingpos): raise RUnicodeEncodeError(encoding, u, startingpos, endingpos, msg) diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -66,7 +66,7 @@ if identifier is not None: return identifier u = self._value - eh = unicodehelper.encode_error_handler(space) + eh = unicodehelper.rpy_encode_error_handler() try: identifier = unicode_encode_utf_8(u, len(u), None, errorhandler=eh) @@ -493,12 +493,12 @@ try: if encoding == 'ascii': u = space.unicode_w(w_object) - eh = unicodehelper.encode_error_handler(space) + eh = unicodehelper.rpy_encode_error_handler() return space.wrapbytes(unicode_encode_ascii( u, len(u), None, errorhandler=eh)) if encoding == 'utf-8': u = space.unicode_w(w_object) - eh = unicodehelper.encode_error_handler(space) + eh = unicodehelper.rpy_encode_error_handler() return space.wrapbytes(unicode_encode_utf_8( u, len(u), None, errorhandler=eh)) except unicodehelper.RUnicodeEncodeError, ue: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit