Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r71357:4ce5be4dfac4
Date: 2014-05-06 17:01 -0700
http://bitbucket.org/pypy/pypy/changeset/4ce5be4dfac4/
Log: match cpython's error message
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1553,10 +1553,10 @@
if space.isinstance_w(w_source, space.w_unicode):
from pypy.interpreter.unicodehelper import encode
w_source = encode(space, w_source)
- source = space.bytes0_w(w_source)
+ source = space.bytes_w(w_source)
flags |= consts.PyCF_IGNORE_COOKIE
elif space.isinstance_w(w_source, space.w_bytes):
- source = space.bytes0_w(w_source)
+ source = space.bytes_w(w_source)
else:
try:
buf = space.buffer_w(w_source, space.BUF_SIMPLE)
@@ -1565,8 +1565,12 @@
raise
raise oefmt(space.w_TypeError,
"%s() arg 1 must be a %s object", funcname, what)
- source = rstring.assert_str0(buf.as_str())
- return source, flags
+ source = buf.as_str()
+
+ if '\x00' in source:
+ raise oefmt(space.w_TypeError,
+ "source code string cannot contain null bytes")
+ return rstring.assert_str0(source), flags
def ensure_ns(space, w_globals, w_locals, funcname, caller=None):
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
@@ -490,9 +490,7 @@
co = compile(memoryview(b'1+2'), '?', 'eval')
assert eval(co) == 3
exc = raises(TypeError, compile, chr(0), '?', 'eval')
- assert str(exc.value) == "compile() expected string without null bytes"
- exc = raises(TypeError, compile, memoryview(b'1+2'), '?', 'eval')
- assert str(exc.value) == "expected a readable buffer object"
+ assert str(exc.value) == "source code string cannot contain null bytes"
compile("from __future__ import with_statement", "<test>", "exec")
raises(SyntaxError, compile, '-', '?', 'eval')
raises(SyntaxError, compile, '"\\xt"', '?', 'eval')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit