[pypy-svn] pypy fast-forward: Don't let raw UnicodeErrors in expat callbacks, use the "official" function which raises applevel exceptions.
amauryfa
commits-noreply at bitbucket.org
Thu Jan 13 11:44:59 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: fast-forward
Changeset: r40637:77b2d271478a
Date: 2011-01-13 10:44 +0100
http://bitbucket.org/pypy/pypy/changeset/77b2d271478a/
Log: Don't let raw UnicodeErrors in expat callbacks, use the "official"
function which raises applevel exceptions.
diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -361,9 +361,8 @@
def w_convert(self, space, s):
if self.returns_unicode:
- from pypy.rlib.runicode import str_decode_utf_8
- return space.wrap(str_decode_utf_8(
- s, len(s), "strict")[0])
+ from pypy.interpreter.unicodehelper import PyUnicode_DecodeUTF8
+ return space.wrap(PyUnicode_DecodeUTF8(space, s))
else:
return space.wrap(s)
diff --git a/pypy/module/pyexpat/test/test_parser.py b/pypy/module/pyexpat/test/test_parser.py
--- a/pypy/module/pyexpat/test/test_parser.py
+++ b/pypy/module/pyexpat/test/test_parser.py
@@ -75,3 +75,12 @@
assert text == u"caf\xe9"
p.CharacterDataHandler = gotText
p.Parse(xml)
+
+ def test_decode_error(self):
+ xml = '<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>'
+ import pyexpat
+ p = pyexpat.ParserCreate()
+ def f(*args): pass
+ p.StartElementHandler = f
+ exc = raises(UnicodeDecodeError, p.Parse, xml)
+ assert exc.value.start == 4
More information about the Pypy-commit
mailing list