[pypy-commit] pypy py3k: pass through source as bytes to the compiler

pjenvey noreply at buildbot.pypy.org
Thu Nov 10 02:53:08 CET 2011


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r49071:bc99fcedc6e4
Date: 2011-11-09 17:51 -0800
http://bitbucket.org/pypy/pypy/changeset/bc99fcedc6e4/

Log:	pass through source as bytes to the compiler

diff --git a/pypy/interpreter/main.py b/pypy/interpreter/main.py
--- a/pypy/interpreter/main.py
+++ b/pypy/interpreter/main.py
@@ -18,7 +18,7 @@
 def compilecode(space, source, filename, cmd='exec'):
     w = space.wrap
     w_code = space.builtin.call('compile', 
-             w(source), w(filename), w(cmd), w(0), w(0))
+             space.wrapbytes(source), w(filename), w(cmd), w(0), w(0))
     pycode = space.interp_w(eval.Code, w_code)
     return pycode
 
diff --git a/pypy/interpreter/test/test_main.py b/pypy/interpreter/test/test_main.py
--- a/pypy/interpreter/test/test_main.py
+++ b/pypy/interpreter/test/test_main.py
@@ -1,3 +1,4 @@
+# coding: utf-8
 from cStringIO import StringIO
 
 import py
@@ -77,3 +78,29 @@
                     testmodule, ['hello world'])
         checkoutput(self.space, testresultoutput, main.run_module,
                     testpackage + '.' + testmodule, ['hello world'])
+
+
+class TestMainPEP3120:
+    def setup_class(cls):
+        # Encoding the string here to ease writing to the captured
+        # stdout's underlying Python 2 (not 3) file!
+        testfn.write("""print('&#26085;&#26412;'.encode('utf-8'), end='')""", 'wb')
+        space = cls.space
+        cls.w_oldsyspath = space.appexec([space.wrap(str(udir))], """(udir):
+            import sys
+            old = sys.path[:]
+            sys.path.insert(0, udir)
+            return old
+        """)
+
+    def teardown_class(cls):
+        cls.space.appexec([cls.w_oldsyspath], """(old):
+            import sys
+            sys.path[:] = old
+        """)
+
+    def test_pep3120(self):
+        # Ensure '&#26085;&#26412;' written to the file above is interpreted as utf-8
+        # per PEP3120
+        checkoutput(self.space, 'b' + repr(u'&#26085;&#26412;'.encode('utf-8')),
+                    main.run_file, str(testfn))


More information about the pypy-commit mailing list