[pypy-svn] r78234 - in pypy/branch/fast-forward/pypy/interpreter/pyparser: . test

afa at codespeak.net afa at codespeak.net
Sat Oct 23 17:37:33 CEST 2010


Author: afa
Date: Sat Oct 23 17:37:29 2010
New Revision: 78234

Modified:
   pypy/branch/fast-forward/pypy/interpreter/pyparser/pyparse.py
   pypy/branch/fast-forward/pypy/interpreter/pyparser/test/test_pyparse.py
Log:
while compiling, decoding errors should be turned into SyntaxErrors


Modified: pypy/branch/fast-forward/pypy/interpreter/pyparser/pyparse.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/pyparser/pyparse.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/pyparser/pyparse.py	Sat Oct 23 17:37:29 2010
@@ -125,6 +125,11 @@
                     if space.is_w(e.w_type, space.w_LookupError):
                         raise error.SyntaxError("Unknown encoding: %s" % enc,
                                                 filename=compile_info.filename)
+                    # Transform unicode errors into SyntaxError
+                    if space.is_w(e.w_type, space.w_UnicodeDecodeError):
+                        e.normalize_exception(space)
+                        w_message = space.str(e.get_w_value(space))
+                        raise error.SyntaxError(space.str_w(w_message))
                     raise
 
         flags = compile_info.flags

Modified: pypy/branch/fast-forward/pypy/interpreter/pyparser/test/test_pyparse.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/pyparser/test/test_pyparse.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/pyparser/test/test_pyparse.py	Sat Oct 23 17:37:29 2010
@@ -56,6 +56,10 @@
         input = "# coding: not-here"
         exc = py.test.raises(SyntaxError, self.parse, input).value
         assert exc.msg == "Unknown encoding: not-here"
+        input = u"# coding: ascii\n\xe2".encode('utf-8')
+        exc = py.test.raises(SyntaxError, self.parse, input).value
+        assert exc.msg == ("'ascii' codec can't decode byte 0xc3 "
+                           "in position 16: ordinal not in range(128)")
 
     def test_syntax_error(self):
         parse = self.parse



More information about the Pypy-commit mailing list