[pypy-commit] pypy default: Improve a bit the error message given by marshal.loads.
amauryfa
noreply at buildbot.pypy.org
Tue Mar 13 21:50:55 CET 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r53489:9cbb8e14aeee
Date: 2012-03-13 21:40 +0100
http://bitbucket.org/pypy/pypy/changeset/9cbb8e14aeee/
Log: Improve a bit the error message given by marshal.loads.
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,8 +327,10 @@
# %r not supported in rpython
#u.raise_exc('invalid typecode in unmarshal: %r' % tc)
c = ord(tc)
- if c < 32 or c > 126:
- s = '\\x' + hex(c)
+ if c < 16:
+ s = '\\x0%x' % c
+ elif c < 32 or c > 126:
+ s = '\\x%x' % c
elif tc == '\\':
s = r'\\'
else:
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
@@ -174,6 +174,11 @@
pass
raises(ValueError, marshal.dumps, subtype)
+ def test_bad_typecode(self):
+ import marshal
+ exc = raises(ValueError, marshal.loads, chr(1))
+ assert r"'\x01'" in exc.value.message
+
class AppTestRope(AppTestMarshal):
def setup_class(cls):
More information about the pypy-commit
mailing list