summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-02-23 22:53:24 (GMT)
committerGitHub <noreply@github.com>2020-02-23 22:53:24 (GMT)
commitb19f7ecfa3adc6ba1544225317b9473649815b38 (patch)
tree90e05b2a2897a598bf22e39c4f0a74d4dffb96c7 /Lib/test
parent13951c7f25c628ea2dc0a869ebe18e7bf593fa6d (diff)
downloadcpython-b19f7ecfa3adc6ba1544225317b9473649815b38.zip
cpython-b19f7ecfa3adc6ba1544225317b9473649815b38.tar.gz
cpython-b19f7ecfa3adc6ba1544225317b9473649815b38.tar.bz2
bpo-39681: Fix C pickle regression with minimal file-like objects (GH-18592) (#18630)
Fix a regression where the C pickle module wouldn't allow unpickling from a file-like object that doesn't expose a readinto() method. (cherry picked from commit 9f37872e307734666a7169f7be6e3370d3068282) Co-authored-by: Antoine Pitrou <antoine@python.org> Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/pickletester.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 3a8aee4..7c8383f 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -73,6 +73,18 @@ class UnseekableIO(io.BytesIO):
raise io.UnsupportedOperation
+class MinimalIO(object):
+ """
+ A file-like object that doesn't support readinto().
+ """
+ def __init__(self, *args):
+ self._bio = io.BytesIO(*args)
+ self.getvalue = self._bio.getvalue
+ self.read = self._bio.read
+ self.readline = self._bio.readline
+ self.write = self._bio.write
+
+
# We can't very well test the extension registry without putting known stuff
# in it, but we have to be careful to restore its original state. Code
# should do this:
@@ -3361,7 +3373,7 @@ class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
f.seek(0)
self.assertEqual(unpickler.load(), data2)
- def _check_multiple_unpicklings(self, ioclass):
+ def _check_multiple_unpicklings(self, ioclass, *, seekable=True):
for proto in protocols:
with self.subTest(proto=proto):
data1 = [(x, str(x)) for x in range(2000)] + [b"abcde", len]
@@ -3374,10 +3386,10 @@ class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
f = ioclass(pickled * N)
unpickler = self.unpickler_class(f)
for i in range(N):
- if f.seekable():
+ if seekable:
pos = f.tell()
self.assertEqual(unpickler.load(), data1)
- if f.seekable():
+ if seekable:
self.assertEqual(f.tell(), pos + len(pickled))
self.assertRaises(EOFError, unpickler.load)
@@ -3385,7 +3397,12 @@ class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
self._check_multiple_unpicklings(io.BytesIO)
def test_multiple_unpicklings_unseekable(self):
- self._check_multiple_unpicklings(UnseekableIO)
+ self._check_multiple_unpicklings(UnseekableIO, seekable=False)
+
+ def test_multiple_unpicklings_minimal(self):
+ # File-like object that doesn't support peek() and readinto()
+ # (bpo-39681)
+ self._check_multiple_unpicklings(MinimalIO, seekable=False)
def test_unpickling_buffering_readline(self):
# Issue #12687: the unpickler's buffering logic could fail with