Author: Brian Kearns <[email protected]>
Branch:
Changeset: r62362:6cbb87a9026d
Date: 2013-03-15 16:51 -0400
http://bitbucket.org/pypy/pypy/changeset/6cbb87a9026d/
Log: test and fix for _marshal.dump_unicode (fixes issue 1420)
diff --git a/lib_pypy/_marshal.py b/lib_pypy/_marshal.py
--- a/lib_pypy/_marshal.py
+++ b/lib_pypy/_marshal.py
@@ -167,8 +167,8 @@
def dump_unicode(self, x):
self._write(TYPE_UNICODE)
#s = x.encode('utf8')
- s, len_s = utf_8_encode(x)
- self.w_long(len_s)
+ s = utf_8_encode(x)[0]
+ self.w_long(len(s))
self._write(s)
try:
unicode
@@ -387,7 +387,7 @@
n = self.r_long()
s = self._read(n)
#ret = s.decode('utf8')
- ret, len_ret = utf_8_decode(s)
+ ret = utf_8_decode(s)[0]
return ret
dispatch[TYPE_UNICODE] = load_unicode
diff --git a/pypy/module/test_lib_pypy/test_marshal_extra.py
b/pypy/module/test_lib_pypy/test_marshal_extra.py
--- a/pypy/module/test_lib_pypy/test_marshal_extra.py
+++ b/pypy/module/test_lib_pypy/test_marshal_extra.py
@@ -145,3 +145,8 @@
def test_load_truncated_string():
s = '(\x02\x00\x00\x00i\x03\x00\x00\x00sB\xf9\x00\x00\nabcd'
py.test.raises(EOFError, marshal.loads, s)
+
+def test_dump_unicode_length():
+ s = u'123\xe9'
+ r = marshal.dumps(s)
+ assert r == b'u\x05\x00\x00\x00123\xc3\xa9'
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit