[pypy-commit] pypy default: fix marshal unknown type code message

bdkearns noreply at buildbot.pypy.org
Thu Apr 24 22:52:14 CEST 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r70939:18b81200f942
Date: 2014-04-24 16:38 -0400
http://bitbucket.org/pypy/pypy/changeset/18b81200f942/

Log:	fix marshal unknown type code message

diff --git a/pypy/module/marshal/interp_marshal.py b/pypy/module/marshal/interp_marshal.py
--- a/pypy/module/marshal/interp_marshal.py
+++ b/pypy/module/marshal/interp_marshal.py
@@ -327,21 +327,8 @@
 
 
 def invalid_typecode(space, u, tc):
-    # %r not supported in rpython
-    #u.raise_exc('invalid typecode in unmarshal: %r' % tc)
-    c = ord(tc)
-    if c < 16:
-        s = '\\x0%x' % c
-    elif c < 32 or c > 126:
-        s = '\\x%x' % c
-    elif tc == '\\':
-        s = r'\\'
-    else:
-        s = tc
-    q = "'"
-    if s[0] == "'":
-        q = '"'
-    u.raise_exc('invalid typecode in unmarshal: ' + q + s + q)
+    u.raise_exc("bad marshal data (unknown type code)")
+
 
 def register(codes, func):
     """NOT_RPYTHON"""
diff --git a/pypy/module/marshal/test/test_marshal.py b/pypy/module/marshal/test/test_marshal.py
--- a/pypy/module/marshal/test/test_marshal.py
+++ b/pypy/module/marshal/test/test_marshal.py
@@ -14,11 +14,14 @@
         print(repr(s))
         x = marshal.loads(s)
         assert x == case and type(x) is type(case)
-        f = StringIO.StringIO()
-        marshal.dump(case, f)
-        f.seek(0)
-        x = marshal.load(f)
-        assert x == case and type(x) is type(case)
+
+        import sys
+        if '__pypy__' in sys.builtin_module_names:
+            f = StringIO.StringIO()
+            marshal.dump(case, f)
+            f.seek(0)
+            x = marshal.load(f)
+            assert x == case and type(x) is type(case)
         return x
 
     def test_None(self):
@@ -191,7 +194,7 @@
     def test_bad_typecode(self):
         import marshal
         exc = raises(ValueError, marshal.loads, chr(1))
-        assert r"'\x01'" in exc.value.message
+        assert str(exc.value) == "bad marshal data (unknown type code)"
 
 
 class AppTestSmallLong(AppTestMarshal):


More information about the pypy-commit mailing list