[pypy-commit] pypy py3k: bytes can only contain ASCII literal characters.

amauryfa noreply at buildbot.pypy.org
Thu Nov 29 23:19:31 CET 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r59139:06ccdd561468
Date: 2012-11-29 22:22 +0100
http://bitbucket.org/pypy/pypy/changeset/06ccdd561468/

Log:	bytes can only contain ASCII literal characters.

diff --git a/pypy/interpreter/pyparser/parsestring.py b/pypy/interpreter/pyparser/parsestring.py
--- a/pypy/interpreter/pyparser/parsestring.py
+++ b/pypy/interpreter/pyparser/parsestring.py
@@ -92,6 +92,14 @@
 
     assert 0 <= ps <= q
     substr = s[ps : q]
+
+    if not unicode_literal:
+        # Disallow non-ascii characters (but not escapes)
+        for c in substr:
+            if ord(c) > 0x80:
+                raise OperationError(space.w_SyntaxError, space.wrap(
+                        'bytes can only contain ASCII literal characters.'))
+
     if rawmode or '\\' not in substr:
         if not unicode_literal:
             return space.wrapbytes(substr)
diff --git a/pypy/interpreter/pyparser/test/test_parsestring.py b/pypy/interpreter/pyparser/test/test_parsestring.py
--- a/pypy/interpreter/pyparser/test/test_parsestring.py
+++ b/pypy/interpreter/pyparser/test/test_parsestring.py
@@ -37,6 +37,9 @@
             space.raises_w(space.w_ValueError,
                            parsestring.parsestr, space, None, s)
 
+        space.raises_w(space.w_SyntaxError,
+                       parsestring.parsestr, space, None, "b'\xe9'")
+
     def test_unicode(self):
         space = self.space
         for s in ['hello world', 'hello\n world']:


More information about the pypy-commit mailing list