[pypy-commit] pypy py3k: Rename function unicodehelper.encode_error_handler(), it is used in many places in py3k,
amauryfa
noreply at buildbot.pypy.org
Sun Feb 15 19:43:22 CET 2015
Author: Amaury Forgeot d'Arc <amauryfa at 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
+ at 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:
More information about the pypy-commit
mailing list