[pypy-svn] r17893 - in pypy/dist/pypy/module/__builtin__: . test

ac at codespeak.net ac at codespeak.net
Tue Sep 27 10:46:13 CEST 2005


Author: ac
Date: Tue Sep 27 10:46:13 2005
New Revision: 17893

Modified:
   pypy/dist/pypy/module/__builtin__/compiling.py
   pypy/dist/pypy/module/__builtin__/test/test_builtin.py
Log:
Don't alter lineumbers when compiling unicode.

Modified: pypy/dist/pypy/module/__builtin__/compiling.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/compiling.py	(original)
+++ pypy/dist/pypy/module/__builtin__/compiling.py	Tue Sep 27 10:46:13 2005
@@ -9,11 +9,11 @@
 
 def compile(space, w_source, filename, mode, flags=0, dont_inherit=0):
     if space.is_true(space.isinstance(w_source, space.w_unicode)):
-        # hack: encode the unicode string as UTF-8 and attach a 'coding'
-        # declaration at the start
+        # hack: encode the unicode string as UTF-8 and attach
+        # a BOM at the start
         w_source = space.call_method(w_source, 'encode', space.wrap('utf-8'))
         str_ = space.str_w(w_source)
-        str_ = "# -*- coding: utf-8 -*-\n" + str_
+        str_ = '\xEF\xBB\xBF' + str_
     else:
         str_ = space.str_w(w_source)
 

Modified: pypy/dist/pypy/module/__builtin__/test/test_builtin.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/test/test_builtin.py	(original)
+++ pypy/dist/pypy/module/__builtin__/test/test_builtin.py	Tue Sep 27 10:46:13 2005
@@ -360,6 +360,12 @@
         raises(ValueError, compile, '1+2', '?', 'maybenot')
         raises(TypeError, compile, '1+2', 12, 34)
 
+    def test_unicode_compile(self):
+        try:
+            compile(u'-', '?', 'eval')
+        except SyntaxError, e:
+            assert e.lineno == 1
+            
     def test_isinstance(self):
         assert isinstance(5, int)
         assert isinstance(5, object)



More information about the Pypy-commit mailing list