Author: fijal
Branch: unicode-utf8
Changeset: r93096:d17afc06eedf
Date: 2017-11-20 15:15 +0100
http://bitbucket.org/pypy/pypy/changeset/d17afc06eedf/
Log: fixes
diff --git a/pypy/interpreter/test/test_unicodehelper.py
b/pypy/interpreter/test/test_unicodehelper.py
--- a/pypy/interpreter/test/test_unicodehelper.py
+++ b/pypy/interpreter/test/test_unicodehelper.py
@@ -63,3 +63,8 @@
def test_unicode_raw_escape(u):
r = uh.utf8_encode_raw_unicode_escape(u.encode("utf8"), 'strict')
assert r == u.encode("raw-unicode-escape")
+
+@given(strategies.text())
+def test_unicode_escape(u):
+ r = uh.utf8_encode_unicode_escape(u.encode("utf8"), "strict")
+ assert r == u.encode("unicode-escape")
diff --git a/pypy/interpreter/unicodehelper.py
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -23,13 +23,12 @@
@specialize.memo()
def encode_error_handler(space):
# Fast version of the "strict" errors handler.
- def raise_unicode_exception_encode(errors, encoding, msg, u, u_len,
+ def raise_unicode_exception_encode(errors, encoding, msg, utf8,
startingpos, endingpos):
- # XXX fix once we stop using runicode.py
- flag = _get_flag(u.decode('utf8'))
+ u_len, flag = rutf8.check_utf8(utf8)
raise OperationError(space.w_UnicodeEncodeError,
space.newtuple([space.newtext(encoding),
- space.newutf8(u, u_len, flag),
+ space.newutf8(utf8, u_len, flag),
space.newint(startingpos),
space.newint(endingpos),
space.newtext(msg)]))
@@ -578,13 +577,15 @@
digits = 4 if s[pos] == 'u' else 8
message = "truncated \\uXXXX"
pos += 1
- pos = hexescape(result, s, pos, digits,
+ pos, _, _ = hexescape(result, s, pos, digits,
"rawunicodeescape", errorhandler, message, errors)
r = result.build()
lgt, flag = rutf8.check_utf8(r, True)
return r, pos, lgt, flag
+_utf8_encode_unicode_escape = rutf8.make_utf8_escape_function()
+
TABLE = '0123456789abcdef'
@@ -620,6 +621,9 @@
return result.build()
+def utf8_encode_unicode_escape(s, errors):
+ return _utf8_encode_unicode_escape(s)
+
# ____________________________________________________________
# utf-7
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit