summaryrefslogtreecommitdiffstats
path: root/Lib/pickle.py
diff options
context:
space:
mode:
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2008-11-04 00:31:31 (GMT)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2008-11-04 00:31:31 (GMT)
commit1543a22d8645c304d39d471333e18ac31fec4c6f (patch)
treefa06a51f0716694271c0d3bf0b2bc6584b8bd394 /Lib/pickle.py
parentc1de4ccad7907939b78c8e9e7de248d20c7840ee (diff)
downloadcpython-1543a22d8645c304d39d471333e18ac31fec4c6f.zip
cpython-1543a22d8645c304d39d471333e18ac31fec4c6f.tar.gz
cpython-1543a22d8645c304d39d471333e18ac31fec4c6f.tar.bz2
Blocked revisions 67002 via svnmerge
........ r67002 | hirokazu.yamamoto | 2008-10-23 09:37:33 +0900 | 1 line Issue #4183: Some tests didn't run with pickle.HIGHEST_PROTOCOL. ........
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 37c3d52..2e55c8a 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -345,6 +345,9 @@ class _Pickler:
else:
self.write(PERSID + str(pid).encode("ascii") + b'\n')
+ def _isiter(self, obj):
+ return hasattr(obj, '__next__') and hasattr(obj, '__iter__')
+
def save_reduce(self, func, args, state=None,
listitems=None, dictitems=None, obj=None):
# This API is called by some subclasses
@@ -357,6 +360,16 @@ class _Pickler:
if not hasattr(func, '__call__'):
raise PicklingError("func from save_reduce() should be callable")
+ # Assert that listitems is an iterator
+ if listitems is not None and not self._isiter(listitems):
+ raise PicklingError("listitems from save_reduce() should be an "
+ "iterator")
+
+ # Assert that dictitems is an iterator
+ if dictitems is not None and not self._isiter(dictitems):
+ raise PicklingError("dictitems from save_reduce() should be an "
+ "iterator")
+
save = self.save
write = self.write