[pypy-svn] r75137 - in pypy/branch/unfreeze-encodings/pypy/rpython: . test
fijal at codespeak.net
fijal at codespeak.net
Sun Jun 6 00:19:35 CEST 2010
Author: fijal
Date: Sun Jun 6 00:19:33 2010
New Revision: 75137
Modified:
pypy/branch/unfreeze-encodings/pypy/rpython/rbuiltin.py
pypy/branch/unfreeze-encodings/pypy/rpython/test/test_rbuiltin.py
Log:
Make Unicode[Encode|Decode]Error understandable on RPython level
Modified: pypy/branch/unfreeze-encodings/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/branch/unfreeze-encodings/pypy/rpython/rbuiltin.py (original)
+++ pypy/branch/unfreeze-encodings/pypy/rpython/rbuiltin.py Sun Jun 6 00:19:33 2010
@@ -270,6 +270,37 @@
v_errno = hop.inputarg(lltype.Signed, arg=1)
r_self.setfield(v_self, 'errno', v_errno, hop.llops)
+def rtype_UnicodeDecodeError_init(hop):
+ if hop.nb_args != 6:
+ raise TypeError("UnicodeDecodeError() should be called with 5 "
+ "arguments")
+ r_self = hop.args_r[0]
+ r_str = hop.rtyper.type_system.rstr.string_repr
+ TPS = [hop.args_r[0], r_str, r_str, lltype.Signed, lltype.Signed,
+ r_str]
+ v_self, v_encoding, v_obj, v_start, v_end, v_msg = hop.inputargs(*TPS)
+ r_self.setfield(v_self, 'encoding', v_encoding, hop.llops)
+ r_self.setfield(v_self, 'object', v_obj, hop.llops)
+ r_self.setfield(v_self, 'start', v_start, hop.llops)
+ r_self.setfield(v_self, 'end', v_end, hop.llops)
+ r_self.setfield(v_self, 'reason', v_msg, hop.llops)
+
+def rtype_UnicodeEncodeError_init(hop):
+ if hop.nb_args != 6:
+ raise TypeError("UnicodeEncodeError() should be called with 5 "
+ "arguments")
+ r_self = hop.args_r[0]
+ r_str = hop.rtyper.type_system.rstr.string_repr
+ r_unicode = hop.rtyper.type_system.rstr.unicode_repr
+ TPS = [hop.args_r[0], r_str, r_unicode, lltype.Signed, lltype.Signed,
+ r_str]
+ v_self, v_encoding, v_obj, v_start, v_end, v_msg = hop.inputargs(*TPS)
+ r_self.setfield(v_self, 'encoding', v_encoding, hop.llops)
+ r_self.setfield(v_self, 'object', v_obj, hop.llops)
+ r_self.setfield(v_self, 'start', v_start, hop.llops)
+ r_self.setfield(v_self, 'end', v_end, hop.llops)
+ r_self.setfield(v_self, 'reason', v_msg, hop.llops)
+
def rtype_WindowsError__init__(hop):
if hop.nb_args == 2:
raise TyperError("WindowsError() should not be called with "
@@ -329,6 +360,8 @@
BUILTIN_TYPER[getattr(OSError.__init__, 'im_func', OSError.__init__)] = (
rtype_OSError__init__)
+BUILTIN_TYPER[getattr(UnicodeDecodeError.__init__, 'im_func', UnicodeDecodeError.__init__)] = rtype_UnicodeDecodeError_init
+BUILTIN_TYPER[getattr(UnicodeEncodeError.__init__, 'im_func', UnicodeEncodeError.__init__)] = rtype_UnicodeEncodeError_init
try:
WindowsError
Modified: pypy/branch/unfreeze-encodings/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/branch/unfreeze-encodings/pypy/rpython/test/test_rbuiltin.py (original)
+++ pypy/branch/unfreeze-encodings/pypy/rpython/test/test_rbuiltin.py Sun Jun 6 00:19:33 2010
@@ -496,6 +496,35 @@
res = self.interpret(llf, [rffi.r_short(123)], policy=LowLevelAnnotatorPolicy())
assert res == 123
+ def test_unicode_errors(self):
+ def f():
+ try:
+ raise UnicodeDecodeError("xx", "x", 0, 1, "reason")
+ except UnicodeDecodeError, ude:
+ assert ude.start == 0
+ assert ude.encoding == "xx"
+ assert ude.object == "x"
+ assert ude.start == 0
+ assert ude.reason == "reason"
+ return ude.end
+
+ res = self.interpret(f, [])
+ assert res == f()
+
+ def f():
+ try:
+ raise UnicodeEncodeError("xx", u"x", 0, 1, "reason")
+ except UnicodeEncodeError, ude:
+ assert ude.start == 0
+ assert ude.encoding == "xx"
+ assert ude.object == u"x"
+ assert ude.start == 0
+ assert ude.reason == "reason"
+ return ude.end
+
+ res = self.interpret(f, [])
+ assert res == f()
+
class TestLLtype(BaseTestRbuiltin, LLRtypeMixin):
def test_isinstance_obj(self):
More information about the Pypy-commit
mailing list