summaryrefslogtreecommitdiffstats
path: root/Lib/pickle.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-02-13 15:44:41 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-02-13 15:44:41 (GMT)
commit8587b3c0730236dc007e8533c3cbfccd421fa381 (patch)
treee031741700152eb780af1071669c69f397402429 /Lib/pickle.py
parentfe62bc917d1ab51fc591839b3c65589b268cad31 (diff)
downloadcpython-8587b3c0730236dc007e8533c3cbfccd421fa381.zip
cpython-8587b3c0730236dc007e8533c3cbfccd421fa381.tar.gz
cpython-8587b3c0730236dc007e8533c3cbfccd421fa381.tar.bz2
Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 00f5834..74748f8 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -47,6 +47,10 @@ compatible_formats = ["1.0", # Original protocol 0
"2.0", # Protocol 2
] # Old format versions we can read
+# Keep in synch with cPickle. This is the highest protocol number we
+# know how to read.
+HIGHEST_PROTOCOL = 2
+
# Why use struct.pack() for pickling but marshal.loads() for
# unpickling? struct.pack() is 40% faster than marshal.dumps(), but
# marshal.loads() is twice as fast as struct.unpack()!
@@ -200,9 +204,9 @@ class Pickler:
if protocol is None:
protocol = 0
if protocol < 0:
- protocol = 2
- elif protocol not in (0, 1, 2):
- raise ValueError, "pickle protocol must be 0, 1 or 2"
+ protocol = HIGHEST_PROTOCOL
+ elif not 0 <= protocol <= HIGHEST_PROTOCOL:
+ raise ValueError("pickle protocol must be <= %d" % HIGHEST_PROTOCOL)
self.write = file.write
self.memo = {}
self.proto = int(protocol)