Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65897a3

Browse files
committed
Closes #12291 for 3.3 - merged fix from 3.2.
2 parents 2ee6188 + 5bdae3b commit 65897a3

4 files changed

Lines changed: 183 additions & 60 deletions

File tree

Lib/importlib/test/source/test_file_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def _test_bad_marshal(self, *, del_source=False):
214214
lambda bc: bc[:8] + b'<test>',
215215
del_source=del_source)
216216
file_path = mapping['_temp'] if not del_source else bytecode_path
217-
with self.assertRaises(ValueError):
217+
with self.assertRaises(EOFError):
218218
self.import_(file_path, '_temp')
219219

220220
def _test_bad_magic(self, test, *, del_source=False):

Lib/test/test_marshal.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,30 @@ def test_invalid_longs(self):
228228
invalid_string = b'l\x02\x00\x00\x00\x00\x00\x00\x00'
229229
self.assertRaises(ValueError, marshal.loads, invalid_string)
230230

231+
def test_multiple_dumps_and_loads(self):
232+
# Issue 12291: marshal.load() should be callable multiple times
233+
# with interleaved data written by non-marshal code
234+
# Adapted from a patch by Engelbert Gruber.
235+
data = (1, 'abc', b'def', 1.0, (2, 'a', ['b', b'c']))
236+
for interleaved in (b'', b'0123'):
237+
ilen = len(interleaved)
238+
positions = []
239+
try:
240+
with open(support.TESTFN, 'wb') as f:
241+
for d in data:
242+
marshal.dump(d, f)
243+
if ilen:
244+
f.write(interleaved)
245+
positions.append(f.tell())
246+
with open(support.TESTFN, 'rb') as f:
247+
for i, d in enumerate(data):
248+
self.assertEqual(d, marshal.load(f))
249+
if ilen:
250+
f.read(ilen)
251+
self.assertEqual(positions[i], f.tell())
252+
finally:
253+
support.unlink(support.TESTFN)
254+
231255

232256
def test_main():
233257
support.run_unittest(IntTestCase,

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #12291: You can now load multiple marshalled objects from a stream,
14+
with other data interleaved between marshalled objects.
15+
1316
- Issue #12356: When required positional or keyword-only arguments are not
1417
given, produce a informative error message which includes the name(s) of the
1518
missing arguments.

0 commit comments

Comments
 (0)