[pypy-commit] pypy py3k: Allow bytes source code in compile()

amauryfa noreply at buildbot.pypy.org
Mon Nov 7 21:22:36 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48876:1afdb2a14313
Date: 2011-11-07 21:02 +0100
http://bitbucket.org/pypy/pypy/changeset/1afdb2a14313/

Log:	Allow bytes source code in compile()

diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -30,6 +30,8 @@
     if space.is_true(space.isinstance(w_source, w_ast_type)):
         ast_node = space.interp_w(ast.mod, w_source)
         ast_node.sync_app_attrs(space)
+    elif space.isinstance_w(w_source, space.w_bytes):
+        source_str = space.bytes_w(w_source)
     else:
         source_str = space.str_w(w_source)
         # This flag tells the parser to reject any coding cookies it sees.
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -509,6 +509,10 @@
         code = u"# -*- coding: utf-8 -*-\npass\n"
         raises(SyntaxError, compile, code, "tmp", "exec")
 
+    def test_bytes_compile(self):
+        code = b"# -*- coding: utf-8 -*-\npass\n"
+        compile(code, "tmp", "exec")
+
     def test_recompile_ast(self):
         import _ast
         # raise exception when node type doesn't match with compile mode


More information about the pypy-commit mailing list