Author: Armin Rigo <[email protected]>
Branch:
Changeset: r60928:78bc49b20cba
Date: 2013-02-07 11:45 +0100
http://bitbucket.org/pypy/pypy/changeset/78bc49b20cba/
Log: Try to hide another small difference between pickle and cPickle.
diff --git a/lib_pypy/cPickle.py b/lib_pypy/cPickle.py
--- a/lib_pypy/cPickle.py
+++ b/lib_pypy/cPickle.py
@@ -1,5 +1,5 @@
#
-# One-liner implementation of cPickle
+# Reimplementation of cPickle, mostly as a copy of pickle.py
#
from pickle import Pickler, dump, dumps, PickleError, PicklingError,
UnpicklingError, _EmptyClass
@@ -131,6 +131,13 @@
# Unpickling machinery
+class _Stack(list):
+ def pop(self, index=-1):
+ try:
+ return list.pop(self, index)
+ except IndexError:
+ raise UnpicklingError("unpickling stack underflow")
+
class Unpickler(object):
def __init__(self, file):
@@ -155,7 +162,7 @@
Return the reconstituted object hierarchy specified in the file.
"""
self.mark = object() # any new unique object
- self.stack = []
+ self.stack = _Stack()
self.append = self.stack.append
try:
key = ord(self.read(1))
diff --git a/lib_pypy/pypy_test/test_cPickle.py
b/lib_pypy/pypy_test/test_cPickle.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/pypy_test/test_cPickle.py
@@ -0,0 +1,7 @@
+from __future__ import absolute_import
+import py
+
+from lib_pypy import cPickle
+
+def test_stack_underflow():
+ py.test.raises(cPickle.UnpicklingError, cPickle.loads, "a string")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit